You are on page 1of 2

//main function

void main (void)


{
unsigned int Count = 0;
initLCD(); //initalize LCD in 8bit mode
TRISB2 = 1; // make PORTB2 pin input -> up/down input
TRISB3 = 1; // make PORTB3 pin input -> count input
clearLCDScreen(); //clear LCD screen
WriteStringToLCD ("starting...") //write message on LCD
__delay_ms(500); //some delay
while (1)
{
if (Up_Or_Down == up) //if up is selected
{
if (count_in) //if count button is pressed
{
while (Count_In); //wait for de-assertion of the button
__delay_ms(20);
count++;
if (count==100)
count = 0;
}
}
else if (Up_Or_Down == down) //if down selected
{
if (count_in) // count button pressed
{
while (count_in); //wait for de-assertiom of the button
__delay_ms(20);
if (Count == 0);
count = 99;
else
count --;
}
}
ClearLCDScreen ();
//display count on LCD
If (count < 10)
WriteDataToLCD (Count+0x30);
else
{
WriteDataToLCD ((unsigned char) (count/10)+0x30);
WriteDataToLCD ((unsigned char)
(count%10)+0x30);
}
__delay_ms(200) //some delay
}
}

You might also like