A kódba nem írtam magyarázatokat, azt megtette más.
#include <avr/io.h>
#include <util/delay.h>
#define RED_ON() PORTB |= (1<<PB4)
#define RED_OFF() PORTB &= ~(1<<PB4)
#define YEL_ON() PORTB |= (1<<PB3)
#define YEL_OFF() PORTB &= ~(1<<PB3)
#define GRN_ON() PORTB |= (1<<PB5)
#define GRN_OFF() PORTB &= ~(1<<PB5)
#define G_RED_ON() PORTB |= (1<<PB1)
#define G_RED_OFF() PORTB &= ~(1<<PB1)
#define G_GRN_ON() PORTB |= (1<<PB2)
#define G_GRN_OFF() PORTB &= ~(1<<PB2)
void m_delay_10ms(unsigned long val) {
while(val--) _delay_ms(10);
}
void m_delay_fl(unsigned long val2) {
while(val2--){
G_GRN_OFF();
m_delay_10ms(5);
G_GRN_ON();
m_delay_10ms(5);
}
}
int main(void) {
uint8_t state;
DDRB = (1<<PINB1)|(1<<PINB2)|(1<<PINB3)|(1<<PINB4)|(1<<PINB5);
DDRB &= ~(1 << PB0);
PORTB |= (1 << PB0);
state = 0;
while(1) {
switch(state) {
case 0: RED_OFF();
YEL_OFF();
GRN_ON();
G_RED_ON();
G_GRN_OFF();
while(PINB & (1 << PB0)){}
m_delay_10ms(200);
state++;
break;
case 1: YEL_ON();
GRN_OFF();
m_delay_10ms(25);
state++;
break;
case 2: YEL_OFF();
RED_ON();
case 3: G_GRN_ON();
G_RED_OFF();
m_delay_10ms(110);
m_delay_fl(4);
state++;
break;
case 4: YEL_ON();
G_RED_ON();
G_GRN_OFF();
m_delay_10ms(25);
state++;
break;
default: state = 0;
}
}
return 0;
}
A cikk még nem ért véget, lapozz!
Értékeléshez bejelentkezés szükséges!