ggrcntrbug FTW!

This commit is contained in:
bigalex 2012-09-06 23:09:20 +02:00
parent 6f54c8ccf3
commit 62bea8d896
3 changed files with 93 additions and 14 deletions

View File

@ -11,7 +11,7 @@ void init_leds(void){
//enable LED channels as output
DDRC |= (1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3);
// both LEDs off
PORTC &= ~(1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3);
PORTC &= ~((1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3));
//TCCR2A = (1 << WGM21);
@ -25,10 +25,44 @@ void init_leds(void){
return;
};
void init_buzzr(int mode){
return;
void inline led_on(int leds){
PORTC |= leds;
};
void inline led_off(int leds){
PORTC &= ~leds;
};
void init_buzzr(){
//its on B2 and C5, for reasons
DDRC |= (1 << PORTC5);
DDRB |= (1 << PORTB2);
//switch it off
buzzr_off();
return;
};
void buzzr_up(){
PORTC &= ~(1 << PORTC5);
PORTB |= (1 << PORTB2);
return;
};
void buzzr_down(){
PORTC |= (1 << PORTC5);
PORTB &= ~(1 << PORTB2);
};
void inline buzzr_off(){
PORTC &= ~(1 << PORTC5);
PORTB &= ~(1 << PORTB2);
};
void buzzr_inv(){
PORTC ^= (1 << PORTC5);
PORTB ^= (1 << PORTB2);
};
void init_switch(){
return;
@ -42,3 +76,9 @@ void init_motor(void)
return;
}
void set_motor(int val){
PORTB = ~(val);
PORTB = PORTB;
return;
};

View File

@ -7,11 +7,25 @@ enum { BUZZR_OUT, //initialize buzzer for OUTPUT mode (emmiting soundwaves)
BUZZR_IN //initialize buzzer for INPUT mode (registering soundwaves)
};
#define LED_L (1 << PORTC0)
#define LED_R (1 << PORTC2)
#define MOTOR_ON (0<<PORTB1)
#define MOTOR_OFF (1<<PORTB1)
void init_leds(void);
void init_buzzr(int);
void led_on(int);
void led_off(int);
void init_buzzr();
void buzzr_up();
void buzzr_down();
void buzzr_off();
void buzzr_inv();
void init_switch(void);
void init_motor(void);
void set_motor(int);
#endif

View File

@ -51,22 +51,42 @@ static inline void init_pwm(void)
}
inline void setleds(uint8_t state)
{
/* set leds according to */
PORTC |= (state | 0b00001111);
PORTC &= ~(state | 0b11110000);
void click(){
buzzr_up();
_delay_ms(1);
buzzr_inv();
_delay_ms(1);
buzzr_off();
};
void waitr(int min, int max){
int waitms = (rand() % (max-min)) + min;
for(int i=0; i <= waitms; i++){
_delay_ms(1);
};
return;
};
void ledr(){
int i = (rand() % 3);
switch(i) {
case 0 : led_on(LED_L); break;
case 1 : led_on(LED_R); break;
default : led_on(LED_L|LED_R);
};
_delay_ms(10);
led_off(LED_L|LED_R);
}
void __attribute__((noreturn))
main(void)
{
/* hardware initialisation: */
init_leds();
init_buzzr();
//USART0_Init();
// init_motor();
//init_pwm();
@ -77,9 +97,14 @@ main(void)
/* here the show begins:*/
//sei();
for(;;) /* ever */ {
//set_motor(MOTOR_ON);
for(;;) /* ever */ {
//do something
waitr(50,5000);
click();
ledr();
//do something
//synth_poll();
//USART0_put_uint16(0xA09F);
//USART0_crlf();