dim912
Junior Member level 2
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..
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..