Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ********************************************
- // Project:
- // Author:
- // Module description:
- // ***********************************************************
- #include <avr\io.h> // Most basic include files
- #include <avr\interrupt.h> // Add the necessary ones
- #define F_CPU 11059200U
- #include <avr\signal.h> // here
- uint8_t Koduj(uint8_t wartosc)
- {
- uint8_t wynik = 0;
- switch(wartosc)
- {
- // PPPPPPPP
- // AAAAAAAA
- // 76543210
- case 0 : wynik = 0b00111111; break;
- case 1 : wynik = 0b00000110; break;
- case 2 : wynik = 0b01011011; break;
- case 3 : wynik = 0b01001111; break;
- case 4 : wynik = 0b01100110; break;
- case 5 : wynik = 0b01101101; break;
- case 6 : wynik = 0b01111101; break;
- case 7 : wynik = 0b00000111; break;
- case 8 : wynik = 0b01111111; break;
- case 9 : wynik = 0b01101111; break;
- }
- return wynik;
- }
- void wyswietl(uint16_t counter){
- uint8_t tab[4] = {0,0,0,0};
- uint8_t ports[4] = {_BV(PE4), _BV(PE5), _BV(PE6), _BV(PE7)};
- uint8_t length = 1;
- if(counter > 10){
- tab[1] = counter%10;
- counter/=10;
- tab[0] = counter;
- length = 2;
- }else if(counter > 100){
- tab[2] = counter%10;
- counter/=10;
- tab[1] = counter%10;
- counter/=10;
- tab[0] = counter;
- length = 3;
- }else if(counter > 1000){
- tab[3] = counter%10;
- counter/=10;
- tab[2] = counter%10;
- counter/=10;
- tab[1] = counter%10;
- counter/=10;
- tab[0] = counter;
- length = 4;
- }else{
- tab[0] = counter;
- }
- for(int i=0;i<length;i++){
- PORTA = Koduj(tab[i]);
- PORTE = ports[i];
- }
- }
- uint8_t start = _BV(PE4);
- volatile uint8_t i = 1;
- volatile uint8_t state = 0;
- ISR(TIMER1_COMPA_vect){
- i = ( i > 3 ) ? 1 : i+1;
- state = 1;
- }
- int main(void) {
- DDRA = 0xFF;
- DDRE = 0xFF;
- PORTE = start;
- PORTA = Koduj(i);
- TCCR1B = _BV(CS10) | _BV(CS11) | _BV(WGM12);
- OCR1A = 100;
- TIMSK |= _BV(OCIE1A);
- uint16_t c = 0;
- // sei();
- uint8_t state4 = 0;
- uint8_t buttonState4 = 0;
- uint8_t state5 = 0;
- uint8_t buttonState5 = 0;
- while(1) {
- if(((PIND & _BV(PD4)) == 0) && buttonState4 == 0){
- state4 = !state4;
- buttonState4 = 1;
- }
- if((PIND & _BV(PD4)) != 0){
- buttonState4 = 0;
- }
- if(state4){
- c++;
- state4 = 0;
- }
- wyswietl(c);
- // PORTA = Koduj(c);
- // if((TIFR & _BV(OCF1A)) == _BV(OCF1A)){
- // i = ( i > 3 ) ? 1 : i+1;
- // PORTE = start << i-1;
- // PORTA = Koduj(i);
- // TIFR |= _BV(OCF1A);
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement