Hallo
Genau so funktioniert das. Bei meinen Beispielvideos (und all den anderen Videos bei Youtube zu dem Thema) wir das so gemacht.kann man nicht die LEDs einzeln ansteuern und schnell hintereinander an und ausmachen?
Es werden dabei alle drei Zustände der AVR-Pins verwendet: High, Low und Eingang (ohne PullUp, auch Z-State genannt). Lies dich mal ein, das ist ein interessantes Thema ;)
Zur Ansicht hier mein Arbeitscode für 12 LEDs an den LEDs der RP6-Base ohne ISR (sollte auch mit der RP6-Lib funktionieren). Es wird ein statisches Bitmuster ausgegeben:
Mit ISR (und minimaler Lib) und Lauflicht. Das ist der Nightrider-Code aus den Videos:Code:// Lauflicht mit 12 LEDs an 4 Pins mit Charlieplexing 1.3.2008 mic #include "rblib.h" #include "rblib.c" volatile uint16_t bitmuster; uint8_t p=0, bit=0; int main(void) { rblib_init(); DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off bitmuster=0b110011001100; //bitmuster=0b111111111111; while(1) { if((bitmuster & (1<<bit))==1){ DDRC|=SL1; PORTC|=SL1; //SL1 high DDRC|=SL2; PORTC&=~SL2; //SL2 low DDRB&=~SL4; PORTB&=~SL4; //SL4 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==2){ DDRC|=SL1; PORTC|=SL1; //SL1 high DDRB|=SL4; PORTB&=~SL4; //SL4 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==4){ DDRC|=SL1; PORTC|=SL1; //SL1 high DDRB|=SL5; PORTB&=~SL5; //SL5 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off } if((bitmuster & (1<<bit))==8){ DDRC|=SL2; PORTC|=SL2; //SL2 high DDRC|=SL1; PORTC&=~SL1; //SL1 low DDRB&=~SL4; PORTB&=~SL4; //SL4 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==16){ DDRC|=SL2; PORTC|=SL2; //SL2 high DDRB|=SL4; PORTB&=~SL4; //SL4 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==32){ DDRC|=SL2; PORTC|=SL2; //SL2 high DDRB|=SL5; PORTB&=~SL5; //SL5 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off } if((bitmuster & (1<<bit))==64){ DDRB|=SL4; PORTB|=SL4; //SL4 high DDRC|=SL1; PORTC&=~SL1; //SL1 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==128){ DDRB|=SL4; PORTB|=SL4; //SL4 high DDRC|=SL2; PORTC&=~SL2; //SL2 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==256){ DDRB|=SL4; PORTB|=SL4; //SL4 high DDRB|=SL5; PORTB&=~SL5; //SL5 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRC&=~SL1; PORTC&=~SL1; //SL1 off } if((bitmuster & (1<<bit))==512){ DDRB|=SL5; PORTB|=SL5; //SL5 high DDRC|=SL1; PORTC&=~SL1; //SL1 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off } if((bitmuster & (1<<bit))==1024){ DDRB|=SL5; PORTB|=SL5; //SL5 high DDRC|=SL2; PORTC&=~SL2; //SL2 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off } if((bitmuster & (1<<bit))==2048){ DDRB|=SL5; PORTB|=SL5; //SL5 high DDRB|=SL4; PORTB&=~SL4; //SL4 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRC&=~SL2; PORTC&=~SL2; //SL2 off } if(bit<12) bit++; else bit=0; } return 0; }
GrußCode:// Lauflicht mit 12 LEDs an 4 Pins mit Charlieplexing 1.3.2008 mic #include "rblib.h" #include "rblib.c" uint16_t bitmuster; uint16_t demo1[]={ 0b100000000001, 0b010000000010, 0b001000000100, 0b000100001000, 0b000010010000, 0b000001100000, 0b000010010000, 0b000100001000, 0b001000000100, 0b010000000010 }; uint16_t demo2[]={ 0b110000000011, 0b011000000110, 0b001100001100, 0b000110011000, 0b000011110000, 0b000001100000, 0b000011110000, 0b000110011000, 0b001100001100, 0b011000000110, 0b110000000011, 0b100000000001 }; uint16_t demo3[]={ 0b100000000000, 0b110000000000, 0b011100000000, 0b001110000000, 0b000111000000, 0b000011100000, 0b000001110000, 0b000000111000, 0b000000011100, 0b000000001110, 0b000000000111, 0b000000000011, 0b000000000001 }; uint8_t repeat, i; int main(void) { rblib_init(); DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off cli(); TCCR0 = (0 << WGM00) | (1 << WGM01); // CTC-Mode TCCR0 |= (0 << COM00) | (0 << COM01); // ohne OCR-Pin TCCR0 |= (0 << CS02) | (1 << CS01) | (0 << CS00); // prescaler /8 TIMSK = (1 << OCIE0); // Interrupt ein OCR0 = 199; sei(); while(1) { repeat=5; while(repeat--) for(i=0; i<10; bitmuster=demo1[i++]){ delay(255); delay(255); } repeat=5; while(repeat--) for(i=0; i<10; bitmuster=~demo1[i++]){ delay(255); delay(255); } repeat=5; while(repeat--) for(i=0; i<12; bitmuster=demo2[i++]){ delay(255); } repeat=5; while(repeat--) for(i=0; i<12; bitmuster=~demo2[i++]){ delay(255); } repeat=5; while(repeat--) for(i=0; i<13; bitmuster=demo3[i++]){ delay(255); delay(255); } repeat=5; while(repeat--) for(i=0; i<13; bitmuster=~demo3[i++]){ delay(255); delay(255); } } return 0; } ISR (TIMER0_COMP_vect) { static uint8_t bit=0; if((bitmuster & (1<<bit))==1){ DDRC|=SL1; PORTC|=SL1; //SL1 high DDRC|=SL2; PORTC&=~SL2; //SL2 low DDRB&=~SL4; PORTB&=~SL4; //SL4 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==2){ DDRC|=SL1; PORTC|=SL1; //SL1 high DDRB|=SL4; PORTB&=~SL4; //SL4 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==4){ DDRC|=SL1; PORTC|=SL1; //SL1 high DDRB|=SL5; PORTB&=~SL5; //SL5 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off } if((bitmuster & (1<<bit))==8){ DDRC|=SL2; PORTC|=SL2; //SL2 high DDRC|=SL1; PORTC&=~SL1; //SL1 low DDRB&=~SL4; PORTB&=~SL4; //SL4 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==16){ DDRC|=SL2; PORTC|=SL2; //SL2 high DDRB|=SL4; PORTB&=~SL4; //SL4 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==32){ DDRC|=SL2; PORTC|=SL2; //SL2 high DDRB|=SL5; PORTB&=~SL5; //SL5 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off } if((bitmuster & (1<<bit))==64){ DDRB|=SL4; PORTB|=SL4; //SL4 high DDRC|=SL1; PORTC&=~SL1; //SL1 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==128){ DDRB|=SL4; PORTB|=SL4; //SL4 high DDRC|=SL2; PORTC&=~SL2; //SL2 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRB&=~SL5; PORTB&=~SL5; //SL5 off } if((bitmuster & (1<<bit))==256){ DDRB|=SL4; PORTB|=SL4; //SL4 high DDRB|=SL5; PORTB&=~SL5; //SL5 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRC&=~SL1; PORTC&=~SL1; //SL1 off } if((bitmuster & (1<<bit))==512){ DDRB|=SL5; PORTB|=SL5; //SL5 high DDRC|=SL1; PORTC&=~SL1; //SL1 low DDRC&=~SL2; PORTC&=~SL2; //SL2 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off } if((bitmuster & (1<<bit))==1024){ DDRB|=SL5; PORTB|=SL5; //SL5 high DDRC|=SL2; PORTC&=~SL2; //SL2 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRB&=~SL4; PORTB&=~SL4; //SL4 off } if((bitmuster & (1<<bit))==2048){ DDRB|=SL5; PORTB|=SL5; //SL5 high DDRB|=SL4; PORTB&=~SL4; //SL4 low DDRC&=~SL1; PORTC&=~SL1; //SL1 off DDRC&=~SL2; PORTC&=~SL2; //SL2 off } if(bit<11) bit++; else bit=0; }
mic







Zitieren

Lesezeichen