Week13 | Networking and Communications |
/ #include <avr/io.h> #include <util/delay.h> #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 position_delay() _delay_ms(100) #define PWM_port PORTA #define PWM_pin (1 << PA6) #define PWM_direction DDRA #define input_port PORTA #define input_direction DDRA #define input_pin (1 << PB2) #define input_pins PINA int main(void) { // CLKPR = (1 << CLKPCE); CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); TCCR1A = (1 << COM1A1) | (0 << COM1A0); // clear OC1A on compare match TCCR1B = (0 << CS12) | (1 << CS11) | (0 << CS10) | (1 << WGM13); ICR1 = 25000; clear(PWM_port, PWM_pin); output(PWM_direction, PWM_pin); set(input_port, input_pin); // turn on pull-up input(input_direction, input_pin); while (1){ while (0 != pin_test(input_pins,input_pin)); OCR1A = 100; position_delay(); while (0 == pin_test(input_pins,input_pin)); OCR1A = 1000; position_delay(); } } |