SEARCH
TOOLBOX
LANGUAGES
Register    Login    Forum    Search    FAQ

Board index » Electronics Projects » PIC18F USB development




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Send text to pic example
 Post Posted: Tue Jun 12, 2012 5:13 am 
Offline

Joined: Tue Jun 12, 2012 5:04 am
Posts: 5
Hello, i use your Open Source Framework 3.0.0.0

not I send a text from pc to pic and vice versa ...
as it should send the text from pc to pic?

thanks and sorry for my bad English


Top 
 Profile  
 
 Post subject: Re: Send text to pic example
 Post Posted: Tue Jun 12, 2012 6:23 am 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 888
Take a look at the following project which sends text from the PC to the PIC device:

http://www.waitingforfriday.com/index.p ... se_USB_LCD

It should give you some good guidance on how it is done.

/Simon


Top 
 Profile  
 
 Post subject: Re: Send text to pic example
 Post Posted: Tue Jun 12, 2012 6:59 am 
Offline

Joined: Tue Jun 12, 2012 5:04 am
Posts: 5
Thanks,

yes, but works with another version of Framwork and compiled with hi-tech ... tries but fails to do so with the new framework and c18

a few years ago I started to learn using the famework 1.0 and the example you I comment, thanks!


Top 
 Profile  
 
 Post subject: Re: Send text to pic example
 Post Posted: Tue Jun 12, 2012 4:31 pm 
Offline

Joined: Tue Jun 12, 2012 5:04 am
Posts: 5
How I can generate a string for display in the debug?

When I run this code hangs the pic...

Code:
        public bool outputString(String text)
        {
            // Output a string to the LCD display

            // Encode the passed string into an array of bytes for transfer
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            Byte[] outputString = encoding.GetBytes(text);

            // Declare our output buffer
            Byte[] outputBuffer = new Byte[65];

            // Byte 0 must be set to 0
            outputBuffer[0] = 0;

            // Byte 1 must be set to our command
            outputBuffer[1] = 0x90;

            // Byte 2 is our character count
            outputBuffer[2] = Convert.ToByte(text.Length);

            // Copy the characters from the string into the output buffer
            for (Int64 counter = 0; counter < text.Length; counter++)
                outputBuffer[3 + counter] = outputString[counter];

            // Perform the write command
            bool success;
            success = writeRawReportToDevice(outputBuffer);

            // We can't tell if the device receieved the data ok, we are
            // only indicating that the write was error free.
            return success;
        }

Code:
                case 0x90: // *** Send text to PIC ***
                    sprintf(debugString, "Text to PIC");
                    debugOut(debugString);

                    for (characterNumber = 0; characterNumber < ReceivedDataBuffer[1]; characterNumber++) {
                        stringtext = ReceivedDataBuffer[2 + characterNumber];
                    }
                    sprintf(debugString, stringtext);
                    debugOut(debugString);
                    break;


Top 
 Profile  
 
 Post subject: Re: Send text to pic example
 Post Posted: Tue Jun 12, 2012 5:10 pm 
Offline

Joined: Tue Jun 12, 2012 5:04 am
Posts: 5
modify the code and now it works!
I do not know if is the right way ...

Code:
                case 0x90: // *** Send text to PIC ***
                    sprintf(debugString, "Text to PIC");
                    debugOut(debugString);

                    for (characterNumber = 0; characterNumber < ReceivedDataBuffer[1]; characterNumber++) {
                        string[characterNumber] = ReceivedDataBuffer[2 + characterNumber];
                    }
                    string[characterNumber] = '\0';
                   
                    sprintf(debugString, "%s", string);
                    debugOut(debugString);
                    break;


Top 
 Profile  
 
 Post subject: Re: Send text to pic example
 Post Posted: Tue Jun 12, 2012 5:32 pm 
Offline

Joined: Tue Jun 12, 2012 5:04 am
Posts: 5
Now if it all works, send text to the PC and the LCD...

Again is the right way?

Code:
                case 0x90: // *** Send text to PIC ***
                    sprintf(debugString, "Text to PIC");
                    debugOut(debugString);

                    for (characterNumber = 0; characterNumber < ReceivedDataBuffer[1]; characterNumber++) {
                        string[characterNumber] = ReceivedDataBuffer[2 + characterNumber];
                    }
                    string[characterNumber] = '\0';

                    sprintf(LCDString, "%s", string);

                    // Clear display
                    while (BusyXLCD()); // Wait if LCD busy
                    WriteCmdXLCD(0x01); // Clear display

                    putsXLCD(LCDString);

                    sprintf(debugString, "%s", string);
                    debugOut(debugString);
                    break;


Top 
 Profile  
 
 Post subject: Re: Send text to pic example
 Post Posted: Wed Jun 13, 2012 5:53 am 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 888
Looks ok to me. The code copied the number of characters indicated by receiveBuffer[1] into an array of char and then terminates the string with '\0' (to make it into a normal C string) before passing it to the LCD.


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 7 posts ] 

Board index » Electronics Projects » PIC18F USB development


Who is online

Users browsing this forum: No registered users and 0 guests

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Translated by MaĆ«l Soucaze © 2009 phpBB.fr