Gast
#4023035
Hallo ich versuche mit ei ATtiny13A eine LED über ein Taster ein- und auszuschalten. Irgendwie stehe ich gerade aufm Schlauch. Die LED will einfach nicht schalten. Kann mir jmd. helfen und sagen was ich hier falsch mache? Der CODE ************************************************************************ **** /* * Button_test.c * * Created: 21.02.2015 17:33:34 * Author: Sonja */ #include <avr/io.h> #include <avr/interrupt.h> // fixed variable register unsigned char btn_states asm("r8");//bit0:up(0),down(1) //global variable unsigned char btn_state_last = 0; //macro #define BTN_PRESSED (btn_states & 0x08) #define BTN_TIPPED (btn_states & 0x02) inline void init() { DDRB = 0x08;//Directions XXXX 1XXX as output PORTB = 0xF8;//Pull Ups } inline void readinput() { //button 1 select channel: PB1 xxxx xx1x if(PINB &(1<<PB1)) { btn_states &= 0xFE; } else { btn_states |= 0x01; } } inline void getButtonStates() { if((btn_states & 0x01) != (btn_state_last = 0x01)) { if(btn_states & 0x01) { btn_states |= 0x08; } else { btn_states &= 0xFB; } } btn_state_last = btn_states; } int main(void) { unsigned char switch_on_marker = 0; char global_on_off = 0; btn_states = 0x00; // Bit0:up(0)/down(1), bit1:tipped(1), bit2:hold(1), bit3:untouched(1) btn_state_last = btn_states; int button = 0; int release = 0; while(1) { if(BTN_PRESSED) { btn_states &= 0xF7; if(global_on_off == 0) //was off -> on { DDRB |= 0x08; PORTB |= 0x08; global_on_off = 1; switch_on_marker = 1;// remember button state and dont turn of when release } } else if(BTN_TIPPED) { btn_states &= 0xDF; if(switch_on_marker == 1) { if(global_on_off == 1) { DDRB &= 0xFF; PORTB &= 0xFF; global_on_off = 0; switch_on_marker = 0; } } } } } ************************************************************************ ******* Danke Gruß Dima