|
发表于 2013-3-10 22:18:52
|
显示全部楼层
这是3310的程序,5110的一样可能驱动,我实验过的!
#include <reg51.h>
sbit sce = P0^0; //片选
sbit res = P0^1; //复位,0复位
sbit dc = P0^2; //1写数据,0写指令
sbit sdin = P1^5; //数据
sbit sclk = P1^7; //时钟
unsigned char code hanzi[]=
{
/*-- 文字: 单 --*/
/*-- 宋体9; 此字体下对应的点阵为:宽x高=12x12 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/
0x00,0x00,0x7C,0x55,0x56,0xFC,0x56,0x55,0x54,0x7C,0x00,0x00,0x01,0x01,0x01,0x01,
0x01,0x07,0x01,0x01,0x01,0x01,0x01,0x00,
/*-- 文字: 片 --*/
/*-- 宋体9; 此字体下对应的点阵为:宽x高=12x12 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/
0x00,0x00,0xFF,0x48,0x48,0x48,0x4F,0xC8,0x08,0x08,0x08,0x00,0x04,0x02,0x01,0x00,
0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,
/*-- 文字: 机 --*/
/*-- 宋体9; 此字体下对应的点阵为:宽x高=12x12 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/
0x84,0x64,0xFF,0x24,0x44,0xFE,0x02,0x02,0xFF,0x02,0x00,0x00,0x01,0x00,0x07,0x04,
0x02,0x01,0x00,0x00,0x07,0x04,0x07,0x00,
/*-- 文字: 开 --*/
/*-- 宋体9; 此字体下对应的点阵为:宽x高=12x12 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/
0x20,0x22,0x22,0xFE,0x22,0x22,0x22,0xFE,0x22,0x23,0x22,0x00,0x04,0x04,0x02,0x01,
0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,
/*-- 文字: 发 --*/
/*-- 宋体9; 此字体下对应的点阵为:宽x高=12x12 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/
0x08,0x0E,0x88,0x78,0x2F,0xE8,0x28,0xA9,0x6A,0x08,0x08,0x00,0x04,0x02,0x05,0x04,
0x02,0x02,0x01,0x02,0x02,0x04,0x04,0x00,
/*-- 文字: 工 --*/
/*-- 宋体9; 此字体下对应的点阵为:宽x高=12x12 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/
0x00,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x03,0x02,0x00,0x00,0x04,0x04,0x04,0x04,
0x04,0x07,0x04,0x04,0x04,0x04,0x04,0x00,
/*-- 文字: 作 --*/
/*-- 宋体9; 此字体下对应的点阵为:宽x高=12x12 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/
0x10,0x08,0xFC,0x13,0x08,0x04,0xFF,0x24,0x24,0x24,0x04,0x00,0x00,0x00,0x07,0x00,
0x00,0x00,0x07,0x01,0x01,0x01,0x01,0x00,
/*-- 文字: 室 --*/
/*-- 宋体9; 此字体下对应的点阵为:宽x高=12x12 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/
0x04,0x06,0x4A,0x6A,0x5A,0xCB,0x4A,0x5A,0x6A,0x4A,0x06,0x00,0x04,0x04,0x05,0x05,
0x05,0x07,0x05,0x05,0x05,0x04,0x04,0x00
};
void delayms(unsigned int ii)//1ms延时函数
{
unsigned int i,x;
for (x=0;x<ii;x++)
{
for (i=0;i<100;i++);
}
}
/*--------------------------------------------
LCD_write_byte: 使用SPI接口写数据到LCD
输入参数:dt:写入的数据;
command :写数据/命令选择;
编写日期:20080918
----------------------------------------------*/
void LCD_write_byte(unsigned char dt, unsigned char command)
{
unsigned char i;
sce=0;
dc=command;
for(i=0;i<8;i++)
{
if(dt&0x80)
sdin=1;
else
sdin=0;
dt=dt<<1;
sclk=0;
sclk=1;
}
dc=1;
sce=1;
sdin=1;
}
/*---------------------------------------
LCD_init: 3310LCD初始化
编写日期:20080918
----------------------------------------- */
void LCD_init(void)
{
res=0;
delayms(10);
res=1;
LCD_write_byte(0x21,0);//初始化Lcd,功能设定使用扩充指令
LCD_write_byte(0xC6,0);//设定液晶偏置电压
LCD_write_byte(0x06,0);//温度校正
LCD_write_byte(0x13,0);;//1:48
LCD_write_byte(0x20,0);//使用基本指令
LCD_write_byte(0x0C,0);//设定显示模式,正常显示
}
/*-------------------------------------------
LCD_set_XY: 设置LCD坐标函数
输入参数:X:0-83 Y:0-5
编写日期:20080918
---------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0);// column
LCD_write_byte(0x80 | X, 0);// row
}
/*------------------------------------------
LCD_clear: LCD清屏函数
编写日期:20080918
--------------------------------------------*/
void LCD_clear(void)
{
unsigned char t;
unsigned char k;
LCD_set_XY(0,0);
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(0x00,1);
}
}
}
/*---------------------------------------------
LCD_write_hanzi: 显示12(宽)*16(高)点阵列汉字等半角类
输入参数:c:显示的字符;
编写日期:20080918
-----------------------------------------------*/
void LCD_write_hanzi(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符 12*16
{
unsigned char i;
LCD_set_XY(row*6, page);// 列,页
for(i=0; i<12;i++)
{
LCD_write_byte(hanzi[c*24+i],1);
}
LCD_set_XY(row*6, page+1);// 列,页
for(i=12; i<24;i++)
{
LCD_write_byte(hanzi[c*24+i],1);
}
}
void main()
{
unsigned char k;
delayms(1000);
sce=0;
res=0;
for(k=0;k<250;k++);
res=1;
LCD_init(); //初始化LCD模块
LCD_clear(); //清屏幕
LCD_write_hanzi(0,0,0); //单
LCD_write_hanzi(2,0,1); //片
LCD_write_hanzi(4,0,2); //机
LCD_write_hanzi(6,0,3); //开
LCD_write_hanzi(8,0,4); //发
LCD_write_hanzi(10,0,5); //工
LCD_write_hanzi(12,0,6); //作
LCD_write_hanzi(0,2,7); //室
while(1);
}
|
|