#define KeyPORT (PORTA&0x0F)
#define KeyDIR TRISB
#define ENTER 2
#define UP 3
#define DOWN 4
#define LCD_LINE
#define LCD_DATA
#define LCD_STR
// LCD connections definitions
sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD connections definitions
unsigned rom char MainMenuLIST[2][16] = {
{"Option 1"},
{"Option 2"}
};
unsigned char WaitForInput(void){
unsigned char temp1; //TEMP DATA HOLDER
unsigned char done = 0; //DONE Var will determine if done
while(!done){ //while done == 0
if(KeyPORT>0){ //if KeyPORT aka PORTB&0x0F.. the &0x0f will make sure we
//return the lower part of port only RB0 to RB3
temp1 = KeyPORT; //Place the lower part of port into temp variable
while(KeyPORT==temp1); //Like a debounce for button press
done = 0xFF; //Set DONE Var so we know we are complete
}
}
return temp1; //Return our temp1 var
}
void MainMenu(void){
unsigned char POS = 0; //Used for cursor ONLY!
unsigned char done = 0;
unsigned char x;
unsigned char ITEM=0;
Lcd_Cmd(_LCD_CLEAR);
while(!done){
for(x=0;x<2;x++){
LCD_LINE(x+1);
if(x == POS)
LCD_DATA('>',1);
else
LCD_DATA(' ',1);
LCD_STR(MainMenuLIST[x]);
}
switch(WaitForInput()){
case UP:
if(POS>0){
POS--;
ITEM--;
}
break;
case DOWN:
if(POS<1){
POS++;
ITEM++;
}
break;
case ENTER:
done = 0xFF;
break;
}
}
// ITEM contains what item is selected
// POS isnt used incase larger then 2 menu...
switch(ITEM){
case 0:
//Code to toggle C or F
break;
case 1:
//Code to jump to new menu system
break;
}
//Bring our title back.. cuz we are done with the menu...
LCD_LINE(1);
LCD_STR((unsigned rom char*)" AtomSoftTech ");
}
void main() {
CMCON |= 7; // Disable Comparators
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 3, "Temperature:");
do {
if(Button(&PORTA,2, 1, 0)) {
MainMenu();
}
} while (1);
}