Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 16000000UL
- #include <avr/io.h>
- #include <math.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #include "cyfry.h"
- class Dioda{
- private:
- int _status;
- int _pin;
- public:
- Dioda(int pin){
- _status=0;
- _pin=pin;
- DDRA|=(1<<pin); //jako wyjscie
- }
- ~Dioda(){
- PORTA|=(1<<_pin);
- }
- void wlacz(int status){
- if (status){
- _status=1;
- PORTA&=~(1<<_pin);
- } else{
- _status=0;
- PORTA|=(1<<_pin);
- }
- }
- };
- class Przycisk{
- private:
- int _pin;
- public:
- Przycisk(int pin){
- _pin=pin;
- DDRA&=~pin; //jako wejscie
- PORTA|=pin;
- }
- int checkstatus(){
- if(!(PINA & (1<<_pin) )){
- return 1;
- }
- return 0;
- }
- };
- class Wyswietlacz{
- private:
- int _pin;
- int segment(int digit){
- switch (digit){
- case 0: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F);
- case 1: return ~(SEG_B|SEG_C);
- case 2: return ~(SEG_A|SEG_B|SEG_D|SEG_E|SEG_G);
- case 3: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_G);
- case 4: return ~(SEG_B|SEG_C|SEG_F|SEG_G);
- case 5: return ~(SEG_A|SEG_C|SEG_D|SEG_F|SEG_G);
- case 6: return ~(SEG_A|SEG_C|SEG_D|SEG_E|SEG_F|SEG_G);
- case 7: return ~(SEG_A|SEG_B|SEG_C|SEG_F);
- case 8: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F|SEG_G);
- case 9: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_F|SEG_G);
- default: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F);
- }
- }
- public:
- volatile int cyfra;
- Wyswietlacz(int pin){
- _pin=pin;
- cyfra=0;
- PORTC&=~(1<<pin);
- }
- ~Wyswietlacz(){
- PORTC|=(1<<_pin);
- }
- void set(){
- PORTC=~(1<<_pin);
- }
- void show(int digit){
- PORTA=segment(digit);
- }
- };
- Wyswietlacz w1(0);
- Wyswietlacz w2(1);
- ISR(TIMER2_COMP_vect){
- w1.set();
- w1.show(w1.cyfra);
- _delay_ms(1);
- w2.set();
- w2.show(w2.cyfra);
- _delay_ms(1);
- }
- int main(void){
- DDRA=0xFF;
- DDRC=0xFF;
- /*TIMER*/
- TCCR2=(1<<WGM21);
- TCCR2|=((1<CS21) | (1<<CS22) | (1<CS20));
- TIMSK=(1<<OCIE2);
- OCR2=99;
- sei();//wlaczanie
- volatile int c1,c2;
- //const int a= Wyswietlacz::cyfry;
- //PORTA=Wyswietlacz::cyfry[1];
- //1 wyjscie
- while(1){
- w1.cyfra=1;
- w2.cyfra=2;
- w1.cyfra=4;
- w2.cyfra=4;
- //w1.show(w1.cyfra);
- //w2.show(w2.cyfra);
- }
- /*
- TCCR2=(1<<WGM21);
- TCCR2|=((1<CS21) | (1<<CS22) | (1<CS20));
- TIMSK=(1<<OCIE2);
- OCR2=99;
- //sei();//wlaczanie
- cli();//wylaczene
- */
- /*
- Dioda Dioda1(2);
- Dioda Dioda2(3);
- Dioda Dioda3(4);
- Przycisk Przycsik1(0);
- Przycisk Przycsik2(1);
- PORTA=0xff;
- while(1){
- if(Przycsik1.checkstatus() && Przycsik2.checkstatus()){
- Dioda Dioda4(5);
- while(Przycsik1.checkstatus() && Przycsik2.checkstatus())
- Dioda4.wlacz(1);
- }
- Dioda2.wlacz(Przycsik2.checkstatus());
- Dioda1.wlacz(Przycsik1.checkstatus());
- _delay_ms(200);
- }*/
- }
Add Comment
Please, Sign In to add comment