Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to catch string from VB to be store and display in PIC with LCD

Status
Not open for further replies.

rizwan128

Newbie level 5
Newbie level 5
Joined
May 24, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,340
Hye all,

Currently i'm developing program that can communicate between PC and PIC, for PC GUI, i'm using visual basic and for PIC, i'm using 16f877A and PCWH pic c compiler as the software. i have no problem on sending one ascii character from VB GUI to PIC and retrieving data from PIC to VB GUI. The problem is, is that possible to send string to PIC from VB GUI and store the value inside PIC and then display send value to LCD. i.e, PIC send signal to VB GUI to retrieve value, then VB GUI send value to PIC, let say an integer of 12345, then PIC will take that value and store it in it's variable, let say A, so now value of A will be 12345, then this value of A will be display on LCD.

Any help will be much appreciated,

thanks.
 

If you can send one ascii character then you can send many ascii characters.
This implies you can send strings to PIC from your PC, Right???
The only problem i guess You are facing is storing, Right???

Do you want to store it permanently or temporaryly?

If youy need to store temporarily then you can store it in a variable and send it to the LCD routine.

Well when Integer 1234 is sent to the PIC over a serial link it first converted to string, Then character by character it us sent to the PIC.
On PIC side you should take care how to convert it back or how to manipulate.

Hope this helps.
 

If you can send one ascii character then you can send many ascii characters.
This implies you can send strings to PIC from your PC, Right???
The only problem i guess You are facing is storing, Right???

Do you want to store it permanently or temporaryly?

If youy need to store temporarily then you can store it in a variable and send it to the LCD routine.

Well when Integer 1234 is sent to the PIC over a serial link it first converted to string, Then character by character it us sent to the PIC.
On PIC side you should take care how to convert it back or how to manipulate.

Hope this helps.

Yup, i could'nt find the way on catching the single character and store it as one string, then assign the string to one variable, i'm going to store the string temporary with a variable, do you have any example to do so? i'm using ccs pic c compiler.
 

Yup, i could'nt find the way on catching the single character and store it as one string, then assign the string to one variable, i'm going to store the string temporary with a variable, do you have any example to do so? i'm using ccs pic c compiler.

Well To receive a string on PIC side you should know how the UART_Read_Char() functions. and There must be a terminating condition.

so if I write a function to read a string then it may look like this ++++ THIS IS PSEUDO CODE +++++
Code:
Global  :
unsigned int i;
unsigned char a[20]="" ; //empty string of 19 char + '\0'
void MyReadString()
{
          for(i=0 ; i<19 ; i++)
          {
                 a[i] = UART_Receive_char();
          }
          a[i] = '\0';
}
 
Well To receive a string on PIC side you should know how the UART_Read_Char() functions. and There must be a terminating condition.

so if I write a function to read a string then it may look like this ++++ THIS IS PSEUDO CODE +++++
Code:
Global  :
unsigned int i;
unsigned char a[20]="" ; //empty string of 19 char + '\0'
void MyReadString()
{
          for(i=0 ; i<19 ; i++)
          {
                 a[i] = UART_Receive_char();
          }
          a[i] = '\0';
}

OK, before i try with this method, i would like to know on the GUI side, do i need to send 1 character at a time or i can send directly 1 string to be read by PIC?
 

OK, before i try with this method, i would like to know on the GUI side, do i need to send 1 character at a time or i can send directly 1 string to be read by PIC?

GUI side ??? do you mean on PC side???
If the above assumption is true then you have to send a string not more than 19 chars or better send char by char.
 

GUI side ??? do you mean on PC side???
If the above assumption is true then you have to send a string not more than 19 chars or better send char by char.

GUI = Graphical User Interface, yup, on PC side. Hard for me to send it char by char since the string will be retrieve from excell database, but i'll try both method, sending char by char and sending string in one shot, i'll inform you latter on any progress.
 

Code:
  for(i=0;i<5;i++)
            { 
          string[i]=getc();          
            }      
            
            lcd_gotoxy(1,1);
            printf(lcd_putc,"Read=%s",string);

i tried to use the above code, it works fine if i send 5 character at one time, and display it correctly, but it wont work if i send less then 5 character, program will wait until 5 character has been read and display it on LCD, do you have any idea on how am i going to solve this, since the character that will be send to PIC is not fix.
 

Code:
  for(i=0;i<5;i++)
            { 
          string[i]=getc();          
            }      
            
            lcd_gotoxy(1,1);
            printf(lcd_putc,"Read=%s",string);

i tried to use the above code, it works fine if i send 5 character at one time, and display it correctly, but it wont work if i send less then 5 character, program will wait until 5 character has been read and display it on LCD, do you have any idea on how am i going to solve this, since the character that will be send to PIC is not fix.

So you got something working.:cool:

if you just change the loop and check the EOL character then you are done. Try it.
 

So you got something working.:cool:

if you just change the loop and check the EOL character then you are done. Try it.

Yup, thanks to you ;-). But i did'nt quite understand on changing the loop and check for EOL, can you give some example and a little explanation.
 

Yup, thanks to you ;-). But i did'nt quite understand on changing the loop and check for EOL, can you give some example and a little explanation.

The Clue is EOL = End Of Line character. which is '\0' or NULL character.

So if you itterate a loop until you get the EOL then your purpose is solved.

This is covered in any standard C text book under String handling.
[PSEUDOCODE]
while( ch = getc() != '\0')
{
store in string
}
store NULL character
[/PSEUDOCODE]
See the EOL is a misnomer BUT when it is stored in a file or sent to a terminal the '\0' is treated differently.
The actual EOL id 0x0d 0x0a the CRLF pair.
 

Code:
 while(true)
 {
      lcd_gotoxy(1,1); // Column,Row
      printf(lcd_putc,"Read=%s",string);
      
    while(getc()!='\n')
    {
            for(i=0;i<5;i++)
            { 
               string[i]=getc();          
            }      
    }          
 }

i tried to use the above code, but it wont work, displayed string is not the same as entered, can you tell me what's wrong?
 

Code:
 while(true)
 {
      lcd_gotoxy(1,1); // Column,Row
      printf(lcd_putc,"Read=%s",string);
      
    while(getc()!='\n')
    {
            for(i=0;i<5;i++)
            { 
               string[i]=getc();          
            }      
    }          
 }

i tried to use the above code, but it wont work, displayed string is not the same as entered, can you tell me what's wrong?

replace '\n' with '\0'
 

i changed it, but still not working :sad:
 

i tried sooo many time, with a lot of trial and error, but still i could'nt get desired output, then i decided to send fix number of character and eliminate unwanted character, i.e, i'm sending ---123, then it will display 123, have to do the hard way, but it works, thanks ;-)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top