void lcd_init(void) { CTRL_PORT_DIR = 0x00; /* Direction of control port as Output */ DATA_PORT_DIR = 0x00; /* Direction of data port as Output */ LCD_cmd(0x38); /* LCD command - 5x7 matrix */ LCD_cmd(0x80); /* LCD command - Force cursor to the bigining of first line */ LCD_cmd(0x0C); /* LCD command - Display ON, cursor OFF */ LCD_cmd(0x01); /* LCD command - Clear display */ }
void LCD_init(void){ TRISD=0x00; TRISB=0x00; LCD_cmd(MODE_8BIT); // 2 Line, 5x7 display, 8 bit LCD_cmd(CLRSCR); // clear the screen LCD_cmd(CURSOR_INC); // Cursor Incremetns on each write LCD_cmd(DISPLAY_ON | CURSOR_OFF); // Display on and Cursor Off return; }
void LCD_init(void){ TRISD=0x00; TRISC=0x00; LCD_cmd(0x38); // 2 Line 5x7 display LCD_cmd(0x01); // clear display LCD_cmd(0x06); // Entry mode LCD_cmd(0x0F); // Display on Cursor blinking return; }
void dis_cmd(unsigned char cmd) { char cmd1; cmd1=cmd&0xF0; //takes higher nibble to send to LCD for 4 bit mode LCD_cmd(cmd1); cmd1=(cmd<<4)&0xF0; //takes lower nibble to send to LCd LCD_cmd(cmd1); }
/** * @brief Set cursor using a string. */ static int set_cursor(const char *carg) { if (!strcasecmp(carg, "Blink")) { return LCD_cmd(DISPLAY_SET | DISPLAY_ON | CURSOR_BLINK_ON); } else if (!strcasecmp(carg, "On")) { return LCD_cmd(DISPLAY_SET | DISPLAY_ON | CURSOR_ON); } else if (!strcasecmp(carg, "Off")) { return 0; } else { fprintf(stderr, "set_cursor error: Invalid option.\n"); } return 3; }
void init_LCD(void) { LCD_cmd(0x38); // initialization of 16X1 LCD in 8bit mode _delay_ms(1); LCD_cmd(0x01); // clear LCD _delay_ms(1); LCD_cmd(0x0E); // cursor ON _delay_ms(1); LCD_cmd(0x80); // ---8 go to first line and --0 is for 0th position _delay_ms(1); return; }
void set_DDRAM_address(unsigned char address) // Sets the DDRAM address. DDRAM data is sent or received after this setting. { unsigned char display_address = (1<<7) | address; // formula for calculating the command byte // this command is to set the cursor on the inputted address LCD_cmd(display_address); }
void Move_Right(unsigned char n) { unsigned char i; for(i=0;i<n;i++) { LCD_cmd(0x1c); /* LCD command - Shift entire display to the Right */ delay_ms(200); } }
/** * @brief set CGRAM address * @param[in] n custom character number, must be no bigger than 7. * @return 0, if successful */ static int CGRAM_set_addr(int n) { if (n > 7) { fprintf(stderr, "CGRAM_set_addr error: invalid address."); return -1; } uint8_t cmd = CGRAM | (n << 3); return LCD_cmd(cmd); }
void Move_Left(unsigned char n) { unsigned char i=0; while(i!=n) { LCD_cmd(0x18); /* LCD command for moving entire display to the left */ delay_ms(200); /* Milli seconds delay function call */ i++; } }
void Write_TIME_LCD(char *str) { unsigned char i=0; LCD_cmd(0x80); /* LCD command - Force cursor to the bigining of first line */ while(i!=16) { LCD_data(*str); /* Passing address of a string to LCD data display function */ str++; /* String variable address increment */ i++; } str++; /* String variable address increment */ i=17; LCD_cmd(0xC0); /* Force cursor to the bigining of the 2nd line */ while(i!=32) { LCD_data(*str); /* Passing address of a string to LCD data display function */ str++; /* String variable address increment */ i++; } }
void Init() { //-------Oscillator Configuration OSCCON=0b01100000; OSCTUNE.PLLEN=1; //-------AD Configuration ANCON0=0; ANCON1=0; //-------Port Configuration porta=0; portb=0; portc=0; portd=0; porte=0; trisa=0b11010111; trisb=0b11000000; trisc=0b10111101; trisd=0b01110000; trise=0b1111; //------TMR0 T0CON=0b10000001; //prescaler 4 TMR0H=0x63; TMR0L=0xBF; INTCON.b7=1; INTCON.T0IE=1; //------LCD Init LCD_Init(); //LCDSystem_Init(&LCD); LCD_cmd(_LCD_CURSOR_OFF); delay_ms(500); LCDBL=1; //-------UART UART1_Init(9600); //UART2_Init(9600); RC1IF_bit=0; RC1IE_bit=1; RC1IP_bit=1; PEIE_bit=1; UART_Set_Active(&UART1_Read, &UART1_Write, &UART1_Data_Ready, &UART1_Tx_Idle); //-------Signaling System SignalingSystem_Init(&SigSys); //-------Door Status DoorStatus=DOORSTATUS_Close; //-------LoadConfigs LoadConfig(); //-------RS485 RS485Slave_Init(NetworkAddress); }
/** * @brief restore DDRAM address * @return 0, if successful; -1, if failed */ static int DDRAM_addr_restore() { uint8_t old_DDRAM_addr = g_DDRAM_addr; LCD_cmd(DDRAM | g_DDRAM_addr); if (old_DDRAM_addr == g_DDRAM_addr) { return 0; } fprintf(stderr, "LL_DDRAM_addr_restore error: could not restore DDRAM address"); return -1; }
void Entry_mode_set(unsigned char I_D, unsigned char S) // Sets cursor move direction (I/D), specifies to shift the display (S). These operations are performed during data read/write. { /* I_D should be either 0 or 1 0 - Decrement Position Cursor 1 - Incrememt Position Cursor */ /* S is to decide Shift 0 - No Display Shift 1 - Display Shift */ unsigned char entry = (1<<2) | (1<<I_D) | (S); // formula to generate command byte LCD_cmd(entry); }
void cursor_display_shift(unsigned char SC, unsigned char RL) { /* SC RL 0 0 Shifts the cursor position to the left (Address Counter is decremented by 1) 0 1 Shifts the cursor position to the right (Address Counter is incremented by 1) 1 0 Shifts the entire display to the left The cursor follows the display shift 1 1 Shifts the entire display to the right The cursor follows the display shift */ unsigned char entry = (1<<4) | (SC<<3) | (RL<<2); // formula to generate command byte LCD_cmd(entry); }
void display_control(unsigned char D, unsigned char C, unsigned char B) // Sets On/Off of all display (D), cursor On/Off (C) and blink of cursor position character (B). { /* D is Display bit 0 - Display off 1 - Display on */ /* C is cursor bit 0 - Cursor off 1 - Cursor on */ /* B is to set whether the cursor will blink or not 0 - Blink off 1 - Blink on */ unsigned char display = (1<<3) | (D<<2) | (C<<1) | (B); // formula to generate command byte LCD_cmd(display); }
void function_set(unsigned char DL,unsigned char N,unsigned char F) // Sets interface data length (DL), number of display line (N) and character font(F). { /* DL to decide whether 4-bit display or 8-bit display 0 - 4-bit interface 1 - 8-bit interface */ /* N is to set number of display line F is for font size display Character Duty N F lines Font Factor Remarks === ======= ========= ====== ======= 0 0 1 5x 7 dots 1/8 - 0 1 1 5x10 dots 1/11 - 1 * 2 5x 7 dots 1/16 Cannot display 2 lines with 5x10 dot character font */ // when N = 1 then two lines of display // when N = 0 unsigned char func = (1<<5) | (DL<<4) | (N<<3) | (F<<2); LCD_cmd(func); }
void main(void) { uint8_t ui1; start_main: LCD_init(); DELAY(100); LCD_cmd(LCD_CMD_CUR_10); DELAY(100); LCD_WR_LINE(0, 0, "Hello World 1"); DELAY(100); FlashWriteByte (0xF000, 0x1); FlashWriteByte (0xF001, 0x2); FlashWriteByte (0xF002, 0x3); FlashWriteByte (0xF003, 0x4); ui1 = FlashReadByte(0xF000); LCD_WR("Hello World "); LCD_wrchar('0'+ui1); DELAY(10); ui1 = FlashReadByte(0xF001); LCD_WR("Hello World "); LCD_wrchar('0'+ui1); DELAY(10); ui1 = FlashReadByte(0xF002); LCD_WR("Hello World "); LCD_wrchar('0'+ui1); DELAY(10); ui1 = FlashReadByte(0xF003); LCD_WR("Hello World "); LCD_wrchar('0'+ui1); DELAY(10); goto start_main; }
void LCD_clear_display() // Clears display and returns cursor to the home position (address 0) { LCD_cmd(0x01); // clear LCD_cmd(0x02); // home }
void LCD_cursor_home() // Returns cursor to home position (address 0). Also returns display being shifted to the original position. DDRAM contents remains unchanged. { LCD_cmd(0x02); }
void UpdateMenuText() { char txt[10]; memcpy(txt," ",10); LCD_cmd(_LCD_CLEAR); switch(MenuCounter) { case 0: lcd_out(1,1,"1 Openning Time "); charValueToStr(OpenningTime,txt); lcd_out(2,5,txt); break; case 1: lcd_out(1,1,"2 Closing Time "); charValueToStr(ClosingTime,txt); lcd_out(2,5,txt); break; case 2: lcd_out(1,1,"3 Invalid Time "); charValueToStr(InvalidTime,txt); lcd_out(2,5,txt); break; case 3: lcd_out(1,1,"4 Autoclose Time"); charValueToStr(AutocloseTime,txt); lcd_out(2,5,txt); break; case 4: lcd_out(1,1,"5 Net Address "); byteToStr(NetworkAddress,txt); lcd_out(2,5,txt); break; case 5: lcd_out(1,1,"6 Working Mode "); if(WorkingMode==0) lcd_out(2,1," Start/Stop "); else lcd_out(2,1," Open/Close "); break; case 6: lcd_out(1,1,"7 IR in Mode "); if(IRMode==0) lcd_out(2,1," NO "); else lcd_out(2,1," NC "); break; case 7: lcd_out(1,1,"8 Car Pass Time "); charValueToStr(CarPassTime,txt); lcd_out(2,5,txt); break; case 8: lcd_out(1,1,"9 Save Changes "); lcd_out(2,1,_Blank); break; case 9: lcd_out(1,1,"10 Discard Exit "); lcd_out(2,1,_Blank); break; } }