int gd32_hw_lcd_init(void) { _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t) * RT_HW_LCD_WIDTH * RT_HW_LCD_HEIGHT, 32); if (_rt_framebuffer == RT_NULL) return -1; /* no memory yet */ lcd_config(); tli_config(); tli_layer_enable(LAYER0); tli_reload_config(TLI_FRAME_BLANK_RELOAD_EN); tli_enable(); _lcd_info.bits_per_pixel = LCD_BITS_PER_PIXEL; _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; _lcd_info.framebuffer = (void *)_rt_framebuffer; _lcd_info.width = RT_HW_LCD_WIDTH; _lcd_info.height = RT_HW_LCD_HEIGHT; lcd.type = RT_Device_Class_Graphic; lcd.init = NULL; lcd.open = NULL; lcd.close = NULL; lcd.read = NULL; lcd.write = NULL; lcd.control = rt_lcd_control; lcd.user_data = (void *)&_lcd_info; /* register lcd device to RT-Thread */ rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR); return 0; }
//=============================================================================== // Functions //=============================================================================== //4-bit mode configuration void lcd_init() { __delay_ms(30); //wait for 30ms after power ON for LCD internal controller to initialize itself LCD_E = 1; //Set lcd to configuration mode LCD_RS = 0; //Selected command register __delay_us(5); //macro from HITECH compiler to generate code to delay for 1 microsecond base on _XTAL_FREQ value LCD_DATA = (LCD_DATA & 0x0F) | 0b00110000; //make it in 8-bit mode first, for 3 times lcd_e_clock(); __delay_ms(2); LCD_DATA = (LCD_DATA & 0x0F) | 0b00110000; //make it in 8-bit mode first, for 3 times lcd_e_clock(); __delay_ms(2); LCD_DATA = (LCD_DATA & 0x0F) | 0b00110000; //make it in 8-bit mode first, for 3 times lcd_e_clock(); __delay_ms(2); LCD_DATA = (LCD_DATA & 0x0F) | 0b00100000; //make it in 4-bit mode lcd_e_clock(); __delay_ms(2); //start sending command in 4 bit mode //Function Set lcd_config(0b00101000); //0b 0 0 1 ID N F X X //Interface Data Length, ID= 4-bit //Number of line to display, N = 1 is 2 line display, N = 0 is 1 line display //Display Font, F = 0 is 5x 8 dots, F = 1 is 5 x 11 dots //Command Entry Mode lcd_config(0b00000110); //0b 0 0 0 0 0 1 ID SH //ID = 1, cursor automatic move to right, increase by 1 //SH = 0, shift of entire display is not perform //Display Control lcd_config(0b00001111); //0b 0 0 0 0 1 D C B //D = 1, Display is ON //C = 0, Cursor is not display //B = 0. Cursor does not blink lcd_clear(); //clear LCD and move the cursor back to home position }
//------------------------------- void lcd_init(void) { lcd_config(DEFAULT_DISPLAY_CONFIG); // 1, Data Lenght, Number of lines, character font lcd_cmd(DEFAULT_DISPLAY_CONTROL,0); // 1, lcd, cursor, blink lcd_cmd(DEFAULT_ENTRY_MODE,0); // 1,increment/decrement,display shift on/off lcd_cmd(0x01,2); // clear display lcd_cmd(0x02,2); // 1, return home cursor #if (USE_PROGRESS_BAR) lcd_readybar(); #endif }
/*! \brief Initialize the LCD. * \note This library use the 4-bit interface. */ void lcd_init(void) { /* GPIO initialization. */ Set_All_pins_as_Outputs(); /* LCD initialization. */ lcd_config(DEFAULT_DISPLAY_CONFIG); /*! \brief Initializing by instruction. 4-bit interface initialization. */ lcd_setmode(DEFAULT_VIEW_MODE); lcd_setmode(DEFAULT_ENTRY_MODE); lcd_clrscr(); lcd_return(); #if (USE_PROGRESS_BAR) lcd_initbar(); #endif }
/********************************************************** * Routine: initialize_lcd * Description: Initializes the LCD and displays the * splash logo **********************************************************/ void initialize_lcd(int show_what) { char *pwm_on[2] = {"pwm", "7F"}; //gpio 119 ADO_SPK_ENABLE // //__raw_writew(0x1B,0x4a100110); //gpio_119 gpio_120 pull high __raw_writel(0x001B001B,0x4a100110); __raw_writew(__raw_readw(0x48059134) & 0xFEFF, 0x48059134); __raw_writew(__raw_readw(0x4805913C) | 0x0100, 0x4805913C); __raw_writew(__raw_readw(0x48059134) & 0xFF7F, 0x48059134); __raw_writew(__raw_readw(0x4805913C) | 0x0080, 0x4805913C); spi_init(); /* Enable GPIO_45 (LCD_PWR_ON) */ __raw_writew(0x1B,0x4a10006A); __raw_writew(__raw_readw(0x48055134) & 0xDFFF, 0x48055134);//gpio_OE gpio45 __raw_writew(__raw_readw(0x4805513C) | 0x2000, 0x4805513C);//gpio_dataout gpio45 /* Enable GPIO_47 (OMAP_3V_ENABLE, 3.3 V rail) */ __raw_writel(0x001B0007,0x4a10006C); __raw_writew(__raw_readw(0x48055134) & 0x7FFF, 0x48055134);//gpio_OE gpio47 __raw_writew(__raw_readw(0x4805513C) | 0x8000, 0x4805513C);//gpio_dataout gpio47 udelay(10000); //kc1 lcd initialize spi_command(); udelay(2000); /* Enable GPIO_37 (OMAP_RGB_SHTDOWN, switch to LVDS mode) */ __raw_writew(0x1B,0x4a10005A); __raw_writew(__raw_readw(0x48055134) & 0xFFDF, 0x48055134);//gpio_OE gpio37 __raw_writew(__raw_readw(0x4805513C) | 0x0020, 0x4805513C);//gpio_dataout gpio37 show_black_data(); if(show_what==OTTER_LCD_DISPLAY_LOW_BATT_SCREEN) show_lowbattery(); else show_splash(); lcd_config(); /* Turn on backlight */ set_omap_pwm(NULL, 0, 2, pwm_on); }
/* Initialise the LCD with appropriate initialisation */ void lcd_init(void) { /* Display pin modes */ gpio_mode_setup(LCD_RS_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_RS); gpio_mode_setup(LCD_E_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_E); gpio_mode_setup(LCD_DB4_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_DB4); gpio_mode_setup(LCD_DB5_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_DB5); gpio_mode_setup(LCD_DB6_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_DB6); gpio_mode_setup(LCD_DB7_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_DB7); /* Set LCD pins to idle state */ gpio_clear(LCD_RS_PORT, LCD_RS); gpio_clear(LCD_E_PORT, LCD_E); /* Wait for things to warm up: LCD wants 40ms guaranteed from 5V startup */ delay_ms(60); /* Set 4-bit mode */ _hd44780_write_nibble(0x03, true); delay_ms(6); _hd44780_write_nibble(0x03, true); delay_us(200); _hd44780_write_nibble(0x03, true); /* yes, really. */ delay_us(50); _hd44780_write_nibble(0x02, true); /* Set small font (F=0), 2-line mode (N=1) */ _hd44780_write((1<<5) | (1<<3), true); delay_us(50); /* Display on*/ _hd44780_write((1<<3), true); delay_us(50); lcd_clear(); /* Entry point: I/D=1 (left-to-right script), SH=0 (no scroll) */ _hd44780_write((1<<2) | (1<<1), true); delay_us(50); /* Display on, cursor off, cursor blink off */ lcd_config(true, false, false); delay_us(50); lcd_cursor_pos(0, 0); delay_us(50); }
//------------------------------- void lcd_init(void) { DELAY_native(15000); gpio_init(); lcd_cmd_native(0x30); // 1, return home cursor lcd_cmd_native(0x30); // 1, return home cursor lcd_cmd_native(0x30); // 1, return home cursor lcd_cmd_native(0x30); // 1, return home cursor lcd_cmd_native(0x30); // 1, return home cursor lcd_config(DEFAULT_DISPLAY_CONFIG); // 1, Data Lenght, Number of lines, character font lcd_cmd_native(DEFAULT_DISPLAY_CONTROL); // 1, lcd, cursor, blink lcd_cmd_native(DEFAULT_ENTRY_MODE); // 1,increment/decrement,display shift on/off lcd_cmd_native(0x01); // clear display lcd_cmd_native(0x02); // 1, return home cursor #if (USE_PROGRESS_BAR) lcd_readybar(); #endif }
int main() { char arry[255]={0}; mJTAGPortEnable(0); lcd_config(); lcd_ini(); chip_select(); //select the slavehhjhjkhk unsigned short address=0x0000; unsigned char da_ta=0x20; unsigned char loc=0x80; for(i=0x0000,n=0;n<255;i++,n++) { lcd_ini(); arry[n]=read_ext_eeprom(i); } }
/********************************************************************* * * LCD_X_DisplayDriver * * Function description: * This function is called by the display driver for several purposes. * To support the according task the routine needs to be adapted to * the display controller. Please note that the commands marked with * 'optional' are not cogently required and should only be adapted if * the display controller supports these features. * * Parameter: * LayerIndex - Index of layer to be configured * Cmd - Please refer to the details in the switch statement below * pData - Pointer to a LCD_X_DATA structure * * Return Value: * < -1 - Error * -1 - Command not handled * 0 - Ok */ int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) { int r; (void) LayerIndex; (void) pData; switch (Cmd) { case LCD_X_INITCONTROLLER: { // // Called during the initialization process in order to set up the // display controller and put it into operation. If the display // controller is not initialized by any external routine this needs // to be adapted by the customer... // // ... lcd_config(); return 0; } default: r = -1; } return r; }
//------------------------------------------------------------------------------ // // Function: ShowSDLogo // // This function is called to display the splaschreen bitmap from the SDCard // // BOOL ShowSDLogo() { DWORD framebuffer = 0; DWORD framebufferPA = 0; DWORD dwLcdWidth = 0; DWORD dwLcdHeight = 0; DWORD dwLength = 0; // Get the LCD width and height LcdPdd_LCD_GetMode( NULL, &dwLcdWidth, &dwLcdHeight, NULL ); // Get the frame buffer LcdPdd_GetMemory( NULL, &framebufferPA ); framebuffer = (DWORD) OALPAtoUA(framebufferPA); // Compute the size dwLength = BYTES_PER_PIXEL * LOGO_WIDTH * LOGO_HEIGHT; if (!BLSDCardReadLogo(L"Logo.bmp", (UCHAR*)framebuffer, dwLength)) { return FALSE; } // Compute position and size of logo image g_dwLogoPosX = (dwLcdWidth - LOGO_WIDTH)/2; g_dwLogoPosY = (dwLcdHeight - LOGO_HEIGHT)/2; g_dwLogoWidth = LOGO_WIDTH; g_dwLogoHeight = LOGO_HEIGHT; //As BMP are stored upside down, we need to flip the frame buffer's content FlipFrameBuffer((PUCHAR)framebuffer,LOGO_HEIGHT,LOGO_WIDTH*BYTES_PER_PIXEL,(PUCHAR)framebuffer + dwLength); // Fire up the LCD lcd_config(framebufferPA); return TRUE; }
//------------------------------------------------------------------------------ // // Function: ShowLogo // // This function shows the logo splash screen // VOID ShowLogo(UINT32 flashAddr, UINT32 offset) { HANDLE hFlash = NULL; DWORD framebuffer; DWORD framebufferPA; PUCHAR pChar; ULONG x, y; WORD wSignature = 0; DWORD dwOffset = 0; DWORD dwLcdWidth, dwLcdHeight; DWORD dwLength; // Get the LCD width and height LcdPdd_LCD_GetMode( NULL, &dwLcdWidth, &dwLcdHeight, NULL ); dwLength = BYTES_PER_PIXEL * LOGO_WIDTH * LOGO_HEIGHT; // Get the video memory LcdPdd_GetMemory( NULL, &framebufferPA ); framebuffer = (DWORD) OALPAtoUA(framebufferPA); pChar = (PUCHAR)framebuffer; if (flashAddr != -1) { // Open flash storage hFlash = OALFlashStoreOpen(flashAddr); if( hFlash != NULL ) { // The LOGO reserved NAND flash region contains the BMP file OALFlashStoreBufferedRead( hFlash, offset, (UCHAR*) &wSignature, sizeof(wSignature), FALSE ); // Check for 'BM' signature if( wSignature == 0x4D42 ) { // Read the offset to the pixel data OALFlashStoreBufferedRead( hFlash, offset + 10, (UCHAR*) &dwOffset, sizeof(dwOffset), FALSE ); // Read the pixel data with the given offset OALFlashStoreBufferedRead( hFlash, offset + dwOffset, pChar, dwLength, FALSE ); } // Close store OALFlashStoreClose(hFlash); // Compute position and size of logo image g_dwLogoPosX = (dwLcdWidth - LOGO_WIDTH)/2; g_dwLogoPosY = (dwLcdHeight - LOGO_HEIGHT)/2; g_dwLogoWidth = LOGO_WIDTH; g_dwLogoHeight = LOGO_HEIGHT; //As BMP are stored upside down, we need to flip the frame buffer's content FlipFrameBuffer((PUCHAR)framebuffer,LOGO_HEIGHT,LOGO_WIDTH*BYTES_PER_PIXEL,(PUCHAR)framebuffer + dwLength); } } // If bitmap signature is valid, display the logo, otherwise fill screen with pattern if( wSignature != 0x4D42 ) { // Adjust color bars to LCD size g_dwLogoPosX = 0; g_dwLogoPosY = 0; g_dwLogoWidth = dwLcdWidth; g_dwLogoHeight = dwLcdHeight; for (y= 0; y < dwLcdHeight; y++) { for( x = 0; x < dwLcdWidth; x++ ) { if( y < dwLcdHeight/2 ) { if( x < dwLcdWidth/2 ) { *pChar++ = 0xFF; // Blue *pChar++ = 0x00; // Green *pChar++ = 0x00; // Red } else { *pChar++ = 0xFF; // Blue *pChar++ = 0x00; // Green *pChar++ = 0x00; // Red } } else { if( x < dwLcdWidth/2 ) { *pChar++ = 0xFF; // Blue *pChar++ = 0x00; // Green *pChar++ = 0x00; // Red } else { *pChar++ = 0xFF; // Blue *pChar++ = 0x00; // Green *pChar++ = 0x00; // Red } } } } } // Fire up the LCD lcd_config(framebufferPA); }
/* * Routine: misc_init_r * Description: Configure board specific parts */ int misc_init_r(void) { int err; hw_boot_status status_bits; unsigned short reg; unsigned char val; u8 data; /* * Configure drive strength for IO cells */ // already pulled up on board //*(ulong *)(CONTROL_PROG_IO1) &= ~(PRG_I2C2_PULLUPRESX); _board_revision(); printf("%s: initialize TPS65950 voltages\n", __func__); twl4030_power_init(); printf("%s: select TPS65950 power-on HW transitions(PWRON and RTC)\n", __func__); twl4030_set_px_transition(0x07, 0x49); printf("%s: select 1-GHz MPU clock\n", __func__); // 26 MHz * 500 / (12 + 1) select_mpu_clock(500, 12); lcd_config(); printf("%s: initialize all peripherals\n", __func__); omap_request_gpio(27); // Enable periph 3V omap_request_gpio(34); // reset USBHUB omap_request_gpio(38); // disable CAN omap_request_gpio(40); // reset modem omap_request_gpio(41); // disable modem omap_request_gpio(42); // reset CAP touch omap_request_gpio(43); // off CAN omap_request_gpio(61); // off modem omap_request_gpio(64); // off GPS omap_request_gpio(65); // off USB PHY omap_request_gpio(94); // automotive out high omap_request_gpio(95); // Wireless module VIO 1.8 V omap_request_gpio(98); // DEVICE_EN omap_request_gpio(111); // off USB PHY omap_request_gpio(136); // Wireless module VDD 3.6 V omap_request_gpio(137); // BT_EN omap_request_gpio(138); // WL_EN omap_request_gpio(144); // disable GPS omap_request_gpio(145); // reset GPS omap_request_gpio(146); // disable GPS boot omap_request_gpio(161); // select microphone omap_request_gpio(162); // serial transmitter force on omap_request_gpio(175); // shutdown internal speaker amplifier omap_request_gpio(176); // shutdown external speaker amplifier omap_request_gpio(177); // enable external I2C device omap_request_gpio(186); // PWR_ON generator // Enable serial ports transceiver omap_set_gpio_dataout(162, 1); omap_set_gpio_direction(162, 0); omap_set_gpio_dataout(98, 0); omap_set_gpio_direction(98, 0); omap_set_gpio_dataout(94, 0); omap_set_gpio_direction(94, 0); // enable peripheral 3.3 V omap_set_gpio_dataout(27, 1); omap_set_gpio_direction(27, 0); // PWR_ON generator will off omap_set_gpio_dataout(186, 1); omap_set_gpio_direction(186, 0); // disable BT omap_set_gpio_dataout(137, 0); omap_set_gpio_direction(137, 0); // disable WL omap_set_gpio_dataout(138, 0); omap_set_gpio_direction(138, 0); // wireless VIO 1.8V off omap_set_gpio_dataout(95, 0); omap_set_gpio_direction(95, 0); // remove wireless VDD 3.6 V omap_set_gpio_dataout(136, 0); omap_set_gpio_direction(136, 0); udelay(100000); // Supply VDD and VIO to WiFi omap_set_gpio_dataout(136, 1); omap_set_gpio_dataout(95, 1); udelay(100000); // enable digital PADs // MMC2 MUX_VAL(CP(MMC2_CLK), (IEN | PTU | EN | M0)) MUX_VAL(CP(MMC2_CMD), (IEN | PTU | EN | M0)) MUX_VAL(CP(MMC2_DAT0), (IEN | PTU | EN | M0)) MUX_VAL(CP(MMC2_DAT1), (IEN | PTU | EN | M0)) MUX_VAL(CP(MMC2_DAT2), (IEN | PTU | EN | M0)) MUX_VAL(CP(MMC2_DAT3), (IEN | PTU | EN | M0)) // UART2 MUX_VAL(CP(MCBSP3_FSX), (IEN | PTD | DIS | M1)) MUX_VAL(CP(MCBSP3_CLKX),(IDIS | PTD | DIS | M1)) MUX_VAL(CP(MCBSP3_DR), (IDIS | PTD | DIS | M1)) MUX_VAL(CP(MCBSP3_DX), (IEN | PTD | DIS | M1)) udelay(200000); // pulse enable pins // enable WL omap_set_gpio_dataout(138, 1); // enable BT omap_set_gpio_dataout(137, 1); udelay(200000); // Valdimir: temporary enabled // disable BT //omap_set_gpio_dataout(137, 0); // disable WL //omap_set_gpio_dataout(138, 0); omap_set_gpio_dataout(41, 0); omap_set_gpio_direction(41, 0); omap_set_gpio_dataout(40, 0); omap_set_gpio_direction(40, 0); omap_set_gpio_dataout(61, 0); omap_set_gpio_direction(61, 0); omap_set_gpio_dataout(144, 0); omap_set_gpio_direction(144, 0); omap_set_gpio_dataout(145, 0); omap_set_gpio_direction(145, 0); omap_set_gpio_dataout(146, 0); omap_set_gpio_direction(146, 0); omap_set_gpio_dataout(64, 0); omap_set_gpio_direction(64, 0); omap_set_gpio_dataout(38, 0); omap_set_gpio_direction(38, 0); omap_set_gpio_dataout(43, 0); omap_set_gpio_direction(43, 0); omap_set_gpio_dataout(42, 0); omap_set_gpio_direction(42, 0); omap_set_gpio_dataout(34, 0); omap_set_gpio_direction(34, 0); omap_set_gpio_dataout(111, 1); omap_set_gpio_direction(111, 0); omap_set_gpio_dataout(65, 0); omap_set_gpio_direction(65, 0); // enable internal speaker amplifier omap_set_gpio_dataout(175, 0); omap_set_gpio_direction(175, 0); // shutdown external speaker amplifier omap_set_gpio_dataout(176, 0); omap_set_gpio_direction(176, 0); // select internal microphone omap_set_gpio_dataout(161, 0); omap_set_gpio_direction(161, 0); // External I2C Bus enable omap_set_gpio_dataout(177, 0); omap_set_gpio_direction(177, 0); omap_free_gpio(27); omap_free_gpio(34); omap_free_gpio(38); omap_free_gpio(40); omap_free_gpio(41); omap_free_gpio(42); omap_free_gpio(43); omap_free_gpio(61); omap_free_gpio(64); omap_free_gpio(65); omap_free_gpio(94); omap_free_gpio(95); omap_free_gpio(98); omap_free_gpio(111); omap_free_gpio(136); omap_free_gpio(137); omap_free_gpio(138); omap_free_gpio(144); omap_free_gpio(145); omap_free_gpio(146); omap_free_gpio(161); omap_free_gpio(162); omap_free_gpio(175); omap_free_gpio(177); omap_free_gpio(186); printf("%s: initialize all peripherals done\n", __func__); twl4030_keypad_init(); // TODO: thermal shutdown and dynamic frequency scaling // TPS659XX PHY 3.3 V recovery workaround // Status bits read from companion chip and OMAP twl4030_i2c_read_u8(TWL4030_CHIP_RTC, &data, TWL_BACKUP_REG_G); //TWL_BACKUP_REG_G - set in thermal driver status_bits.thermal = data; twl4030_i2c_read_u8(TWL4030_CHIP_RTC, &data, TWL_RTC_STATUS_REG); //TWL_RTC_STATUS_REG status_bits.rtc_power_up = (data & TWL_RTC_STATUS_POWER_UP) ? 1 : 0; status_bits.rtc_alarm = (data & TWL_RTC_STATUS_ALARM) ? 1 : 0; status_bits.rtc_event = (data & (TWL_RTC_STATUS_ONE_D_EVENT | TWL_RTC_STATUS_ONE_H_EVENT | TWL_RTC_STATUS_ONE_M_EVENT | TWL_RTC_STATUS_ONE_S_EVENT))? 1 : 0; twl4030_i2c_read_u8(TWL4030_CHIP_RTC, &data, TWL_RTC_INTERRUPTS_REG); //TWL_RTC_INTERRUPTS_REG status_bits.rtc_it_timer = (data & TWL_RTC_INTERRUPTS_IT_TIMER) ? 1 : 0; status_bits.rtc_it_alarm = (data & TWL_RTC_INTERRUPTS_IT_ALARM) ? 1 : 0; twl4030_i2c_read_u8(TWL4030_CHIP_RTC, &data, TWL_STS_BOOT); //TWL_STS_BOOT status_bits.watchdog_reset = (data & (1<<5)) ? 1 : 0;//TWL_WATCHDOG_RESET twl4030_i2c_read_u8(TWL4030_CHIP_RTC, &data, TWL_STS_HW_CONDITIONS); //TWL_STS_HW_CONDITIONS status_bits.sts_pwon = (data & 1) ? 1 : 0; //STS_PWON status_bits.sts_warmreset = (data & (1<<3)) ? 1 : 0; //STS_WARMRESET twl4030_i2c_read_u8(TWL4030_CHIP_RTC, &data, TWL_PWR_ISR1); //TWL_PWR_ISR1 status_bits.isr_pwron = (data & STARTON_RTC) ? 1 : 0; status_bits.isr_rtc_it = (data & STARTON_PWON) ? 1 : 0; status_bits.prm_rstst = readl(OMAP_PRCM_PRM_RSTST); char str[9]; sprintf(str, "%d", status_bits.bits); setenv("hw_stat", str); printf("Status bits [0x%x] [%s]\n", status_bits.bits, str); printf("Board Revision A317 (%d)\n", board_revision); sprintf(str, "%s", "A-317"); setenv("product", str); dieid_num_r(); return 0; }
/*Place a string in the specified row and column of the screen. * +--+--+--+--+--+---------------------+ * |0x00 |0x01 |0x02 |0x03 |0x04 |0x05 ...etc |0x0F| <- 1st line * +--+--+--+--+--+---------------------+ * |0x40 |0x41 |0x42 |0x43 |0x44 |0x45 ...etc |0x4F| <- 2nd line * +--+--+--+--+--+---------------------+ */ void lcd_goto(unsigned char address) { lcd_config(0x80 + address); //command to move cursor to desire position base on the LCD DDRAM address }
/*Place a string in the specified row and column of the screen. * +--+--+--+--+--+---------------------+ * |0 |1 |2 |3 |4 |5 ...etc | <- row 0 * +--+--+--+--+--+---------------------+ * |0 |1 |2 |3 |4 |5 ...etc | <- row 1 * +--+--+--+--+--+---------------------+ */ void lcd_set_cursor(unsigned char uc_column, unsigned char uc_row) { if(uc_row == 0) lcd_config(0x80 + uc_column); //command to move cursor to first row/line with offset of column else if(uc_row ==1 ) lcd_config(0xC0 + uc_column); //command to move cursor to 2nd row/line with offset of column }
//function to move LCD cursor to home position void lcd_home(void) { lcd_config(0x02); //command to move cursor to home position __delay_ms(1); }
//Routine to clear the LCD void lcd_clear(void) { lcd_config(0x01); //command to clear LCD __delay_ms(1); }