Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

equivalent c# code for a embedded c code


  • Please log in to reply
1 reply to this topic

#1 Beowolf

Beowolf

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 02 December 2010 - 07:05 PM

hi, i have a problem in coding the netduino!!!!!!!!!! i have to design the mobile controlled robot as described in the following document: http://raghueee.110m...te_Document.pdf or find the attachment of the same. but i have the following two problems: 1) how should i replace the microcontroller with netduino. 2) i want an equivalent c# code for the embedded c code given in the document

#2 entens

entens

    Member

  • Members
  • PipPip
  • 10 posts

Posted 03 December 2010 - 07:24 AM

I'm just going to post code for a generic DTFM chip. This specific code is for an MT8870. Probably overkill, but I'm still getting used to writing for the NETMF and microcontrollers.

If your using the HT9170 like in the PDF you linked to, you'll want to connect them something like:
	HT9170		Netduino
       ========        ==========
        Pin 11             D6
	Pin 12             D7
	Pin 13             D8
	Pin 14             D9

    public class DTFM : IDisposable
    {
        private Thread ListenThread;
        private bool Listening;

        private int LastValue;

        private InputPort Binary1;
        private InputPort Binary2;
        private InputPort Binary4;
        private InputPort Binary8;

        public delegate void OutputHandler(object sender, int value);
        public event OutputHandler Output;

        public DTFM(Cpu.Pin Binary1, Cpu.Pin Binary2, Cpu.Pin Binary4, Cpu.Pin Binary8)
        {
            // Initialize the local InputPort's utilized by the DTFM
            this.Binary1 = new InputPort(Binary1, false, Port.ResistorMode.Disabled);
            this.Binary2 = new InputPort(Binary1, false, Port.ResistorMode.Disabled);
            this.Binary4 = new InputPort(Binary1, false, Port.ResistorMode.Disabled);
            this.Binary8 = new InputPort(Binary1, false, Port.ResistorMode.Disabled);

            // Initialize the listener thread
            Listening = true;
            ListenThread = new Thread(new ThreadStart(Listen));
            ListenThread.Start();
        }

        public void Dispose()
        {           
            // Make the thread expire
            Listening = false;
            Thread.Sleep(10);

            // Force the thread dead just in case
            if (ListenThread.IsAlive)
                ListenThread.Abort();

            // Free the InputPort's
            Binary1.Dispose();
            Binary2.Dispose();
            Binary4.Dispose();
            Binary8.Dispose();
        }

        void Listen()
        {
            while (Listening)
            {
                // Don't execute if nothing is attached to the event
                if (Output != null)
                {
                    int CurrentValue = 0;

                    // Build the current value from the DTFM
                    if (Binary1.Read())
                        CurrentValue += 1;
                    if (Binary2.Read())
                        CurrentValue += 2;
                    if (Binary4.Read())
                        CurrentValue += 4;
                    if (Binary8.Read())
                        CurrentValue += 8;

                    // If the value has changed, throw a new event
                    if (CurrentValue != LastValue)
                    {
                        LastValue = CurrentValue;
                        Output(this, CurrentValue);
                    }
                }
                // Wait
                Thread.Sleep(100);
            }
        }
    }

Note: 10 = '0'; 11 = '*'; 12 = '#'




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.