void LCDCursorRight(uint8_t n) //Moves cursor by n poisitions left { for (uint8_t i=0;i<n;i++) { LCDSendCommand(0x14); } }
void LCDShiftRight(uint8_t n) //Scroll n of characters Left { for (uint8_t i=0;i<n;i++) { LCDSendCommand(0x18); } }
void LCDSetXY(BYTE add1, BYTE X,BYTE Y) { BYTE temp[3]; temp[0]= cmdLCD_DEFAULT_PAGE; temp[1]= cmdLCD_SET_Y | Y; temp[2]= cmdLCD_SET_X | X; LCDSendCommand(add1,temp,3); }
void LCDdefinechar(uint8_t *pc,uint8_t char_code){ uint8_t a, pcc; uint16_t i; a=(char_code<<3)|0x40; for (i=0; i<8; i++) { pcc=lcdpgm_read_byte(&pc[i]); LCDSendCommand(a++); LCDSendData(pcc); } }
void LCDGotoXY(unsigned char x, unsigned char y) //Cursor to X Y position { unsigned char DDRAMAddr; switch(y) { case 0: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; break; case 1: DDRAMAddr = LCD_LINE1_DDRAMADDR+x; break; case 2: DDRAMAddr = LCD_LINE2_DDRAMADDR+x; break; case 3: DDRAMAddr = LCD_LINE3_DDRAMADDR+x; break; default: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; } LCDSendCommand(1<<LCD_DDRAM | DDRAMAddr); }
void LCDInit(void) { E_Low(); LCDDirIn(); _delay_ms(40); LCDDirOut(); LCDDataLines(0x30>>4); LCD_RS_DIR|=(1<<LCD_RS_BIT); LCD_RW_DIR|=(1<<LCD_RW_BIT); RS_Low(); RW_Low(); LCD_E_DIR|=(1<<LCD_E_BIT); _delay_us(20); E_High(); _delay_us(20); E_Low(); _delay_ms(20); E_High(); _delay_us(20); E_Low(); _delay_us(100); E_High(); _delay_us(20); E_Low(); _delay_us(100); LCDDataLines(0x20>>4); _delay_us(20); E_High(); _delay_us(20); E_Low(); _delay_us(100); LCDSendCommand(0x28); LCDSendCommand(0x08); LCDSendCommand(0x01); LCDSendCommand(0x06); LCDSendCommand(0x0C); }
void pcfLCDInit(BYTE addr) { #ifndef _WINDOWS WORD i; BYTE sync_mode=0; BYTE slew=0; // Set lcd reset pin as output // Set lcd reset pin low LCD_RESET_TRIS = 0; LCD_RESET = 0; DelayMs(500); // tW(RESL) LCD_RESET = 1; DelayMs(500); // tW(RESH) LCD_RESET = 0; DelayMs(1); // tW(RESL) LCD_RESET = 1; DelayMs(3); // tR(OP) //*************************************************** //* Lcd init commands * //*************************************************** for(i=0;i<20;i++) I2C_Recv[i]=0; addr=PCF8535_BUS_ADDRESS; //address of the device (slave) under communication CloseI2C(); //close i2c if was operating earlier //---INITIALISE THE I2C MODULE FOR MASTER MODE WITH 100KHz --- sync_mode = MASTER; slew = SLEW_OFF; OpenI2C(sync_mode,slew); SSPADD=0x0A; //400kHz Baud clock(9) @8MHz //check for bus idle condition in multi master communication IdleI2C(); //---START I2C--- //StartI2C(); LCDSendCommand(addr,(BYTE*)INIT_SEQUENCE,sizeof(INIT_SEQUENCE)); #else UNUSED(addr); // заглушка #endif }
void LCDVisible(void) //Shows LCD { LCDSendCommand(0x0C); }
void LCDBlank(void) //blanks LCD { LCDSendCommand(0x08); }
void LCDClr(void) //Clears LCD { LCDSendCommand(LCD_CLR); }
void LCDCursorOnBlink(void) //displays LCD blinking cursor { LCDSendCommand(0x0F); }
void LCDCursorOn(void) //displays LCD cursor { LCDSendCommand(0x0E); }
void LCDHome(void) //LCD cursor home { LCDSendCommand(LCD_HOME); }
void SmartUp(void) { int Temp; for(Temp=0; Temp<1; Temp++) LCDSendCommand(CUR_UP); }
void LCDCursorOFF(void) //turns OFF cursor { LCDSendCommand(0x0C); }
void SmartDown(void) { int Temp; for(Temp=0; Temp<40; Temp++) LCDSendCommand(CUR_DOWN); }
int main() { Port_Init(); LCD_Init(); LCDSendCommand(DISP_OFF); while (1) { //Value of Bl prevents holding the buttons //Bl = 0: One of the Buttons is pressed, release to press again //LCD_State value is the state of LCD: 1 - LCD is ON; 0 - LCD is OFF //Up Button (Button 1) : Turn ON Display if (!(PINA & 0b00000001) & Bl & !(LCD_State)) //check state of button 1 and value of Bl and LCD_State { LCDSendCommand(DISP_ON); //Turn ON Display LCDSendCommand(CLR_DISP); //Clear Display LCDSendTxt(" Welcome "); //Print welcome screen Bl = 0; //Button is pressed LCD_State = 1; //Display is ON (LCD_State = 1) } //Left Button (Button 2) : Set Text1 if (!(PINA & 0b00000010) & Bl & LCD_State) //check state of button 2 and value of Bl and LCD_State { LCDSendCommand(CLR_DISP); //Clear Display LCDSendCommand(DD_RAM_ADDR); //set to Line 1 for (i=0; i<16; i++) Text[i] = 0; //Clear Text strcpy(Text, Text1); //set Text for (i=0; i<16; i++) if (Text[i] == 0) Text[i] = ' ';//fill the Text with space //LCDSendTxt(Text); //Print the text for (i=0; i<16; i++) LCDSendChar(Text[i]); Bl = 0; //Button is pressed Line = 1; //text must be print on up line } //Middle Button (Button 3) : Slide the text if (!(PINA & 0b00000100) & Bl & LCD_State) { while (!(PINA & 0b00000100) & (Line != 0)) //check state of button 3 and value of Line (Line = 0 - no text selected) { //sliding the text for(i=60000; i; i--); Ch = Text[0]; for (i=0; i<15; i++) Text[i] = Text[i+1]; Text[15] = Ch; //print the text in the correct line if (Line == 1) LCDSendCommand(DD_RAM_ADDR); else LCDSendCommand(DD_RAM_ADDR2); //LCDSendTxt(Text); for (i=0; i<16; i++) LCDSendChar(Text[i]); } } //Right Button (Button 4) Set Text2 if (!(PINA & 0b00001000) & Bl & LCD_State) //check state of button 4 and value of Bl and LCD_State { LCDSendCommand(CLR_DISP); //Clear Display LCDSendCommand(DD_RAM_ADDR2); //set to Line 2 for (i=0; i<16; i++) Text[i] = 0; //Clear Text strcpy(Text, Text2); //set Text for (i=0; i<16; i++) if (Text[i] == 0) Text[i] = ' ';//fill the Text with space //LCDSendTxt(Text); //Print the text for (i=0; i<16; i++) LCDSendChar(Text[i]); Bl = 0; //Button is pressed Line = 2; //text must be print on down line } //Down Button (Button 5) Turn OFF Display if (!(PINA & 0b00010000) & Bl & LCD_State) //check state of button 5 and value of Bl and LCD_State { LCDSendCommand(CLR_DISP); //Clear Display LCDSendTxt(" Turn OFF "); //Print Turn OFF message for (i=30; i; i--) for (j=30000; j; j--); //simple delay Bl = 0; //Button is pressed LCDSendCommand(DISP_OFF); //Display is OFF ==> LCD_State = 0, Line = 0 LCD_State = 0; Line = 0; } //check state of all buttons if ( ((PINA & 0b00000001) |(PINA & 0b00000010) |(PINA & 0b00000100) |(PINA & 0b00001000) |(PINA & 0b00010000)) == 31) Bl = 1; //if all buttons are released Bl gets value 1 } return 0; }