Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 7372800UL
- #include <avr/io.h>
- #include <util/delay.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <avr/interrupt.h>
- #include "lcd.h"
- uint8_t i;
- uint8_t values[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
- uint8_t data[4] = {0, 0, 0, 0};
- uint16_t stotinka = 0;
- uint16_t counter2 = 0;
- uint8_t dotOn = 0;
- uint8_t state = 0;
- void time2data(uint16_t time, uint8_t data[])
- {
- for(i=0; i<4; i++)
- {
- data[3-i] = time%10;
- time = time / 10;
- }
- }
- ISR(TIMER1_COMPA_vect)
- {
- if(state == 0)
- {
- counter2++;
- if(stotinka == 10000)
- {
- stotinka = 0;
- }
- else
- {
- stotinka++;
- }
- if(counter2 % 50 == 0)
- {
- if(dotOn == 0)
- {
- dotOn = 1;
- }
- else
- {
- dotOn = 0;
- }
- }
- time2data(stotinka, data);
- }
- }
- int main(void)
- {
- DDRA = 0xff;
- DDRB = 0xf0;
- PORTB = 0x0f;
- TCCR1B = _BV(WGM12) | _BV(CS11);
- OCR1A = 9215;
- TIMSK = _BV(OCIE1A);
- sei();
- while (1)
- {
- if(bit_is_clear(PINB, 0))
- {
- if(state == 0)
- {
- state = 1;
- }
- else
- {
- state = 0;
- }
- }
- if(bit_is_clear(PINB, 1))
- {
- stotinka = 0;
- for(i=0; i<4; i++)
- {
- data[i] = 0;
- }
- }
- for(i=0; i<4; i++)
- {
- PORTA = values[data[i]];
- if(dotOn == 1 && i == 1)
- {
- PORTA |= _BV(7);
- }
- PORTB &= 0x0f;
- PORTB |= _BV(4+i);
- _delay_ms(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement