Advertisement
Guest User

klaw

a guest
May 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.73 KB | None | 0 0
  1. #include <REGX52.H>
  2.  
  3. void uart_init()
  4. {  
  5.     EA=1;
  6.     ES=1;
  7.     TMOD = 0x20;
  8.     SCON = 0x50;
  9.     TH1 = 0xFD;
  10.     TR1=1;
  11.     TI=0;
  12.     RI=0;
  13.     //Ustawic SCON
  14.     //Ustawic przerwania
  15.     //Ustawic rejestry przerwan wysylania i odbierania
  16.     //Ustawic timer
  17. }
  18.  
  19. void uart_send(char c)
  20. {
  21.     //Zmieniac na tryb nadawania
  22.     //Dopisac
  23.     //Zmieniac na tryb nasluchiwania
  24.     P3_4=1;
  25.     SBUF = c;
  26.     while (TI==0);     
  27.     TI = 0;
  28.     P3_4=0;
  29. }
  30.  
  31. void uart_sendbuffer(char * buffer, unsigned int count)
  32. {
  33.     unsigned int i = 0;
  34.     for(i = 0; i < count; i++)
  35.         uart_send(buffer[i]);
  36. }
  37.  
  38. //Po odpowiednim ustawieniu
  39. //funkcja ta wykona sie gdy odebrany zostanie bajt danych
  40. //BARDZO WAZNE JA USTAWIC (wyzerowac rejestry) NAWET JAK TYLKO NADAJE
  41. void ISR_Serial (void) interrupt 4
  42. {
  43.     if(RI==1) RI=0;
  44. }
  45.  
  46. char * buffer [4] = {"Przemek   ", "Szczesniak      ", "I7Y6S1    ", "23.05.2019"};
  47.  
  48. unsigned char counter = 0;
  49. void main(void)
  50. {
  51.     unsigned int i=0;
  52.     uart_init();
  53.     P3_4 = 0; //Tryb nasluchiwania
  54.    
  55.     while(1)
  56.     {
  57.         P2 = ~(0x80 >> (counter++ % 4));
  58.        
  59.         //Przycisk 1
  60.         if(P2_4 == 0 && P2_3 == 0)
  61.         {
  62.             uart_send(0x01);
  63.             uart_sendbuffer(buffer[0], 7);
  64.             uart_send('\0');
  65.             P0_0 = ~P0_0;
  66.             for(i=0;i<10000;i++);
  67.         }  
  68.        
  69.         if(P2_4 == 0 && P2_2 == 0)
  70.         {
  71.             uart_send(0x02);
  72.             uart_sendbuffer(buffer[1], 11);
  73.             uart_send('\0');
  74.             P0_0 = ~P0_0;
  75.             for(i=0;i<10000;i++);
  76.         }  
  77.         if(P2_4 == 0 && P2_1 == 0)
  78.         {
  79.             uart_send(0x03);
  80.             uart_sendbuffer(buffer[2], 11);
  81.             uart_send('\0');
  82.             P0_0 = ~P0_0;
  83.             for(i=0;i<10000;i++);
  84.         }  
  85.         if(P2_5 == 0 && P2_3 == 0)
  86.         {
  87.             uart_send(0x04);
  88.             uart_sendbuffer(buffer[3], 11);
  89.             uart_send('\0');
  90.             P0_0 = ~P0_0;
  91.             for(i=0;i<10000;i++);
  92.         }  
  93.         //Przycisk 9
  94.         if(P2_1 == 0 && P2_6 == 0)
  95.         {
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement