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.

MicroC UART gives unexpected results.

Status
Not open for further replies.

dim912

Junior Member level 2
Joined
Sep 9, 2009
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Colombo
Activity points
1,524
I want to communicate a text from a PIC18F25J10 pic to a PIC16F877A device. after receiving the data PIC16F877A device will display the message on a screen. here I wrote a program for it using microC.


PIC18F25J10 (sender) program.

void main() {

TRISC=0x00;
UART1_Init(2400); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabiliz

while (1) { // Endless loop
Delay_ms(6000);
UART1_Write_Text("IamFromSriLaazzzz);

PORTC.b2=0;
Delay_ms(50);
PORTC.b2=1;
}
}



PIC16F877A (receiver) program




char GLCD_DataPort at PORTB;
sbit GLCD_CS1 at RD3_bit;
sbit GLCD_CS2 at RD4_bit;
sbit GLCD_RS at RD5_bit;
sbit GLCD_RW at RD6_bit;
sbit GLCD_EN at RD7_bit;
sbit GLCD_RST at RD2_bit;

sbit GLCD_CS1_Direction at TRISB3_bit;
sbit GLCD_CS2_Direction at TRISB4_bit;
sbit GLCD_RS_Direction at TRISB5_bit;
sbit GLCD_RW_Direction at TRISB6_bit;
sbit GLCD_EN_Direction at TRISB7_bit;
sbit GLCD_RST_Direction at TRISB2_bit;

void display_name(char * name){
Glcd_Fill(0x00);
Glcd_Set_Font(Font_Glcd_Character8x7 , 8, 7, 32); // Change font
Glcd_Write_Text("* WELCOME *",15,0,1) ; //13 letters. each 9 pixel.
Glcd_H_Line(14, 111, 11, 1);
Glcd_Set_Font(Font_Glcd_System5x7 , 5, 7, 32); // Change font
Glcd_Write_Text(name, (127-strlen(name)*6)/2 ,4,1) ; //19 letters. each 6 pixl
Glcd_H_Line((127-strlen(name)*6)/2, (127+strlen(name)*6)/2, 60, 1);
delay_ms(1000);

}

void display_idle(){
char * output;
while(1) {

Glcd_Fill(0x00);
Glcd_Set_Font(Font_Glcd_Character8x7 , 8, 7, 32); // Change font
Glcd_Write_Text("__ENTC ESMS__",6,0,1) ; //13 letters. each 9 pixel.
Glcd_H_Line(5, 122, 11, 1);
Glcd_Set_Font(Font_Glcd_System5x7 , 5, 7, 32); // Change font
Glcd_Write_Text("SWAP YOUR RFID CARD",6,4,1) ; //19 letters. each 6 pixl
Glcd_H_Line(5, 122, 60, 1);
delay_ms(100);

while(UART1_Data_Ready()==0) { // If data is received){
}

UART1_Read_Text(output,"zz",15); // reads text until 'zz' is found
display_name(output);

}
}

void main() {
TRISB=0x00;
TRISD=0x00;
GIE_bit=0;

Glcd_Init(); // Initialize GLCD
UART1_Init(2400);
delay_ms(1000);
display_idle();
}


Results : display connected to PIC16F877A does not correctly display the word sent from PIC18F25J10 device.

but if i passe a arbitrary text, to display it works correctly.

display_name("World Is beautiful"); - this word is correctly display on the screen.

but when i sent the data received through RS232 it does not work.

display_name(output); - does not work. it display a unexpected result.





As i feel there is a data loss .......at UART1_Read_Text(output,"zz",15); .

if you have any suggestion to solve this.. it will help me a lot...


thanx all..
 

All receiving data operations must be realized by interrupt. Your function:
display_name(output);
Takes a lot of time and some bytes can't be received.
Even if you will receive the data in interrupt routine, you will have to realize receive buffer. In this case incoming data stores in buffer and then goes to screen.
BUT
In your simple case, the best way is to wait for the full message and then send the whole message to screen.
To do this the package length must be a constant or you'll have to do a time-out routine.

Try to discrease connection speed to 1200 bod and lower.
 
Last edited:
  • Like
Reactions: dim912

    dim912

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top