Guest User

Untitled

a guest
Sep 4th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3.  
  4. #include "usart.h"
  5. #include "twi.h"
  6.  
  7. int main (void){
  8.  
  9. USART_Init (MYUBRR);
  10. i2cSetBitrate(100);
  11.  
  12. enum {sek, min, godz, dtyg, dn, mies, rok};
  13. uint8_t bufor[7];
  14. uint8_t sekundy, minuty, godziny, dnityg, dni, miesiace, lata;
  15.  
  16. bufor[0] = dec2bcd(40); //sekundy
  17. bufor[1] = dec2bcd(59); //minuty
  18. bufor[2] = dec2bcd(23); //godziny
  19. bufor[3] = dec2bcd(7); //dni tygodnia
  20. bufor[4] = dec2bcd(4); //dni
  21. bufor[5] = dec2bcd(9); //miesiące
  22. bufor[6] = dec2bcd(16); //lata
  23. TWI_write_buf (0xD0, 0x00, 7, bufor); //ustawienie godziny minuty i sekundy
  24.  
  25. while (1){
  26. TWI_read_buf (0xD0, 0x00, 3, bufor);
  27. sekundy = bcd2dec (bufor[sek]);
  28. minuty = bcd2dec (bufor[min]);
  29. godziny = bcd2dec (bufor[godz]);
  30. dnityg = bcd2dec (bufor[dtyg]);
  31. dni = bcd2dec (bufor[dn]);
  32. miesiace = bcd2dec (bufor[mies]);
  33. lata = bcd2dec (bufor[rok]);
  34. USART_Transmit_Int (godziny); //wyślij godzinę
  35. USART_Transmit_String (":");
  36. USART_Transmit_Int (minuty); //wyślij minutę
  37. USART_Transmit_String (":");
  38. USART_Transmit_Int (sekundy); //wyślij sekundę
  39. USART_Transmit (0x0d); //wyślij znak CR (enter)
  40. USART_Transmit (0x0a); //wyślij znak LF (nowa linia)
  41. USART_Transmit_Int (dni); //wyślij dzień
  42. USART_Transmit_String (".");
  43. USART_Transmit_Int (miesiace); //wyślij miesiąc
  44. USART_Transmit_String (".");
  45. USART_Transmit_Int (lata); //wyślij rok
  46. USART_Transmit (0x0d); //wyślij znak CR (enter)
  47. USART_Transmit (0x0a); //wyślij znak LF (nowa linia)
  48. USART_Transmit_Int (dnityg); //wyślij dzień tygodnia
  49. USART_Transmit (0x0d); //wyślij znak CR (enter)
  50. USART_Transmit (0x0a); //wyślij znak LF (nowa linia)
  51. _delay_ms(1000);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment