12864是128*64点阵液晶模块的点阵数简称,业界约定俗成的简称。
一、液晶显示模块概述
12864A-1 汉字图形点阵液晶显示模块,可显示汉字及图形,内置 8192 个中文汉字(16X16 点阵,16*8=128,16*4=64,一行只能写 8 个汉字,4 行;、128 个字符(8X16 点阵)及 64X256 点阵显示 RAM(GDRAM))。
主要技术参数和显示特性:
电源:VDD 3.3V~+5V(内置升压电路,无需负压);
显示内容:128 列× 64 行(128 表示点数)
显示颜色:黄绿
显示角度:6:00 钟直视
LCD 类型:STN
与 MCU 接口:8 位或 4 位并行/3 位串行
配置 LED 背光
多种软件功能:光标显示、画面移位、自定义字符、睡眠模式等
引脚定义:D0-D7,RS,RES,RD,WR,CS,BL;具体头文件定义如下:
#ifndef LCD12864_H
#define LCD12864_H
#define LCD12864_MAJOR 242
#define DEV_NAME "lcd12864"
#define LCD12864_IOCTL 'l'
#define SET_FONT_SIZE _IOW(LCD12864_IOCTL,0 ,unsigned int)
#define SET_LCD_PAGE _IOW(LCD12864_IOCTL,1 ,unsigned int)
#define SET_LCD_COLUMN _IOW(LCD12864_IOCTL,2 ,unsigned int)
#define CLR_SCREEN _IOW(LCD12864_IOCTL,3 ,unsigned int)
#define BACKLIGHT_CTRL _IOW(LCD12864_IOCTL,4 ,unsigned int)
#define CONTRAST_SETTING _IOW(LCD12864_IOCTL,5 ,unsigned int)
#define LCD_DATA_0 S3C2410_GPC8
#define LCD_DATA_1 S3C2410_GPC9
#define LCD_DATA_2 S3C2410_GPC10
#define LCD_DATA_3 S3C2410_GPC11
#define LCD_DATA_4 S3C2410_GPC12
#define LCD_DATA_5 S3C2410_GPC13
#define LCD_DATA_6 S3C2410_GPC14
#define LCD_DATA_7 S3C2410_GPC15
#define LCD_E_RD S3C2410_GPD0
#define LCD_RW_WR S3C2410_GPD1
#define LCD_RS S3C2410_GPD2
#define LCD_RES S3C2410_GPD3
#define LCD_CS1 S3C2410_GPD4
#define LCD_BL S3C2410_GPD5
#define LCD_DATA_CFG0_OUTP S3C2410_GPC8_OUTP
#define LCD_DATA_CFG1_OUTP S3C2410_GPC9_OUTP
#define LCD_DATA_CFG2_OUTP S3C2410_GPC10_OUTP
#define LCD_DATA_CFG3_OUTP S3C2410_GPC11_OUTP
#define LCD_DATA_CFG4_OUTP S3C2410_GPC12_OUTP
#define LCD_DATA_CFG5_OUTP S3C2410_GPC13_OUTP
#define LCD_DATA_CFG6_OUTP S3C2410_GPC14_OUTP
#define LCD_DATA_CFG7_OUTP S3C2410_GPC15_OUTP
#define LCD_E_RD_CFG_OUTP S3C2410_GPD0_OUTP
#define LCD_RW_WR_CFG_OUTP S3C2410_GPD1_OUTP
#define LCD_RS_CFG_OUTP S3C2410_GPD2_OUTP
#define LCD_RES_CFG_OUTP S3C2410_GPD3_OUTP
#define LCD_CS1_CFG_OUTP S3C2410_GPD4_OUTP
#define LCD_BL_CFG_OUTP S3C2410_GPD5_OUTP
#define FONT_SIZE_8 8
#define FONT_SIZE_16 16
#endif
将引脚单独用头文件重新自己定义一次,以提高代码的可移植性。
下面看看模块初始化/释放函数:
static int __init lcd12864_init( void )
{
int ret;
dev_t devno;
DBPRINTF(KERN_ALERT " %s enter!n " ,__func__);
devno = MKDEV(lcd12864_major, 0 );
if ((ret = register_chrdev_region(devno, 1 ,DEV_NAME)) < 0 )
{
if ((ret = alloc_chrdev_region( & devno, 0 , 1 , DEV_NAME)) < 0 )
{
DBPRINTF(KERN_ALERT " chrdev region fail!ret=%d;n " ,ret);
return ret;
}
else
{
lcd12864_major = MAJOR(devno);
}
}
cdev_init( & lcd_cdev, & lcd12864_ops);
lcd_cdev.owner = THIS_MODULE;
lcd_cdev.ops = & lcd12864_ops;
ret = cdev_add( & lcd_cdev, devno, 1 );
if (ret < 0 )
{
goto fail_reg;
}
lcd_dev_class = class_create(THIS_MODULE, DEV_NAME);
if (IS_ERR(lcd_dev_class))
{
goto fail_cdev;
}
device_create(lcd_dev_class, NULL, devno, NULL, DEV_NAME);
lcd_bd_info = kmalloc( sizeof ( struct lcd_board_info),GFP_KERNEL);
lcd_bd_info -> font_size = 16 ;
#ifdef NORMAL
lcd_bd_info -> pag = 0 ;
lcd_bd_info -> column = 0 ;
#else
lcd_bd_info -> pag = 6 ;
lcd_bd_info -> column = 112 ;
#endif
lcd_bd_info -> lcd_data_t = lcd_data_table;
lcd_bd_info -> lcd_data_cfg_t = lcd_data_cfg_table;
spin_lock_init( & lock );
gpio_pin_init();
// gpio_pin_init();
ret = init_lcd12864();
if (ret < 0 )
{
goto fail_dev;
}
back_light_ctrl( 1 );
clear_lcd_screen( 0x00 );
DBPRINTF(KERN_ALERT " %s leave,init success!n " ,__func__);
return ret;
fail_dev:
device_destroy(lcd_dev_class, devno);
class_destroy(lcd_dev_class);
fail_cdev:
cdev_del( & lcd_cdev);
fail_reg:
unregister_chrdev_region(devno, 1 );
return ret;
}
static void __exit lcd12864_exit( void )
{
kfree(lcd_bd_info);
device_destroy(lcd_dev_class, MKDEV(lcd12864_major, 0 ));
class_destroy(lcd_dev_class);
cdev_del( & lcd_cdev);
unregister_chrdev_region(MKDEV(lcd12864_major, 0 ), 1 );
}
module_init(lcd12864_init);
module_exit(lcd12864_exit);
MODULE_LICENSE( " GPL " );
MODULE_AUTHOR( " HOY " );
MODULE_DESCRIPTION( " gonsin 128x64 lcd driver " );
以上主要工作是:通过register_chrdev_region静态分配设备号devno,如果分配失败,则通过系统alloc_chrdev_region动态分配;
此处通过cdev创建字符设备;通过cdev_add添加入系统中。通过class_create和device_create生成并注册一个逻辑设备,通过此工作,可以在/dev/下面看到设备名;
初始化lcd_board_info结构,lcd_board_info结构定义如下:
struct lcd_board_info{
unsigned int font_size;
unsigned int pag;
unsigned int column;
unsigned long * lcd_data_t;
unsigned long * lcd_data_cfg_t;
};
static struct lcd_board_info * lcd_bd_info;
其他变量和头文件定义如下:
#include < linux / fs.h >
#include < linux / module.h >
#include < linux / init.h >
#include < mach / regs - gpio.h >
#include < linux / ioctl.h >
#include < linux / cdev.h >
#include < linux / slab.h >
#include < linux / uaccess.h >
#include < linux / device.h >
#include < asm / io.h >
#include < linux / delay.h >
#define DEBUG // 调试状态
#ifdef DEBUG
#define DBPRINTF(fmt,args...) printk(KERN_ALERT "lcd:" fmt, ##args)
#else
#define DBPRINTF(fmt,args...)
#endif
#include " lcd_12864.h "
#define NORMAL // 正常模式
static struct class * lcd_dev_class;
struct cdev lcd_cdev;
static int lcd12864_major = LCD12864_MAJOR;
static unsigned long lcd_data_table[] = {
LCD_DATA_0,
LCD_DATA_1,
LCD_DATA_2,
LCD_DATA_3,
LCD_DATA_4,
LCD_DATA_5,
LCD_DATA_6,
LCD_DATA_7,
};
/**/
static unsigned long lcd_data_cfg_table[] =
{
LCD_DATA_CFG0_OUTP,
LCD_DATA_CFG1_OUTP,
LCD_DATA_CFG2_OUTP,
LCD_DATA_CFG3_OUTP,
LCD_DATA_CFG4_OUTP,
LCD_DATA_CFG5_OUTP,
LCD_DATA_CFG6_OUTP,
LCD_DATA_CFG7_OUTP,
};
/*
static unsigned char io_read_byte()
{
}
*/
spinlock_t lock ;
然后调用以下函数进行gpio引脚的初始化、液晶屏的初始化:
static int gpio_pin_init( void )
{
int ii;
s3c2410_gpio_cfgpin(LCD_CS1, LCD_CS1_CFG_OUTP);
s3c2410_gpio_cfgpin(LCD_RES, LCD_RES_CFG_OUTP);
s3c2410_gpio_cfgpin(LCD_RS, LCD_RS_CFG_OUTP);
s3c2410_gpio_cfgpin(LCD_RW_WR, LCD_RW_WR_CFG_OUTP);
s3c2410_gpio_cfgpin(LCD_E_RD, LCD_E_RD_CFG_OUTP);
s3c2410_gpio_cfgpin(LCD_BL, LCD_BL_CFG_OUTP);
for (ii = 0 ; ii < 8 ; ii ++ )
{
s3c2410_gpio_cfgpin(lcd_bd_info -> lcd_data_t[ii], lcd_bd_info -> lcd_data_cfg_t[ii]);
}
return 0 ;
}
static unsigned char init_cmd[] = {
0xe2 ,
0xa0 ,
0xc0 ,
0xA2 ,
0x2B ,
0x2E ,
0x2F ,
0x27 ,
0xAF ,
0 ,
};
static int init_lcd12864( void )
{
int ii;
s3c2410_gpio_setpin(LCD_CS1, 0 );
udelay( 500 );
s3c2410_gpio_setpin(LCD_RES, 0 );
udelay( 500 );
s3c2410_gpio_setpin(LCD_RES, 1 );
udelay( 500 );
for (ii = 0 ;init_cmd[ii] != 0 ;ii ++ )
{
send_cmd(init_cmd[ii]);
udelay( 50 );
}
return 0 ;
}
以下为写液晶屏和写命令的操作:
#ifdef NORMAL
/* 往液晶中写入1个字符数据 */
static void io_write_byte(unsigned char data)
{
unsigned char ii;
spin_lock( & lock );
for (ii = 0 ;ii < 8 ;ii ++ )
{
if (data & 0b1)
{
s3c2410_gpio_setpin(lcd_bd_info -> lcd_data_t[ii], 1 );
}
else
{
s3c2410_gpio_setpin(lcd_bd_info -> lcd_data_t[ii], 0 );
}
data = data >> 1 ;
}
// __raw_writel(((__raw_readl(S3C2410_GPCDAT)&~(0xff<<8))|(data<<8)),S3C2410_GPCDAT);
spin_unlock( & lock );
s3c2410_gpio_setpin(LCD_RS, 1 );
s3c2410_gpio_setpin(LCD_RW_WR, 0 );
s3c2410_gpio_setpin(LCD_E_RD, 1 );
s3c2410_gpio_setpin(LCD_CS1, 1 );
udelay( 1 );
s3c2410_gpio_setpin(LCD_CS1, 0 );
udelay( 1 );
}
#else
static void io_write_byte(unsigned char data)
{
unsigned char ii;
spin_lock( & lock );
for (ii = 0 ;ii < 8 ;ii ++ )
{
if (data & 0x80 )
{
// DBPRINTF(KERN_ALERT "[||||||||||||||||||||]n");
s3c2410_gpio_setpin(lcd_bd_info -> lcd_data_t[ii], 1 );
}
else
{
// DBPRINTF(KERN_ALERT "[--------------------]n");
s3c2410_gpio_setpin(lcd_bd_info -> lcd_data_t[ii], 0 );
}
data = data << 1 ;
}
spin_unlock( & lock );
// DBPRINTF(KERN_ALERT "n");
s3c2410_gpio_setpin(LCD_RS, 1 );
s3c2410_gpio_setpin(LCD_RW_WR, 0 );
s3c2410_gpio_setpin(LCD_E_RD, 1 );
s3c2410_gpio_setpin(LCD_CS1, 1 );
udelay( 1 );
s3c2410_gpio_setpin(LCD_CS1, 0 );
udelay( 1 );
}
#endif
// 发送命令
static int send_cmd(unsigned char cmd)
{
int ii;
unsigned char tmp;
tmp = 0x00 ;
spin_lock( & lock );
for (ii = 0 ;ii < 8 ;ii ++ )
{
if (cmd & 0x80 )
{
s3c2410_gpio_setpin(lcd_bd_info -> lcd_data_t[ii], 1 );
}
else
{
s3c2410_gpio_setpin(lcd_bd_info -> lcd_data_t[ii], 0 );
}
cmd = cmd << 1 ;
}
/* ***************** */
/*
for(ii=0;ii<8;ii++)
{
tmp = tmp<<1;
if(cmd&0b1)
{
tmp|=0b1;
}
else
{
tmp &= 0b0;
}
cmd = cmd>>1;
}
__raw_writel(((__raw_readl(S3C2410_GPCDAT)&~(0xff<<8))|(tmp<<8)),S3C2410_GPCDAT); */
/* ***************** */
spin_unlock( & lock );
s3c2410_gpio_setpin(LCD_RS, 0 );
s3c2410_gpio_setpin(LCD_RW_WR, 0 );
s3c2410_gpio_setpin(LCD_E_RD, 1 );
s3c2410_gpio_setpin(LCD_CS1, 1 );
udelay( 1 );
s3c2410_gpio_setpin(LCD_CS1, 0 );
udelay( 1 );
return 0 ;
}
static int dev_write_data( const char * data)
{
unsigned char dl,dh;
int i,j;
spin_lock( & lock );
dh = lcd_bd_info -> column / 16 ;
dl = lcd_bd_info -> column - dh * 16 ;
for (i = 0 ; i < 2 ; i ++ )
{
send_cmd( 0xB7 - i - lcd_bd_info -> pag);
send_cmd( 0x10 + dh);
send_cmd(dl);
#ifdef NORMAL
for (j = 0 ;j < 16 ;j ++ )
io_write_byte(data[lcd_bd_info -> font_size * i + j]);
#else
for (j = 0 ;j < 16 ;j ++ )
io_write_byte(data[lcd_bd_info -> font_size * ( 1 - i) + ( 15 - j)]);
#endif
}
spin_unlock( & lock );
return 0 ;
}
上一篇:s3c2440(2410) USB HOST不稳定的原因及解决方法
下一篇:S3C2410触摸屏驱动代码分析1
推荐阅读最新更新时间:2024-11-13 10:55
设计资源 培训 开发板 精华推荐
- DER-412 - 12W高PF非隔离降压-升压TRIAC可调光LED驱动器,适用于A19灯泡
- 使用外部基准的 AD5314 10 位 DAC 的典型应用
- 使用 ROHM Semiconductor 的 BA15BC0FP-E2 的参考设计
- 用于 12V 应用的 LTC4367CMS8 过压电源控制器的典型应用
- 使用 Analog Devices 的 LTC4162IUFD-SAD 的参考设计
- 100W LLC DC-DC转换器
- 小型100瓦双向快充移动电源方案
- 2018电赛A题-电流信号检测装置(青岛理工大学)
- LT3088IST 线性稳压器用于添加软启动的典型应用
- C8051F000DK,MCU 开发套件包括一个带有预安装 C8051F005 器件的目标板,用于评估和初步软件开发