Week 7 - Embedded Programming

Week 7 - Embedded Programming

2018, Oct 17    

Notes:

  • Harvard architecture, RISC, microcontroller
  • ATxmega&ATmega is more powerful then ATtiny.
  • Arduino is calling gcc to compile C programme
  • Turn on the in-board pull-up resistor: write 1 on an input
  • c library: avr-libc
  • Arduino as ISP programmer tutorial: http://highlowtech.org/?p=1695

Programming

#define led_pin (1 << PA2)
#define btn_pin (1 << PA3)

in the main function

DDRA |= led_pin; // set LED PA2 to output
DDRA &= ~btn_pin; // set button PA3 to input
PORTA &= ~(led_pin); // initialize the led output to be low


while (1) {
      if ((PINA & btn_pin) == btn_pin) {
         _delay_ms(100);
         PORTA |= led_pin;

         _delay_ms(100);
         PORTA &= ~led_pin;
      }

      // Output the button status in serial
      // buffer[0] = '0' + ((PINA & btn_pin) == btn_pin);
      // put_string(&serial_port, serial_pin_out, buffer);

   }

And it works!