Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <REGX52.H>
- void uart_init()
- {
- EA=1;
- ES=1;
- TMOD = 0x20;
- SCON = 0x50;
- TH1 = 0xFD;
- TR1=1;
- TI=0;
- RI=0;
- //Ustawic SCON
- //Ustawic przerwania
- //Ustawic rejestry przerwan wysylania i odbierania
- //Ustawic timer
- }
- void uart_send(char c)
- {
- //Zmieniac na tryb nadawania
- //Dopisac
- //Zmieniac na tryb nasluchiwania
- P3_4=1;
- SBUF = c;
- while (TI==0);
- TI = 0;
- P3_4=0;
- }
- void uart_sendbuffer(char * buffer, unsigned int count)
- {
- unsigned int i = 0;
- for(i = 0; i < count; i++)
- uart_send(buffer[i]);
- }
- //Po odpowiednim ustawieniu
- //funkcja ta wykona sie gdy odebrany zostanie bajt danych
- //BARDZO WAZNE JA USTAWIC (wyzerowac rejestry) NAWET JAK TYLKO NADAJE
- void ISR_Serial (void) interrupt 4
- {
- if(RI==1) RI=0;
- }
- char * buffer [4] = {"Przemek ", "Szczesniak ", "I7Y6S1 ", "23.05.2019"};
- unsigned char counter = 0;
- void main(void)
- {
- unsigned int i=0;
- uart_init();
- P3_4 = 0; //Tryb nasluchiwania
- while(1)
- {
- P2 = ~(0x80 >> (counter++ % 4));
- //Przycisk 1
- if(P2_4 == 0 && P2_3 == 0)
- {
- uart_send(0x01);
- uart_sendbuffer(buffer[0], 7);
- uart_send('\0');
- P0_0 = ~P0_0;
- for(i=0;i<10000;i++);
- }
- if(P2_4 == 0 && P2_2 == 0)
- {
- uart_send(0x02);
- uart_sendbuffer(buffer[1], 11);
- uart_send('\0');
- P0_0 = ~P0_0;
- for(i=0;i<10000;i++);
- }
- if(P2_4 == 0 && P2_1 == 0)
- {
- uart_send(0x03);
- uart_sendbuffer(buffer[2], 11);
- uart_send('\0');
- P0_0 = ~P0_0;
- for(i=0;i<10000;i++);
- }
- if(P2_5 == 0 && P2_3 == 0)
- {
- uart_send(0x04);
- uart_sendbuffer(buffer[3], 11);
- uart_send('\0');
- P0_0 = ~P0_0;
- for(i=0;i<10000;i++);
- }
- //Przycisk 9
- if(P2_1 == 0 && P2_6 == 0)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement