void LCDInit(uint8_t style) { /***************************************************************** This function Initializes the lcd module must be called before calling lcd related functions Arguments: style = LS_BLINK,LS_ULINE(can be "OR"ed for combination) LS_BLINK : The cursor is blinking type LS_ULINE : Cursor is "underline" type else "block" type LS_NONE : No visible cursor *****************************************************************/ //After power on Wait for LCD to Initialize __delay_ms(30); //Set IO Ports LCD_DATA_TRIS&=(~(0x0F<<LCD_DATA_POS)); //Output LCD_E_TRIS=0; //Output LCD_RS_TRIS=0; //Output LCD_RW_TRIS=0; //Output LCD_DATA_PORT&=(~(0x0F<<LCD_DATA_POS));//Clear data port CLEAR_E(); CLEAR_RW(); CLEAR_RS(); //Set 4-bit mode __delay_us(0.5); //tAS SET_E(); LCD_DATA_PORT|=((0b00000010)<<LCD_DATA_POS); //[B] To transfer 0b00100000 i was using LCD_DATA_PORT|=0b00100000 __delay_us(1); CLEAR_E(); __delay_us(1); //Wait for LCD to execute the Functionset Command LCDBusyLoop(); //[B] Forgot this delay //Now the LCD is in 4-bit mode LCDCmd(0b00101000); //function set 4-bit,2 line 5x7 dot format LCDCmd(0b00001100|style); //Display On /* Custom Char */ LCDCmd(0b01000000); uint8_t __i; for(__i=0;__i<sizeof(__cgram);__i++) LCDData(__cgram[__i]); }
void LCD_SendCmd(char cmd_value) // send commands function (actually sending occur @ function LCDCmd) { char cmd_value1; cmd_value1 = cmd_value & 0xF0; // i send the higher bits only (PB7 -> PB4) LCDCmd(cmd_value1); // send to LCD cmd_value1 = ((cmd_value<<4) & 0xF0); // shift the bits (PB3->PB0) and send them to LCD LCDCmd(cmd_value1); }
void initLCD(void) { LCDCmd(0x38); // initialization of 16X2 LCD in 8bit mode _delay_ms(1); LCDCmd(0x01); // clear LCD _delay_ms(1); LCDCmd(0x0C); // cursor ON _delay_ms(1); LCDCmd(0x80); // ---8 go to first line and --0 is for 0th position _delay_ms(1); }
void LCDGotoXY(uint8_t x,uint8_t y) { /* if(x<40) { if(y) x|=0b01000000; x|=0b10000000; LCDCmd(x); } */ switch(y) { case 0 : x = 0x80 + x; break; case 1 : x = 0xc0 + x; break; case 2 : x = 0x94 + x; break; case 3 : x = 0xD4 + x; break; } LCDCmd(x); }
void LCDInit(uint8_t style) { /***************************************************************** This function Initializes the lcd module must be called before calling lcd related functions Arguments: style = LS_BLINK,LS_ULINE(can be "OR"ed for combination) LS_BLINK :The cursor is blinking type LS_ULINE :Cursor is "underline" type else "block" type *****************************************************************/ //After power on Wait for LCD to Initialize _delay_ms(30); //Set IO Ports LCD_DATA_DDR|=(0x0F<<LCD_DATA_POS); LCD_E_DDR|=(1<<LCD_E_POS); LCD_RS_DDR|=(1<<LCD_RS_POS); LCD_RW_DDR|=(1<<LCD_RW_POS); LCD_DATA_PORT&=(~(0x0F<<LCD_DATA_POS)); CLEAR_E(); CLEAR_RW(); CLEAR_RS(); //Set 4-bit mode _delay_us(0.3); //tAS SET_E(); LCD_DATA_PORT|=((0b00000010)<<LCD_DATA_POS); //[B] To transfer 0b00100000 i was using LCD_DATA_PORT|=0b00100000 _delay_us(1); CLEAR_E(); _delay_us(1); //Wait for LCD to execute the Functionset Command LCDBusyLoop(); //[B] Forgot this delay //Now the LCD is in 4-bit mode LCDCmd(0b00101000); //function set 4-bit,2 line 5x7 dot format LCDCmd(0b00001100|style); //Display On }
void LCDGotoXY(uint8_t x,uint8_t y) { if(x<40) { if(y) x|=0b01000000; x|=0b10000000; LCDCmd(x); } }
void LCDGotoXY(uint8_t x,uint8_t y) { uint8_t address=0x80; if(y==1) { address=0xC0; } address+=x; LCDCmd(address); }
void LCDInit(uint8_t style) { __delay_ms(30); //Set IO Ports LCD_DATA_TRIS&=(~(0x0F<<LCD_DATA_POS)); //Output LCD_E_TRIS=0; //Output LCD_RS_TRIS=0; //Output LCD_RW_TRIS=0; //Output LCD_DATA_PORT&=(~(0x0F<<LCD_DATA_POS));//Clear data port CLEAR_E(); CLEAR_RW(); CLEAR_RS(); //Set 4-bit mode __delay_us(0.5); //tAS SET_E(); LCD_DATA_PORT|=((0b00000010)<<LCD_DATA_POS); //[B] To transfer 0b00100000 i was using LCD_DATA_PORT|=0b00100000 __delay_us(1); CLEAR_E(); __delay_us(1); //Wait for LCD to execute the Functionset Command LCDBusyLoop(); //[B] Forgot this delay //Now the LCD is in 4-bit mode LCDCmd(0b00101000); //function set 4-bit,2 line 5x7 dot format LCDCmd(0b00001100|style); //Display On /* Custom Char */ LCDCmd(0b01000000); uint8_t __i; for(__i=0;__i<sizeof(__cgram);__i++) LCDData(__cgram[__i]); }
void LCD_init() { unsigned char i; TRISD = 0x00; //LCD Port for (i = 0; i < 2; i++) { Delay15ms(); } //LCD_send_byte(0, 3); //LCD_send_byte(0, 2); //LCD_send_byte(0, 40); //LCD_send_byte(0, 12); //LCD_send_byte(0, 6); //LCD_send_byte(0, 1); // Set port directions TRIS_LCD_DATA &= 0xf0; // Clear lower 4 bits TRIS_LCD_EN = 0; TRIS_LCD_RS = 0; //LCDCmd(FOUR_BIT); // Nigel's code sends this before the next command? LCDCmd(FOUR_BIT & LINES_5X7); LCDCmd(INCREMENT & SHIFT_OFF); LCDCmd(DISPLAY_ON & BLINK_OFF & UNDERLINE_OFF); LCDCmd(CLEAR_DISPLAY); }
void LCDGotoXY(uint8_t x,uint8_t y) { if(x>=20) return; #ifdef LCD_TYPE_204 switch(y) { case 0: break; case 1: x|=0b01000000; break; case 2: x+=0x14; break; case 3: x+=0x54; break; } #endif #ifdef LCD_TYPE_164 switch(y) { case 0: break; case 1: x|=0b01000000; break; case 2: x+=0x10; break; case 3: x+=0x50; break; } #endif x|=0b10000000; LCDCmd(x); }
int main(void){ bPriLev=PRI_MAIN; tTime.bDay=7; tTime.bMonth=8; tTime.bYear=11; _init(); while(1) { /* Infinite Loop */ switch(bState){ /*--------------------------------------------------------------------------------------------------*/ case STATE_IDLE: switch(bBtn){ case NO_BTN: if(bTimeColonToToggle){ toggleTimeColon(); bTimeColonToToggle=0; } refreshQuote(); bFirst=1; break; case BTN_A: case BTN_B: case BTN_C: case BTN_A_LONG: case BTN_B_LONG: START_BACKLIGHT(); bBtn=NO_BTN; break; case BTN_C_LONG: bState = STATE_MENU; BACKLIGHT_ON(); bBtn=NO_BTN; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_MENU: switch(bBtn){ case NO_BTN: if(bSelectionMenuChanged || bFirst){ bFirst=0; bSelectionMenuChanged=0; LCDWriteStringXY(0,0,"-"); LCDWriteStringXY(1,0, options[bSelectionMenu]); LCDWriteStringXY(0,1," "); LCDWriteStringXY(1,1, options[bSelectionMenu+1]); } break; case BTN_A: bSelectionMenu++; bSelectionMenu %= NUMBER_OF_OPTIONS; bSelectionMenuChanged=1; bBtn=NO_BTN; break; case BTN_B: if(bSelectionMenu>0) bSelectionMenu--; else bSelectionMenu=(NUMBER_OF_OPTIONS-1); bSelectionMenu %= NUMBER_OF_OPTIONS; bSelectionMenuChanged=1; bBtn=NO_BTN; break; case BTN_C: switch(bSelectionMenu){ case SEL_DATE: bState = STATE_EDIT_DATE; bBtn = NO_BTN; break; case SEL_TIME: bState = STATE_EDIT_TIME; bBtn = NO_BTN; break; case SEL_TIMEZONE: bState = STATE_EDIT_TIMEZONE; bBtn = NO_BTN; break; default: break; } bFirst=1; break; case BTN_C_LONG: bState = STATE_IDLE; bBtn=NO_BTN; BACKLIGHT_OFF(); START_BACKLIGHT(); LCD_RESET(); bSelectionMenu=0; bDateChanged=1; // Appena rientro in idle stampo le quote bTimeChanged=1; bTempChanged=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_DATE: switch(bBtn){ case NO_BTN: if(bFirst){ bFirst=0; LCDClear(); tTimeEditing = tTime; sprintf(str, "%02d/%02d/%02d", tTimeEditing.bDay, tTimeEditing.bMonth, tTimeEditing.bYear); LCDWriteStringXY(0,0, "Editing date:"); LCDWriteStringXY(3,1, str); LCDCmd(0x0f); // set blinking cursor LCD_CURSOR_LEFT_N(8); } break; case BTN_A: bBtn = NO_BTN; changeEditDate(bSelectionDate, BTN_A); sprintf(str, "%02d/%02d/%02d", tTimeEditing.bDay, tTimeEditing.bMonth, tTimeEditing.bYear); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionDate); break; case BTN_B: bBtn = NO_BTN; changeEditDate(bSelectionDate, BTN_B); sprintf(str, "%02d/%02d/%02d", tTimeEditing.bDay, tTimeEditing.bMonth, tTimeEditing.bYear); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionDate); break; case BTN_C: if(bSelectionDate<7){ LCD_CURSOR_RIGHT_N(1); bSelectionDate++; } else{ bSelectionDate=0; LCD_CURSOR_LEFT_N(7); } // eseguo il controllo della data solo se passo da giorno a mese e da mese a anno if(bSelectionDate==2 || bSelectionDate==5){ LCD_CURSOR_RIGHT_N(1); bSelectionDate++; if(checkDate(&tTimeEditing, aDays)){ sprintf(str, "%02d/%02d/%02d", tTimeEditing.bDay, tTimeEditing.bMonth, tTimeEditing.bYear); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionDate); } } bBtn = NO_BTN; break; case BTN_C_LONG: bState=STATE_EDIT_DATE_CONFIRM; bBtn=NO_BTN; bFirst=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_DATE_CONFIRM: switch(bBtn){ case NO_BTN: if(bFirst){ LCDWriteStringXY(0,0, "Confermi? Si/No"); LCD_CURSOR_LEFT_N(5); bFirst=0; bSelectionDate=0; } if(bSelectionDateChanged){ if(bSelectionDate==0){ LCD_SET_CURSOR_POSITION(10); } else{ LCD_SET_CURSOR_POSITION(13); } bSelectionDateChanged=0; } break; case BTN_C: bSelectionDate = (bSelectionDate == 0)?1:0; bSelectionDateChanged=1; bBtn=NO_BTN; break; case BTN_C_LONG: if(bSelectionDate){ bState = STATE_MENU; bSelectionDate=0; }else{ tTime.bDay = tTimeEditing.bDay; tTime.bMonth = tTimeEditing.bMonth; tTime.bYear = tTimeEditing.bYear; bState = STATE_MENU; LCD_RESET(); } bBtn = NO_BTN; bFirst=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_TIME: switch(bBtn){ case NO_BTN: if(bFirst){ bFirst=0; LCDClear(); tTimeEditing = tTime; sprintf(str, "%02d:%02d:%02d", tTimeEditing.bHour, tTimeEditing.bMin, tTimeEditing.bSec); LCDWriteStringXY(0,0, "Editing time:"); LCDWriteStringXY(3,1, str); LCDCmd(0x0f); // set blinking cursor LCD_CURSOR_LEFT_N(8); } break; case BTN_A: bBtn = NO_BTN; changeEditTime(bSelectionTime, BTN_A); sprintf(str, "%02d:%02d:%02d", tTimeEditing.bHour, tTimeEditing.bMin, tTimeEditing.bSec); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionTime); break; case BTN_B: bBtn = NO_BTN; changeEditTime(bSelectionTime, BTN_B); sprintf(str, "%02d:%02d:%02d", tTimeEditing.bHour, tTimeEditing.bMin, tTimeEditing.bSec); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionTime); break; case BTN_C: if(bSelectionTime<7){ LCDCmd(0x14); bSelectionTime++; } else{ bSelectionTime=0; LCD_CURSOR_LEFT_N(7); } if(bSelectionTime==2 || bSelectionTime==5){ LCDCmd(0x14); bSelectionTime++; } bBtn = NO_BTN; break; case BTN_C_LONG: bState=STATE_EDIT_TIME_CONFIRM; bBtn=NO_BTN; bFirst=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_TIME_CONFIRM: switch(bBtn){ case NO_BTN: if(bFirst){ LCDWriteStringXY(0,0, "Confermi? Si/No"); LCD_CURSOR_LEFT_N(5); bFirst=0; bSelectionTime=0; } if(bSelectionTimeChanged){ if(bSelectionTime==0){ LCD_SET_CURSOR_POSITION(10); } else{ LCD_SET_CURSOR_POSITION(13); } bSelectionTimeChanged=0; } break; case BTN_C: bSelectionTime = (bSelectionTime == 0)?1:0; bSelectionTimeChanged=1; bBtn=NO_BTN; break; case BTN_C_LONG: if(bSelectionTime){ bState = STATE_MENU; bSelectionTime=0; }else{ tTime.bSec = tTimeEditing.bSec; tTime.bMin = tTimeEditing.bMin; tTime.bHour = tTimeEditing.bHour; bState = STATE_MENU; LCD_RESET(); } bBtn = NO_BTN; bFirst=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_TIMEZONE: switch(bBtn){ case NO_BTN: if(bFirst){ bFirst=0; LCDClear(); LCDWriteStringXY(0,0, "Edit timezone:"); LCDWriteStringXY(0,1,"1="); } break; default: break; } break; default: break; } } }
void LCDSetStyle(uint8_t style) { LCDCmd(0b00001100|style); }
void LCDClear() { LCDCmd(0x01); }
void Inicio_2Linha(void) { LCDCmd(0xC0); }
void clear(void) { LCDCmd(0x01); //apaga os dados do display LCDCmd(0x02); }