Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 14745600UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <stdio.h>
- #include <string.h>
- unsigned int ubrr = F_CPU/16/9600-1;
- unsigned int x=0;
- volatile unsigned long long taktis = 0;
- void USART_Init( unsigned int ubrr)
- {
- /* Set baud rate */
- UBRR0H = (unsigned char)(ubrr>>8);
- UBRR0L = (unsigned char)ubrr;
- /* Enable receiver and transmitter */
- UCSR0B = (1<<RXEN)|(1<<TXEN);
- /* Set frame format: 8data, 2stop bit */
- UCSR0C = (1<<USBS)|(3<<UCSZ0);
- }
- void USART_Transmit( char data2 )
- {
- /* Wait for empty transmit buffer */
- while ( !( UCSR0A & (1<<UDRE)) )
- ;
- /* Put data into buffer, sends the data */
- UDR0= data2;
- }
- void USART_String(char data1[]){
- x=0;
- while(x < strlen(data1)){
- USART_Transmit(data1[x]);
- x++;
- }
- }
- unsigned char USART_Receive( void )
- {
- /* Wait for data to be received */
- while ( !(UCSR0A & (1<<RXC)) )
- ;
- /* Get and return received data from buffer */
- return UDR0;
- }
- void EEPROM_write(unsigned int Address, unsigned char Data)
- {
- /*
- Wait for completion of previous write */
- while(EECR & (1<<EEWE));
- /*
- Set up address and data registers */
- EEAR = Address;
- EEDR = Data;
- /*
- Write logical one to EEMWE */
- EECR |= (1<<EEMWE);
- /*
- Start eeprom
- write by setting EEWE */
- EECR |= (1<<EEWE);
- }
- unsigned char EEPROM_read(unsigned int Address)
- {
- /*
- Wait for completion of previous write */
- while(EECR & (1<<EEWE));
- /*
- Set up address register */
- EEAR = Address;
- /*
- Start
- eeprom
- read by writing EERE */
- EECR |= (1<<EERE);
- /*
- Return data from data register */
- return EEDR;}
- ISR(TIMER0_OVF_vect)
- {
- taktis = taktis + 2048; //TO DO
- }
- char time[] ="00:00:00";
- int main(void)
- {
- unsigned char *sP, s = 51;
- unsigned char *mP, m = 10;
- unsigned char *hP, h = 10;
- sP=&s;
- mP=&m;
- hP=&h;
- //sprintf(time,"%02d:%02d:%02d",h,m,s);
- USART_Init(ubrr);
- //uzstada pinus uz izvadi
- DDRD = (1 << DDD7) | (1 << DDD6) | (1 << DDD5) | (1 << DDD4) | (1 << DDD3) | (1 << DDD2) | (1<<DDD1) | (1<<DDD0) ;
- // 0xFF
- PORTD = 0;
- //uzstadam takts avotu / 8
- //uzstadam taimeri
- TCCR0 = (0 << CS02) | (0 << CS01) | (1 << CS00);
- TIMSK = (1 <<TOIE0); //0x01
- //atlaujam taimera parpildes partraukumu
- unsigned long long parbaude = F_CPU*8/3600;
- sei();
- //EEPROM_write(50, 00);
- //EEPROM_write(51, 00);
- //EEPROM_write(52, 00);
- s=EEPROM_read(50);
- m=EEPROM_read(51);
- h=EEPROM_read(52);
- while(1){
- if(taktis>=parbaude){
- taktis=0;
- s++;
- if(s>=60){
- s=0;
- m++;
- }
- if(m>=60){
- h++;
- m=0;
- }
- EEPROM_write(50, *sP);
- EEPROM_write(51, *mP);
- EEPROM_write(52, *hP);
- sprintf(time,"%02d:%02d:%02d",*hP,*mP,*sP);
- USART_String(time);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement