Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <p18f4455.h>
- #include <usart.h>
- #define apasat 0
- #define eliberat 1
- #define buton1 PORTDbits.RD0
- #define buton2 PORTDbits.RD1
- char data;
- void main()
- {
- //initializare port
- PORTD=0;
- LATD=0;
- TRISD=0b00000011; //0,1 butoane
- //initializare port leduri
- PORTB=0;
- LATB=0;
- TRISB=0b00000000;//iesire
- // iniţializare port serial
- // configurare viteza de transmisie 9600bps
- TXSTAbits.BRGH = 0;
- BAUDCONbits.BRG16 = 0;
- SPBRG = 77;
- // activare comunicaţie serială asincronă
- TXSTAbits.SYNC=0;
- // activare modul EUSART
- RCSTAbits.SPEN=1;
- // configurare pini
- TRISCbits.TRISC6 = 1;
- TRISCbits.TRISC7 = 1;
- // date cu polaritate neinversată
- BAUDCONbits.RXDTP = 0;
- BAUDCONbits.TXCKP = 0;
- // pornire transmisie şi recepţie
- TXSTAbits.TXEN = 1;
- RCSTAbits.CREN = 1;
- // transmisia
- //TXREG =‘A’; // se transmite caracterul ‘A’
- //while (TXSTAbits.TRMT==0); //test sfârşit de transmisie
- // când se ajunge în acest punct transmisia s-a realizat
- while(1)
- {
- if(buton1==apasat)
- {
- putrsUSART("Salut \n");
- LATB=0b11111100;
- Delay10KTCYx(120);
- }
- if(buton2==apasat)
- putrsUSART("Salut de pe butonul 2 \n");
- LATB=0b00000011;
- Delay10KTCYx(120);
- }
- //receptia
- while(PIR1bits.RCIF==0); // test recepţie
- //când se ajunge în acest punct s-au primit date
- PIR1bits.RCIF = 1; // ştergere flag
- data = RCREG;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement