sbit GreenLED at RD6_bit;
sbit RedLED at RD7_bit;
sbit IncrementButton at RB1_bit;
sbit DecrementButton at RB0_bit;
sbit LCD_EN at RD0_bit;
sbit LCD_RS at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
sbit GreenLED_Direction at TRISD6_bit;
sbit RedLED_Direction at TRISD7_bit;
sbit IncrementButton_Direction at TRISB1_bit;
sbit DecrementButton_Direction at TRISB0_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
int count = 10;
const int MAX_COUNT = 10;
void main() {
GreenLED_Direction = 0;
RedLED_Direction = 0;
IncrementButton_Direction = 1;
DecrementButton_Direction = 1;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 1, "P.SLOT LEFT:");
Lcd_Out(1, 13, "10");
while(1) {
if (!DecrementButton) {
count = count-1;
if(count < 0){
count = 0;
}
if (count == 0) {
GreenLED = 0;
RedLED = 1;
} else {
GreenLED = 1;
RedLED = 0;
}
while (!DecrementButton);
}
if (!IncrementButton) {
count=count+1;
if (count > MAX_COUNT) {
count = MAX_COUNT;
}
if (count > 0){
GreenLED = 1;
RedLED = 0;
} else{
GreenLED = 0;
RedLED = 1;
}
while (!IncrementButton);
}
if (count == 10) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "10");
}
if (count == 9) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "9");
}
if (count == 8) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "8");
}
if (count == 7) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "7");
}
if (count == 6) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "6");
}
if (count == 5) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "5");
}
if (count == 4) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "4");
}
if (count == 3) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "3");
}
if (count == 2) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "2");
}
if (count == 1) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "1");
}
if (count == 0) {
Lcd_Out(1, 13, " ");
Lcd_Out(1, 13, "0");
Lcd_Out(2, 3, "PARKING FULL");
}
}