LCD160160驱动编写(uc1698u)

本文详细描述了如何使用uc1698u驱动彩色或黑白LCD160160液晶屏,包括初始化过程、设置显示位置以及写入数据控制像素的方法,提供了Write_Word函数示例和显示“功率”文字的应用案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

LCD160160液晶屏一般在电表远程终端领域应用较多。内置uc1698u为彩色驱动芯片,而LCD160160液晶屏是160*160像素的黑白显示屏,所以写入12bit数据才能控制3个像素。对应彩色屏的话就是RGB三色。

注意:阅读过uc1698u的手册发现,写指令是双字节。刚开始写驱动时也有点懵了。通过初始化LCD之后,配置好初始位置后,就可以写数据去点亮像素了,每写4个bit,控制1个像素。

配置好接口:

//==============================================================================
// 函数功能:LCD数据输入的修改
//==============================================================================
void write(uint8_t flag, uint8_t dat)
{
    cog_cd(flag); // flag=0,write command;flag=1,write data 
    cog_rd(1);
    cog_cs(0);
    cog_dportout(dat);
    cog_wr(0);
    cog_wr(1);
    cog_cs(1);
}

写入指令控制显示位置

//==============================================================================
// 函数功能:设置显示位置
//==============================================================================
void set_lcd_address(uint8_t x,uint8_t y)  //x:横坐标 , y:纵坐标
{
//	  write(0, 0x60); // row address LSB
//    write(0, 0x70); // row address MSB
//    write(0, 0x05); // culomn address LSB
//    write(0, 0x12); // culomn address MSB
	 
	write(0,0x60 + (y&0x0f)); write(0,0x70 + ((y>>4)&0x0f)); //设置y坐标起始位置
	write(0,0x05 + (x&0x0f)); write(0,0x12 + ((x>>4)&0x0f)); //设置x坐标起始位置
}

主要驱动代码

/*==============================================================================
    x:起始x坐标
    y:起始y坐标
	num:有几个字
	type: 1为英文,2为中文
    字模取16*16
==============================================================================*/
void Write_Word(uint8_t x, uint8_t y, uint8_t num, uint8_t type, const uint8_t *p)
{							
	uint8_t i,j,data0,data1;
	for(i=0;i<16;i++)
	{
		set_lcd_address(x,y+i);
		for(j=0;j<type*num;j++)
		{
			data1 = 0;
			data0 = (*(p+i*type*num+j)) & 0x80;
			data1 = data0;
			data0 = (*(p+i*type*num+j)) & 0x40;
			data1 = data1 | (data0>>3);
			write(1,data1);
			
			data1 = 0;
			data0 = (*(p+i*type*num+j)) & 0x20;
			data1 = data0<<2;
			data0 = (*(p+i*type*num+j)) & 0x10;
			data1 = data1 | (data0>>1);
			write(1,data1);
			
			data1 = 0;
			data0 = (*(p+i*type*num+j)) & 0x08;
			data1 = data0<<4;
			data0 = (*(p+i*type*num+j)) & 0x04;
			data1 = data1 | (data0<<1);
			write(1,data1);
			
			data1 = 0;
			data0 = (*(p+i*type*num+j)) & 0x02;
			data1 = data0<<6;
			data0 = (*(p+i*type*num+j)) & 0x01;
			data1 = data1 | (data0<<3);
			write(1,data1);
		}
		write(1,0);
	}
}

应用驱动示例,显示“功率”文字

//==============================================================================
// 函数功能:显示功率
//==============================================================================
void display_P(uint8_t x,uint8_t y)
{
	Write_Word(x, y, 6, 2, P_bytes);
}
// “功率(W):” 字模  16*8*num(12)
const uint8_t P_bytes[] = {
    0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x40, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 
    0x00, 0x40, 0x7f, 0xfc, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 
    0xfe, 0x40, 0x02, 0x00, 0x08, 0x00, 0xd6, 0x00, 0x10, 0x00, 0x00, 0x00, 
    0x11, 0xfc, 0x44, 0x44, 0x08, 0x00, 0x54, 0x00, 0x10, 0x00, 0x00, 0x00, 
    0x10, 0x44, 0x2f, 0x88, 0x10, 0x00, 0x54, 0x00, 0x08, 0x00, 0x00, 0x00, 
    0x10, 0x44, 0x11, 0x10, 0x10, 0x00, 0x54, 0x00, 0x08, 0x00, 0x00, 0x00, 
    0x10, 0x44, 0x22, 0x48, 0x10, 0x00, 0x54, 0x00, 0x08, 0x00, 0x00, 0x00, 
    0x10, 0x44, 0x4f, 0xe4, 0x10, 0x00, 0x54, 0x00, 0x08, 0x00, 0x00, 0x00, 
    0x10, 0x84, 0x00, 0x20, 0x10, 0x00, 0x6c, 0x00, 0x08, 0x00, 0x30, 0x00, 
    0x10, 0x84, 0x01, 0x00, 0x10, 0x00, 0x28, 0x00, 0x08, 0x00, 0x30, 0x00, 
    0x1e, 0x84, 0xff, 0xfe, 0x08, 0x00, 0x28, 0x00, 0x10, 0x00, 0x00, 0x00, 
    0xf1, 0x04, 0x01, 0x00, 0x08, 0x00, 0x28, 0x00, 0x10, 0x00, 0x30, 0x00, 
    0x41, 0x04, 0x01, 0x00, 0x04, 0x00, 0x28, 0x00, 0x20, 0x00, 0x30, 0x00, 
    0x02, 0x28, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 
    0x04, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

以上为简单的驱动代码,还有很多优化空间。

ARM9的160*160液晶屏驱动。 一、 驱动使用方法: 1、 编译内核:将hgo.c复制到linux内核下drivers/char 目录,修改drvers/char/Makefile 在 obj-$(CONFIG_AT91_LED) += at91_led.o 一句之后,添加: obj-y += hgo.o 重新编译内核,驱动即可编译进内核。 2、建立设备节点:重新烧写内核后,进入系统终端,执行 #mknod /dev/hgo c 227 0 3、使用应用程序访问内核: 可以用如下方式写应用程序: int fd; fd = open (“/dev/hgo”, O_RDWR); ioctl(fd, IOCTL_LCD_RESET, 0); //read(fd, *buf, count); //write(fd, *buf, count); 详细应用程序写法可参考主板上其他设备测试程序。 二、 驱动程序说明: 1、 初始化:系统加载驱动时,会执行hgo_init_module()函数,再此函数中可以执行一些初始化的操作,目前驱动中该函数执行的操作为: a) 映射内存。 b) 配置EBI总线 c) 设置屏的复位管脚为高电平(屏的复位管脚定义为: #define PIN_RESET AT91_PIN_PB20,可根据自己的设计修改)。 d) 注册设备 2、 对屏的硬件操作: 对屏的操作,为以下4个函数: /* write data */ static void write_data(unsigned char data) { writeb( data, lcdbase + 4); } /* write instuction */ static void write_ins(unsigned char ins) { writeb( ins, lcdbase); } /* read data */ static unsigned char read_data(void) { return readb(lcdbase + 4); } /* read instruction */ static unsigned char read_ins(void) { return readb(lcdbase); } 总线上有读写两个操作,通过屏的管脚A0的不同,又有数据和指令两种。 3、 应用程序接口:应用程序接口函数有3个 device_read(); device_write(); hgo_ioctl(); 当应用程序执行read() write() ioctl() 时会分别调用到这三个函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值