Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 1000000UL
- #include <avr/io.h>
- #include <util/delay.h>
- void ports_init();
- void timerCounter0_init();
- void blinkBlueLeds();
- void blinkGreenLeds();
- void blinkYellowLeds();
- void blinkRedLeds();
- unsigned char blueLedsCounter=1;
- unsigned char blueLedsTemp=1;
- unsigned char greenLedsCounter=1;
- unsigned char greenLedsTemp=16;
- unsigned char redLedsCounter=1;
- int main(void)
- {
- unsigned char pwmState=0;
- ports_init();
- timerCounter0_init();
- while(1){
- blinkBlueLeds();
- blinkGreenLeds();
- blinkYellowLeds();
- blinkRedLeds();
- //_delay_ms(500);
- if (((PINB & (1<<PB0))==0) && (pwmState==0)){
- OCR0 = (255/3);
- pwmState = 1;
- }
- if (((PINB & (1<<PB0))!=0) && (pwmState==1)){
- OCR0 = 0;
- pwmState = 0;
- }
- }
- }
- void ports_init(){
- DDRA = 0b00011111;
- PORTA= 0b11100000;
- DDRB = 248;
- PORTB= 7;
- DDRC = (1<<PC7)|(1<<PC5)|(1<<PC3)|(1<<PC1);
- PORTC= 0b11011101;
- DDRD = 0xFF;
- PORTD= 0x00;
- }
- void timerCounter0_init(){
- TCNT0= 0x00;
- OCR0 = 0x00;
- TCCR0= (1<<WGM00)|(1<<COM01)|(1<<CS00);
- }
- void blinkBlueLeds(){
- if(blueLedsCounter <= 5){
- PORTA = (224+blueLedsTemp);
- blueLedsCounter++;
- blueLedsTemp *= 2;
- }
- else{
- PORTA=(224+1);
- blueLedsCounter = 2;
- blueLedsTemp = 2;
- }
- }
- void blinkGreenLeds(){
- if(greenLedsCounter <= 4){
- PORTB = (7+greenLedsTemp);
- greenLedsCounter++;
- greenLedsTemp *= 2;
- }
- else{
- PORTB=(7+16);
- greenLedsCounter=2;
- greenLedsTemp=32;
- }
- }
- void blinkYellowLeds(){
- PORTC ^= (1<<PC7)|(1<<PC5)|(1<<PC3)|(1<<PC1);
- }
- void blinkRedLeds(){
- if(redLedsCounter<256){
- PORTD = redLedsCounter;
- redLedsCounter++;
- }
- else{
- PORTD=1;
- redLedsCounter=2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement