📄 sample_lcd_project.c
字号:
#include <stdio.h>
#include<io.h>
#include<unistd.h>
// define LCD related parameters
#define LCD_BASE_ADDRESS 0x00A20820
//#define LCD_MULTIPLIER 0x4
#define LCD_WR_COMMAND_REG 0x00A20820 //0 for Dynamic
#define LCD_RD_COMMAND_REG 0x00A20824 //1
#define LCD_WR_DATA_REG 0x00A20828 //2
#define LCD_RD_DATA_REG 0x00A2082C //3
// define LCD Local parameters
#define LCD_CLR_DISPLAY 0x1
#define LCD_RETURN_HOME 0x2
#define LCD_INC_DD_ADDR 0x6
#define LCD_DEC_DD_ADDR 0x4
#define LCD_MOVE_DISPLAY 0x5
#define LCD_MOVE_CURSOR 0x4
int lcd_wr_command(int writedata)
{
int ret_code = 0;
IOWR(LCD_WR_COMMAND_REG, 0, writedata);
usleep(1);
return (ret_code);
}
int lcd_wr_data(int writedata)
{
int ret_code = 0;
IOWR(LCD_WR_DATA_REG, 0, writedata);
usleep(1);
return (ret_code);
}
int initialize_lcd(void)
{
int ret_code = 0;
// Setting 8-bit, 2 line, 5x7 mode - Function Set
ret_code = lcd_wr_command(0x38);
usleep(100);
// Setting 8-bit, 2 line, 5x7 mode - Function Set
ret_code = lcd_wr_command(0x38);
usleep(100);
// Setting Autoincrement mode without display shift - Entry Mode Set
ret_code = lcd_wr_command(0x06);
usleep(100);
// Setting Display ON, Cursor OFF, Blinking OFF - Display Control Set
ret_code = lcd_wr_command(0x0C);
usleep(100);
// Setting Cursor to home and clear display - Additional - Return Home Set
ret_code = lcd_wr_command(0x02);
usleep(100);
// Setting Cursor to home and clear display - Clear Display Set
ret_code = lcd_wr_command(0x01);
usleep(100);
return(ret_code);
}
int set_lcd_dd_address(int writedata)
{
int ret_code = 0;
IOWR(LCD_WR_COMMAND_REG, 0, writedata);
usleep(1);
return (ret_code);
}
int set_lcd_dd_data(int dd_address, char *dd_data, int data_length)
{
int ret_code = 0, i;
ret_code = set_lcd_dd_address(dd_address);
usleep(1); // 1 ms delay can be used
usleep(1000);
for(i=0;i<data_length;i++)
{
ret_code = lcd_wr_data(dd_data[i]); // Write Data
usleep(1); // 1 ms delay can be used
}
return (ret_code);
}
int lcd_test (void)
{
int ret_code = 0;
char lcd_data1[16] = "www.slscorp.com";
char lcd_data2[16] = "UP3 Kit ";
// Initialization sequence
printf("\nInitializing LCD ....");
ret_code = initialize_lcd();
printf("\nPrinting Data on LCD .....");
ret_code = set_lcd_dd_data(0x80, lcd_data1, 15);
ret_code = set_lcd_dd_data(0xC0, lcd_data2, 11);
printf("\n\nYou can See \"www.slscorp.com UP3 kit \" Printed on LCD ");
return 0;
}
int main()
{
lcd_test();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -