Advertisement
Guest User

aici

a guest
May 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <p18f4455.h>
  2. #include <usart.h>
  3.  
  4. #define apasat 0
  5. #define eliberat 1
  6. #define buton1 PORTDbits.RD0
  7. #define buton2 PORTDbits.RD1
  8.  
  9. char data;
  10. void main()
  11. {
  12. //initializare port
  13. PORTD=0;
  14. LATD=0;
  15. TRISD=0b00000011; //0,1 butoane
  16.  
  17. //initializare port leduri
  18. PORTB=0;
  19. LATB=0;
  20. TRISB=0b00000000;//iesire
  21.  
  22.  
  23. // iniţializare port serial
  24. // configurare viteza de transmisie 9600bps
  25. TXSTAbits.BRGH = 0;
  26. BAUDCONbits.BRG16 = 0;
  27. SPBRG = 77;
  28. // activare comunicaţie serială asincronă
  29. TXSTAbits.SYNC=0;
  30. // activare modul EUSART
  31. RCSTAbits.SPEN=1;
  32. // configurare pini
  33. TRISCbits.TRISC6 = 1;
  34. TRISCbits.TRISC7 = 1;
  35. // date cu polaritate neinversată
  36. BAUDCONbits.RXDTP = 0;
  37. BAUDCONbits.TXCKP = 0;
  38. // pornire transmisie şi recepţie
  39. TXSTAbits.TXEN = 1;
  40. RCSTAbits.CREN = 1;
  41.  
  42. // transmisia
  43. //TXREG =‘A’; // se transmite caracterul ‘A’
  44. //while (TXSTAbits.TRMT==0); //test sfârşit de transmisie
  45. // când se ajunge în acest punct transmisia s-a realizat
  46.  
  47. while(1)
  48. {
  49. if(buton1==apasat)
  50. {
  51. putrsUSART("Salut \n");
  52. LATB=0b11111100;
  53. Delay10KTCYx(120);
  54. }
  55. if(buton2==apasat)
  56. putrsUSART("Salut de pe butonul 2 \n");
  57. LATB=0b00000011;
  58. Delay10KTCYx(120);
  59.  
  60.  
  61.  
  62.  
  63. }
  64. //receptia
  65. while(PIR1bits.RCIF==0); // test recepţie
  66. //când se ajunge în acest punct s-au primit date
  67. PIR1bits.RCIF = 1; // ştergere flag
  68. data = RCREG;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement