Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #include "usart.h"
- #include "twi.h"
- int main (void){
- USART_Init (MYUBRR);
- i2cSetBitrate(100);
- enum {sek, min, godz, dtyg, dn, mies, rok};
- uint8_t bufor[7];
- uint8_t sekundy, minuty, godziny, dnityg, dni, miesiace, lata;
- bufor[0] = dec2bcd(40); //sekundy
- bufor[1] = dec2bcd(59); //minuty
- bufor[2] = dec2bcd(23); //godziny
- bufor[3] = dec2bcd(7); //dni tygodnia
- bufor[4] = dec2bcd(4); //dni
- bufor[5] = dec2bcd(9); //miesiące
- bufor[6] = dec2bcd(16); //lata
- TWI_write_buf (0xD0, 0x00, 7, bufor); //ustawienie godziny minuty i sekundy
- while (1){
- TWI_read_buf (0xD0, 0x00, 3, bufor);
- sekundy = bcd2dec (bufor[sek]);
- minuty = bcd2dec (bufor[min]);
- godziny = bcd2dec (bufor[godz]);
- dnityg = bcd2dec (bufor[dtyg]);
- dni = bcd2dec (bufor[dn]);
- miesiace = bcd2dec (bufor[mies]);
- lata = bcd2dec (bufor[rok]);
- USART_Transmit_Int (godziny); //wyślij godzinę
- USART_Transmit_String (":");
- USART_Transmit_Int (minuty); //wyślij minutę
- USART_Transmit_String (":");
- USART_Transmit_Int (sekundy); //wyślij sekundę
- USART_Transmit (0x0d); //wyślij znak CR (enter)
- USART_Transmit (0x0a); //wyślij znak LF (nowa linia)
- USART_Transmit_Int (dni); //wyślij dzień
- USART_Transmit_String (".");
- USART_Transmit_Int (miesiace); //wyślij miesiąc
- USART_Transmit_String (".");
- USART_Transmit_Int (lata); //wyślij rok
- USART_Transmit (0x0d); //wyślij znak CR (enter)
- USART_Transmit (0x0a); //wyślij znak LF (nowa linia)
- USART_Transmit_Int (dnityg); //wyślij dzień tygodnia
- USART_Transmit (0x0d); //wyślij znak CR (enter)
- USART_Transmit (0x0a); //wyślij znak LF (nowa linia)
- _delay_ms(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment