çift yönlü uart problemi

Başlatan MCansız, 20 Nisan 2014, 18:06:12

MCansız

merhaba arkadaşlar uart üzerinden birbiri ile haberleşen 2 adet devrem var devreler hem alıcı hem verici durumunda şimdi devre1 ile bir değişkeni bir arttırıp  yolluyorum ve devre2 bunu alıp ekrana veriyor burada sıkıntı yok  devre2 veriyi aldıktan sonra veri göndermeye çalışınca sistem kitleniyo (örnekte bir değişkeni arttırıp yolladım devre2 de gelen değişken 15 olunca devre1 e veri yolluyor burada sistem kitleniyor) bunu çözmek için interrupt kullandım ama fayda etmedi sistemi gerçekte kablo ile denedim ve gerçekten değişken 15 olunca kitleniyor nasıl bir sistem kurulmalı?

şema




devre1   

sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;   sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;   sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;  sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;  sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;  sbit LCD_D7_Direction at TRISD7_bit;

char uart_rd,ax=0,bx=0,cx=0,dx,i,msg[20];
char txt[10];

void interrupt() {
  if (RCIF_bit == 1){
    TXEN_bit=0;
    UART1_Read_Text(txt,"K",255);
    cx= atoi(txt);

    if (cx ==222 ) {
    porta=~porta; 
    cx=0;
    }
    TXEN_bit=1;
    RCIF_bit = 0;
                     }
}

void main() {
  ADCON1 |= 0x0F;                         // Configure all ports with analog function as digital
  CMCON  |= 7;
  TRISb=255;
  TRISa=0;
  porta=0;
  portb=255;
  Lcd_Init();
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100); 
  SYNC_bit=0;BRGH_bit=0;BRG16_bit=1;
  txsta.SYNC =0; rcsta.SPEN=1; rcsta.cren=1;TXEN_bit=1;
  
  RCIE_bit = 1;                   // Enable USART Receiver interrupt
  GIE_bit = 1;                     // Enable Global interrupt
  PEIE_bit = 1;                    // Enable Peripheral interrupt
  
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1,2,"devre1");
  
  
  while (1) {
   ax++;
   byteToStr(ax,msg);
   Lcd_Out(3,5,msg);
   
    UART1_Write_Text("B");
    UART1_Write_text(msg);
   
   
   Lcd_Out(4,1,txt);


  }
}


devre2
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;   sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;   sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;  sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;  sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;  sbit LCD_D7_Direction at TRISD7_bit;
char output[10];
char uart_rd,ax=0,bx=3,cx,dx,msg[5];


void main() {
   ADCON1 |= 0x0F;                         // Configure all ports with analog function as digital
  CMCON  |= 7;
  TRISb=0;
  portb=0;
  Lcd_Init();
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);
  SYNC_bit=0;BRGH_bit=0;BRG16_bit=1;
  txsta.SYNC =0; rcsta.SPEN=1; rcsta.cren=1;TXEN_bit=1;
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                  // Wait for UART module to stabilize
  Lcd_Out(1,2,"devre2");

  while (1) {                     // Endless loop

     if (UART1_Data_Ready())
                                  
                                      {    
       
                                  UART1_Read_Text(output,"B",255);

                                  ax= atoi(output);
                                  portb=ax;
                                  Lcd_Out(3,5,output);

                                  if (ax==15){
                                              UART1_Write_Text("K222");
          
                                                    }
          
                            }
    }
  }


proje dosyaları için https://drive.google.com/file/d/0B6kE5UwAIcnNWmtsZThPempZX00/edit?usp=sharing