Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr\signal.h>
- #include <avr\interrupt.h>
- #include <avr\delay.h>
- #define LED0 0b10000010
- #define LED1 0b11010111
- #define LED2 0b00100011
- #define LED3 0b01000011
- #define LED4 0b01010110
- #define LED5 0b01001010
- #define LED6 0b00001010
- #define LED7 0b11000111
- #define LED8 0b00000010
- #define LED9 0b01000010
- #define LEDA 0b00000110
- #define LEDB 0b00011010
- #define LEDC 0b10101010
- #define LEDD 0b00010011
- #define LEDE 0b00101010
- #define LEDF 0b00101110
- #define DDR_LED DDRB
- #define DDR_WYSW DDRD
- #define PORT_LED PORTB
- #define PORT_WYSW PORTD
- #define DDR_SW DDRE
- #define PORT_SW PORTE
- #define PIN_SW PINE
- volatile uint16_t g_Czekaj = 0;
- volatile uint16_t g_Czekaj2 = 0;
- uint8_t g_AktWyswietlacz = 0;
- uint8_t g_WyborWyswietlacza[4] = { 0b11011111, 0b11101111, 0b11110111, 0b11111011 };
- uint8_t g_Cyfry [10] = { LED0, LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8, LED9 };
- uint8_t g_DaneWyswietlacza [4] = { 0, 0,0,0};
- int main( void )
- {
- DDR_LED = 0xff; DDR_WYSW |= 0b00111100;
- TCCR0 = 1<<CS02|1<<CS00;
- TIMSK = 1<<TOIE0;
- sei();
- int licznik = 0000;
- for(;;) {
- if ( !(PIN_SW & 0b00000001) ) {
- if( g_Czekaj == 0 ){
- g_Czekaj = 100;
- licznik++;
- }
- }
- if ( !(PIN_SW & 0b00000010) ) {
- if( g_Czekaj2 == 0 ){
- g_Czekaj2 = 100;
- licznik--;
- }
- }
- for(int i=0;i<15;i++){
- _delay_loop_2(0xffff);
- }
- if (licznik > 9999){
- licznik = 0;
- }
- g_DaneWyswietlacza [3] = g_Cyfry[licznik % 10];
- g_DaneWyswietlacza [2] = g_Cyfry[(licznik / 10)%10];
- g_DaneWyswietlacza [1] = g_Cyfry[(licznik / 100)%10];
- g_DaneWyswietlacza [0] = g_Cyfry[(licznik / 1000)%10];
- }
- return 0;
- }
- SIGNAL( SIG_OVERFLOW0 ){
- if( g_Czekaj > 0 ){
- g_Czekaj--;
- }
- if( g_Czekaj2 > 0 ){
- g_Czekaj2--;
- }
- PORT_WYSW |= 0b00111100;
- PORT_LED = g_DaneWyswietlacza[g_AktWyswietlacz];
- PORT_WYSW &= g_WyborWyswietlacza[g_AktWyswietlacz];
- g_AktWyswietlacz++;
- if( g_AktWyswietlacz> 3 ){
- g_AktWyswietlacz= 0;
- }
- TCNT0 = 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement