MAin Menu

Course Synopsis

EMBEDDED SYSTEM APPLICATIONS covers the basic concept and application of microcontroller system based on Peripheral Interface Controller (PIC) microcontroller. Students will learn software and hardware development on microcontroller development system and understand how to do interfacing with external devices using suitable internal chip features. Students will be also exposed to the new Microcontroller Unit (MCU) simulation software.

Saturday, June 30, 2012

Switch controlled LED blinking

Video below shows LED light controlled by forward and reverse switch. When forward button is press, LED will shift to the right and reverse button will make the LED shift to the left. When LED is shifted until the last one, it will back to the first one again.


Programming part


//This is the desired array looks like
unsigned char _options[8]={0b00000001, 0b00000010, 0b00000100, 0b00001000,
  0b00010000, 0b00100000, 0b01000000, 0b10000000};
sel=0;  
PORTD =_options[sel]; //assign PORTD output to follow the array

//this is where button assigned to move forward or reverse
while(1)
{
if(forward==1)
{
if(sel==7) sel=0;
else sel++;
PORTD =_options[sel];
while(forward==1);         //waiting for button to be press
}


else if(reverse==1)
{
if(sel==0) sel=7;
else sel--;
PORTD =_options[sel];
while(reverse==1);
}

No comments:

Post a Comment