Embedded Programming
This week's assignment was to read a microcontroller datasheet and then program the serial echo board, that we made 2 weeks ago with the LED and button, to do something
I used the Tiny 44 datasheet to try and understand the assembly language program that Neil had written for the serial echo board. This was surprisingly successful and I managed to fully understand the program. I decided to try and experiment with interrupts as I had heard a lot about them previously but didn't really understand how they worked. I decided that in addition to the function of echoing characters to the PC I would flash the LED 3 times whenever the button was pressed.
As I had already connected the button to PA7 on the controller I used the PCINT0 interrupt from the table below as this allowed me to define one of the PA[0..7] pins to generate the interrupt condition
In order to use interrupts I had to use the following code in the main programme to configure them
![Set_Interrupts (15K)](images/Set_Interrupts.JPG)
I then had to write the interrupt routine to turn the LED pin on and off with delays of 1/2 second
![Interrupt_routine (41K)](images/Interrupt_routine.JPG)
Disabling the interrupts during this routine was key as this prevented a repeat interrupt queuing up as a result of the release of the button (the interrupt was defined on a rising or falling level on the pin).
The interrupt is then called by placing the interrupt routine call at the start of the program
![Interrupt_call (13K)](images/Interrupt_call.JPG)
The 'reti' command is used to skip unused interrupts from the table above, in this case skipping INT0
I used AVR Studio 5 to modify the programme and also used this to create the HEX file directly. I then uploaded this in Ubuntu using AVRdude and my FabISP Programmer. I was very pleased with the result (to save space I have uploaded video to YouTube):
Serial Echo with flashing LEDs video