// // // hello.button.45.c // // button hello-world // 9600 baud FTDI interface // // Neil Gershenfeld // 10/31/10 // // (c) Massachusetts Institute of Technology 2010 // This work may be reproduced, modified, distributed, // performed, and displayed for any purpose. Copyright is // retained and must be preserved. The work is provided // as is; no warranty is provided, and users accept all // liability. // #include #include #define output(directions,pin) (directions |= pin) // set port direction for output #define input(directions,pin) (directions &= (~pin)) // set port direction for input #define set(port,pin) (port |= pin) // set port pin #define clear(port,pin) (port &= (~pin)) // clear port pin #define pin_test(pins,pin) (pins & pin) // test for port pin #define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set #define bit_delay_time 102 // bit delay for 9600 with overhead #define bit_delay() _delay_us(bit_delay_time) // RS232 bit delay #define half_bit_delay() _delay_us(bit_delay_time/2) // RS232 half bit delay #define input_port PORTB #define input_direction DDRB #define input_pin (1 << PC6) #define input_pins PINB int main(void) { // // main // // set clock divider to /1 // CLKPR = (1 << CLKPCE); CLKPR= (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); // // initialize pins // set(input_port, input_pin); // turn on pull-up input(input_direction, input_pin); // // main loop // while (1) { // // wait for button down // while (0 != pin_test(input_pins,input_pin)) ; digitalWrite(PB5, HIGH); // // wait for button up // while (0 == pin_test(input_pins,input_pin)) ; digitalWrite(PB5, LOW); } }