Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with USART communication between 2 PIC18F6585

Status
Not open for further replies.

ykornx

New Member
Hi, i'm trying to make RS232 communication between two boards with PIC18F6585, keypad and LCD. I want to send characters from the board1 keypad to board2 LCD and vice versa. The first thing works fine. I'm sending from board1's keypad and receivig to board2's LCD. But when i'm trying to send from board2 and receive to board1 the boards just hang-up. I am using two functions for transmit and receive.
The function kbd() reads the character from the keypad and sends it to the USART. The usart() function reads the USART buffer and sends the characters to the LCD. I'm trying to switch these functions when i press the '*' key on the keypad.
I am using the C18 compiler and the standard function for the USART included in usart.h.
I'll post my code for you to understand exactly what i'm trying to do.
I have this code on the two boards with that difference that in the main() function of the board1 firts is the kbd() and then the usart() and on the board2 first is the usart() and then the kbd().
Code:
void kbd(void); 
 void usart(void); 
 
 void init() { 
     OpenUSART(    USART_TX_INT_OFF & 
                 USART_RX_INT_OFF & 
                 USART_ASYNCH_MODE & 
                 USART_EIGHT_BIT & 
                 USART_CONT_RX & 
                 USART_BRGH_HIGH, 
                 64); 
     init_usart(); 
     init_keyboard();    
     lcdInit(); 
     init_timer();     
 } 
 
 void usart()     
 {     
     int flag = 0; 
     int count = 0; 
     int result; 
 
     while(flag!=1) 
     {     
         while(count!=16) 
         { 
         while(BusyUSART()); 
         while(!DataRdyUSART()); 
         result = ReadUSART(); 
         lcdSendData(result); 
     if(result == 42)  
         {     
             flag = 1; 
             break; 
         } 
         count++; 
         } 
     count = 0; 
     lcdSetSecondLine(); 
     while(count!=16) 
         { 
         while(BusyUSART()); 
         while(!DataRdyUSART()); 
         result = ReadUSART(); 
         lcdSendData(result); 
     if(result == 42)  
         {     
             flag = 1; 
             break; 
         } 
         count++; 
         } 
     count = 0; 
     lcdClear(); 
     lcdSetFirstLine(); 
     } 
 } 
      
 void main(void) 
 { 
     init(); 
      
     lcdClear(); 
     lcdWriteText("LCD Loaded..."); 
     lcdSetSecondLine(); 
     lcdWriteText("Hello!"); 
     delay_1s; 
     lcdClear(); 
     lcdSetFirstLine(); 
           
     //board1                      //board2
     kbd();                          usart();
     usart();                        kbd();  
      
     while(1); 
 } // void main(void); 
 
 void kbd(void) 
 { 
     int flag=0; 
     int result; 
     unsigned char keyboard_button; 
 
     while(flag!=1){ 
         keyboard_button=check_button();       
         switch (keyboard_button) { 
             case 48: // button 0 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break;     
             case 49: // button 1 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break;     
             case 50: // button 2 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break; 
             case 51: // button 3 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break; 
             case 52: // button 4 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break;     
             case 53: // button 5 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break;     
             case 54: // button 6 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break; 
             case 55: // button 7 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break;     
             case 56: // button 8 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break;     
             case 57: // button 9 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 WriteUSART(keyboard_button); 
                 break; 
             case 35: // button # 
                 lcdClear(); 
                 break; 
             case 42: // button * 
                 lcdSendData(keyboard_button); 
                 delay_100ms;delay_100ms; 
                 flag = 1; 
                 lcdClear(); 
                 break; 
             } 
     } 
 }

Thanks
 

Attachments

  • platki_small.jpg
    platki_small.jpg
    171.1 KB · Views: 174
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top