Week 6 - Embedded Programming

How to Make (Almost) Anything - Manolis Zampetakis

Programming the controller

For this week we decided to program a very simple function for the controller while learning how to do the communication and load the program to it. For the load of the program to the controller we used the Makefile provided in the webpage of the class, namely the file


Also we use the corresponding .c file for programming. In this file we just changed the code inside the while(1) loop to do the function that we wanted. As we can see in the week 4 assignment our board has a microcontroller with one led and one button. The led is connected to the pin PA7 and the button to the pin PA2. So we first defined these pins as 'my_out' and 'my_in' respectively, so that we can reference to them in the code.

      #define my_in (1 << PA2)
      #define my_out (1 << PA7)
Then our idea was to have the led blinking in different frequences based on the number of times we have pressed the button. For this reason we used the function 'set' to light the led, the function 'clear' to close the led and the function 'pin_test' to read the status of the button.
      set(serial_port, my_out); \\ light the LED
      clear(serial_port, my_out); \\ close the LED
      pin_test(serial_pins, my_in); \\ read the status of the button
Based on these we produced the following code for the function that we wanted
      static int num;
      static int i;

      num = 0;
      while (1) {
        if(pin_test(serial_pins, my_in)){
          if(pin_test(serial_pins, my_in)){
            num = (num + 1) % 5;

        set(serial_port, my_out);

        for(i = 0; i <= num; i++)

        clear(serial_port, my_out);
We then connected the controllers appropriately so we can download the program to the controller.

used the following commands to download the program to the controller
       make -f hello.ftdi.44.echo.c.make
       sudo make -f hello.ftdi.44.echo.c.make program-usbtiny
       sudo make -f hello.ftdi.44.echo.c.make program-usbtiny-fuses


The final result is shown in the next video.


Lessons Learned