void lcdInitialize() { // startup delay //posTaskSleep(MS(50)); _delay_ms(50); // set data direction of pins as outputs *(enablePort-1) |= enableMask; *(registerSelectPort -1) |= registerSelectMask; *(ports[0]-1) |= pinMasks[0]; *(ports[1]-1) |= pinMasks[1]; *(ports[2]-1) |= pinMasks[2]; *(ports[3]-1) |= pinMasks[3]; lcdSetEnable(); lcdClearRegisterSelect(); _delay_us(2); // firsth step *(ports[0]) |= pinMasks[0]; *(ports[1]) |= pinMasks[1]; *(ports[2]) &= ~pinMasks[2]; *(ports[3]) &= ~pinMasks[3]; _delay_us(2); lcdClearEnable(); //posTaskSleep(MS(5)); _delay_ms(5); // second step lcdSetEnable(); _delay_us(2); lcdClearEnable(); //posTaskSleep(MS(1)); _delay_us(1000); // third step lcdSetEnable(); _delay_us(2); lcdClearEnable(); // posTaskSleep(MS(1)); _delay_us(1000); // fourth step *(ports[0]) &= ~pinMasks[0]; lcdSetEnable(); _delay_us(2); lcdClearEnable(); //posTaskSleep(MS(1)); _delay_us(1000); lcdWriteCommand(0b00101000); lcdWriteCommand(0b00001000); lcdWriteCommand(0b00000100); lcdWriteCommand(0b00000001); //posTaskSleep(MS(50)); _delay_ms(50); }
void lcdInit( void ) { pinConfig( LCD_SDA, OUT ); pinConfig( LCD_SCL, OUT ); pinConfig( LCD_RS, OUT ); pinConfig( LCD_CS, OUT ); pinConfig( LCD_PSB, OUT ); pinConfig( LCD_PSI2B, OUT ); pinConfig( LCD_BL, OUT ); pinSet( LCD_BL, HIGH ); pinSet( LCD_RS, HIGH ); pinSet( LCD_CS, HIGH ); // SPI pinSet( LCD_PSB, LOW ); pinSet( LCD_PSI2B, HIGH ); lcdWriteCommand( 0x38 ); //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot delay( 100 ); lcdWriteCommand( 0x39 ); //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot IS=1 delay( 100 ); lcdWriteCommand( 0x1c ); //Internal OSC frequency adjustment 183HZ bias will be 1/4 delay( 100 ); lcdWriteCommand( 0x73 ); //Contrast control low byte delay( 100 ); lcdWriteCommand( 0x57 ); //booster circuit is turn on. /ICON display off. /Contrast control high byte delay( 100 ); lcdWriteCommand( 0x6c ); //Follower control delay( 1000 ); lcdWriteCommand( 0x0c ); //DISPLAY ON delay( 100 ); lcdWriteCommand( 0x01 ); //CLEAR DISPLAY delay( 10000 ); lcdWriteCommand( 0x06 ); //ENTRY MODE SET CURSOR MOVES TO RIGHT delay( 100 ); }
void lcdWriteScreenBuffer( void ) { u16 i, ii; for( i = 0; i < 6; i++ ){ lcdWriteCommand( LCD_SETY | i ); lcdWriteCommand( LCD_SETX ); for( ii = 0; ii < 84; ii++ ){ lcdWriteData( globalScreenBuffer[ ( ( ii ) * 6 ) + i ] ); } // for } // for }
void lcdSetAddr(unsigned int x1,unsigned int x2,unsigned int y1,unsigned int y2) { lcdWriteCommand(0x2A); //column address set lcdWriteData(x1>>8); lcdWriteData(x1); lcdWriteData(x2>>8); lcdWriteData(x2); lcdWriteCommand(0x2B); //page(row) address set lcdWriteData(y1>>8); lcdWriteData(y1); lcdWriteData(y2>>8); lcdWriteData(y2); lcdWriteCommand(0x2C); // RAM Write }
void lcdWriteAddress( u8 column, u8 row ) { if( column >= LCD_MAXCOLUMNS ) { column = 0; ++row; } // if if( row >= LCD_MAXROWS ) { row = 0; } // if if( row == 0 ) { lcdWriteCommand( LCD_DDRAM + column ); } else { lcdWriteCommand( 0xC0 + column ); } // else }
//----------------------------------------------------------------- // lcdInit() //----------------------------------------------------------------- void lcdInit(void) { // Init PIC IO and buffer LCD_DATA_TRIS = 1; LCD_BUF_EN_OUT = LCD_BUF_EN_DISABLE; LCD_BUF_EN_OUT_TRIS = 0; LCD_BUF_DIR_OUT_TRIS = 0; LCD_BUF_DIR_OUT = LCD_BUF_DIR_WRITE; LCD_CLOCK_OUT_TRIS = 0; LCD_CLOCK_OUT = 1; LCD_RW_OUT = LCD_RW_WRITE; LCD_RW_OUT_TRIS = 0; LCD_RS_OUT = LCD_RS_CMD; LCD_RS_OUT_TRIS = 0; // Setup pipeline timer T4CON = 0x8000; // 1:1 Prescale (20MHz) TMR4 = 0; PR4 = PIPELINE_DELAY_TIME; _T4IF = 0; // Init LCD Controller lcdLongDelay(20); lcdWriteCommand(LCD_CMD_FUNCTION_SET); lcdLongDelay(6); lcdWriteCommand(LCD_CMD_FUNCTION_SET); lcdLongDelay(1); lcdWriteCommand(LCD_CMD_FUNCTION_SET); lcdLongDelay(1); lcdWriteCommand(LCD_CMD_CLEAR_DISPLAY); lcdLongDelay(2); lcdPipePush(LCD_PIPE_CMD | LCD_CMD_DISPLAY_ON); lcdPipePush(LCD_PIPE_CMD | LCD_CMD_SET_ENTRY_MODE); // Backlight LCD_BKLIGHT_OUT = 1; LCD_BKLIGHT_OUT_TRIS = 0; //lcdPrint("Hello123World456"); }
// index max 7 static void lcdSetCGRAM(uint8_t index,char letter[8]) { lcdWriteCommand((index<<3)|(1<<6)); for(uint8_t i=0; i<8; i++) { lcdWriteData(letter[i]); } }
/* * Set cursor at the specified coordinate in which x is the column and y is the row */ void lcdGoToXY(uint8_t ui8X, uint8_t ui8Y) { uint8_t ui8Address; // Specify the address if (ui8Y == 0) { ui8Address = 0x00 + ui8X; } else { ui8Address = 0x40 + ui8X; } // Set the bit for cursor moving command ui8Address |= 0x80; lcdWriteCommand(ui8Address); }
//----------------------------------------------------------------- // lcdCheck() - Loads the pipeline into the LCD //----------------------------------------------------------------- void lcdCheck(void) { uint16_t pipelineValue; if(_T4IF && lcdGetPipeSize()) { pipelineValue = lcdPipePop(); if(pipelineValue & LCD_PIPE_CMD) { // Command lcdWriteCommand((uint8_t)pipelineValue); } else { // Data lcdWriteData((uint8_t)pipelineValue); } TMR4 = 0; _T4IF = 0; } }
/* * LCD initialization function * Things to consider when initialize a characters LCD: * _Function set: * + Interface data: 4-bit (0) or 8-bit (1) * + Number of line: 1 line (0) or 2 lines (1) * + Character font: 5x7 dots (0) or 5x10 dots (1) * _Display on/off control: * + Display: off (0) or on (1) * + Cursor: off (0) or on (1) * + Cursor blink: off (0) or on (1) * _Entry mode set: * + Cursor move direction: decrement (0) or increment (1) * + Accompanies display shift: off (0) or on (1) */ void lcdInit(uint8_t ui8FunctionSetOptions, uint8_t ui8EntryModeSetOptions, uint8_t ui8DisplayOptions) { SysCtlPeripheralEnable(LCD_GPIO_DATA_PERIPH); SysCtlPeripheralEnable(LCD_GPIO_CTL_PERIPH); // Unlock the locked pins, modify this if needed HWREG(LCD_GPIO_DATA_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(LCD_GPIO_DATA_BASE + GPIO_O_CR) |= 0x80; GPIOPinTypeGPIOOutput(LCD_GPIO_DATA_BASE, DATA_PINS); GPIOPinTypeGPIOOutput(LCD_GPIO_CTL_BASE, E_PIN | RS_PIN); // Check if using 8-bit data or 4-bit data data8Bit = (ui8FunctionSetOptions & FUNCTION_SET_8_BIT) > 0; delayMs(20); // Some mysterious magic lcdWriteCommand(0x30); delayMs(20); lcdWriteCommand(0x30); delayMs(20); lcdWriteCommand(0x30); delayMs(20); if (!data8Bit) { lcdWriteCommand(0x20); delayMs(20); } // Initial setup lcdWriteCommand(FUNCTION_SET_BASE | ui8FunctionSetOptions); lcdWriteCommand(ENTRY_MODE_SET_BASE | ui8EntryModeSetOptions); lcdWriteCommand(DISPLAY_BASE | ui8DisplayOptions); lcdWriteCommand(CLEAR_DISPLAY); }
void lcdInit( void ) { spiConfig( &pygmyLCD, LCD_CS, LCD_SCK, NONE, LCD_MOSI ); pinConfig( LCD_RESET, OUT ); // We will use USART1_RTS as CS pinConfig( LCD_A0, OUT ); pinSet( LCD_RESET, LOW ); delay( 2000 ); // microseconds pinSet( LCD_RESET, HIGH ); delay( 2000 ); // microseconds lcdWriteCommand( LCD_FUNCSET | LCD_FUNCSET_H ); lcdWriteCommand( LCD_SETVOP | 55 ); lcdWriteCommand( LCD_TEMPCONTROL ); lcdWriteCommand( LCD_BIAS | LCD_BIAS_BS1|LCD_BIAS_BS0 ); lcdWriteCommand( LCD_FUNCSET ); lcdWriteCommand( LCD_DISPCONTROL | LCD_DISPCONTROL_D ); lcdSetBPP( PYGMY_PBM_1BPP ); lcdSetColor( 0xFF, 0xFF, 0xFF ); lcdBackColor( 0x00, 0x00, 0x00 ); lcdClear(); drawAll(); }
/* * Clear display */ void lcdClear() { lcdWriteCommand(CLEAR_DISPLAY); }
void lcdOff( void ) { lcdWriteCommand( LCD_FUNCSET | LCD_FUNCSET_PD ); }
void lcdOn( void ) { lcdWriteCommand( LCD_FUNCSET ); }
void lcdGotoXY(uint8_t column, uint8_t row) { uint8_t command = column+row*0x40+0x80; lcdWriteCommand(command); }
void lcdDisplayOff() { uint8_t command = 0b00001000; lcdWriteCommand(command); }
void lcdClear() { lcdWriteCommand(0b00000001); //posTaskSleep(HZ/500); _delay_ms(2); }