ECE 3551

Microcomputer Systems 1

Lab 2

By:

Sunita Ramnarinesingh

Student #900218187

Lab performed: 17th September, 2007.

Report submitted: 24th September, 2007.

Lab Instructor: Za Hniang Za

Lab Partner: Jay Morton OBJECTIVE:

 Learn more event handling in embedded system  Learn to write Interrupt Service Route (ISR)

In this lab we modified the Open the LED Blink (C) project and programmed the following buttons to control the moving lights LED4 - LED9: In part 1:  When Pushing PF8, change the direction of moving light  When pushing PF9, decrease the speed of moving light  When pushing PF10, increase the speed of moving light In part 2: The button PF11 should control the lighting pattern of LEDs in the following manner: (1) When pushing PF11 once, LED4 (the left most one) will be turned on (and stay on) while all the other LEDs continue moving. (2) When pushing PF11 twice, LED9 (the right most one) will be turned on (and stay on), while all the other LEDs continue moving (3) When pushing PF11 for the third time, LED4 and LED9 will turn off and LED movement will resume as in the original case (4) When pushing PF11 again, the pattern will go back to case (1), and so on… Some of the code we modified in the Main file was the variables. // Variables // //------// // flag indicating direction of moving light (toggled in FlagA ISR) short sLight_Move_Direction = 0; short LEDS = 0;

The above code made the LEDs a Global variable in the Header file.

We had to do most of our modification to the Interrupt Sub Routine File (ISR) to perform all the required LEDs outputs.

We had to use the IF and Switch statements in our code. I.e. if a specific switch is pressed then a specific LED pattern is executed in accordance to which switch was pressed otherwise it continues a regular flashing sequence. EX_INTERRUPT_HANDLER(FlagA_ISR) {

if(*pFIO_FLAG_C == 0x0100) { *pFIO_FLAG_C = 0x0100; sLight_Move_Direction = ~sLight_Move_Direction; }

The above code makes the LEDs change their direction by calling the sLight_Move_Direction code when PF 8 is pressed. if(*pFIO_FLAG_C == 0x0200) { *pFIO_FLAG_C = 0x0200; *pTIMER0_PERIOD += 0x0020000; } The above code makes the LEDs slow their direction speed by increasing the period of the TIMER0 every time PF9 is pressed. if(*pFIO_FLAG_C == 0x0400) { *pFIO_FLAG_C = 0x0400; *pTIMER0_PERIOD -= 0x00200000; The above code makes the LEDs increase their direction speed by decreasing the period of the TIMER0 every time PF10 is pressed. if(*pFIO_FLAG_C == 0x0800) { *pFIO_FLAG_C = 0x0800; LEDS++;

Makes the LEDs perform the operations in the switch (LEDS) when PF11 is pressed several times. We created 3 different cases and a default case for the switch part of out code. case 0: //*pFlashA_PortB_Data = ucActive_LED | 0x00; LEDS = 0x00; break; Made the LED4 stay on while the rest of the lights continued the sequence when PF11 is pressed once. case 1: //*pFlashA_PortB_Data = ucActive_LED | 0x01; LEDS = 0x01; break; Made the LED4 and LED9 stay on while the rest of the lights continued the sequence when PF11 is pressed twice.

case 2: //*pFlashA_PortB_Data = ucActive_LED | 0x21; LEDS = 0x21; break; Made the LED4 and LED9 turn off and continued the LED sequence as before when PF11 is pressed three times.

default:

//pFlashA_PortB_Data = ucActive_LED | 0x00; LEDS = 0x00; break; Starts the PF11 function from case 0 all over again. In the switch cases we made use of the OR function by combining it with the active LED to turn on the correct LED.

Discussion In this lab we had made different switches perform different functions and change LEds sequence. We had to make use of different interrupts and subroutines and us IF and Switch C statements. Initially we had some difficulty n knowing how to write such statements in C but we obtained an example and modified it to suit our specific needs. Another difficulty was to get PF11 to resume its original function after it was pressed 4 times. This was solved by using the default case.

Conclusion We were able to successfully write and execute the program code to make the LEDs and switches performed the required tasks.