source code for counter

Upload: mulugeta-ashango

Post on 14-Oct-2015

11 views

Category:

Documents


0 download

DESCRIPTION

source code

TRANSCRIPT

//main function void main (void){unsigned int Count = 0;initLCD(); //initalize LCD in 8bit modeTRISB2 = 1; // make PORTB2 pin input -> up/down inputTRISB3 = 1; // make PORTB3 pin input -> count inputclearLCDScreen(); //clear LCD screenWriteStringToLCD ("starting...") //write message on LCD__delay_ms(500); //some delaywhile (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; elsecount --;}}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 }}