Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include "lcd.h"
- #include <avr/interrupt.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- uint8_t stotinke = 0;
- uint8_t sekunde = 0;
- uint8_t minute = 0;
- uint8_t sati = 0;
- uint8_t state = 0;
- char intStr[10];
- char intStr2[10];
- void time2data()
- {
- sprintf(intStr, "%.2d:%.2d:%.2d", sati, minute, sekunde);
- lcd_clrscr();
- lcd_puts(intStr);
- lcd_gotoxy(0, 1);
- lcd_puts(intStr2);
- }
- ISR(TIMER0_COMP_vect)
- {
- if(state == 0)
- {
- stotinke++;
- if(stotinke == 100)
- {
- sekunde++;
- stotinke = 0;
- }
- if(sekunde == 60)
- {
- minute++;
- sekunde = 0;
- }
- if(minute == 60)
- {
- sati++;
- minute = 0;
- }
- if(sati == 24)
- {
- sati = 0;
- }
- time2data();
- }
- }
- int main(void)
- {
- DDRD = 0xff;
- DDRB = 0xf0;
- PORTB = 0x03;
- TCCR1A = _BV(COM1B1) | _BV(COM1B0) | _BV(WGM10);
- TCCR1B = _BV(WGM12) | _BV(CS11);
- OCR1B = 200;
- lcd_init(LCD_DISP_ON);
- lcd_clrscr();
- TCCR0 = _BV(WGM01) | _BV(CS02) | _BV(CS00);
- OCR0 = 71;
- TIMSK = _BV(OCIE0);
- sei();
- while (1)
- {
- if(bit_is_clear(PINB, 0))
- {
- strcpy(intStr2, intStr);
- }
- if(bit_is_clear(PINB, 1))
- {
- if(state == 0)
- {
- state = 1;
- }
- else
- {
- state = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement