5110液晶驱动程序--AVR
//*******5110是一个48行*84 的点阵,12列*16的汉字只能显示3行(48/16=3),12*12的汉字
可以显示4行(48/12=4),图片取模可以显示出图片*********//
//端口
说明
关于失联党员情况说明岗位说明总经理岗位说明书会计岗位说明书行政主管岗位说明书
:res、cs、dc、sdin、sclk分别为PA口的0、1、2、3、4位
//注意:若把数组放入__flash区,我的数组地址送不出去,不知道为什么~~~~
/**************将
********************************************************************************************************************/
//LCD_write_byte(0x09,0); //黑屏命令LCD_write_byte(0x0D,0); //反映射输出(反白显示
命令)
#include
#define uchar unsigned char
#define uint unsigned int
#define BIT(X) (1 << X)
//*******************5110控制端口定义//
#define RES 0
#define CS 1
#define DC 2
#define SDIN 3
#define SCLK 4
//------------------------------取模汉字是12列16的数字
------------------------------------------------------------------------------// uchar DA[21][24]={
{0x00,0xC0,0xF0,0x30,0x18,0x08,0x08,0x08,0x30,0xF0,0xC0,0x00,0x00,0x07,0x1F,0x18,0x30,0x20,0x20,0x20,0x18,0x1F,0x07,0x00},//0
{0x00,0x00,0x10,0x10,0x10,0xF0,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x3F,0x3F,0x20,0x20,0x20,0x00,0x00},//1
{0x00,0x70,0x50,0x08,0x08,0x08,0x08,0x18,0xF0,0x70,0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x21,0x20,0x38,0x00,0x00},//2
{0x00,0x30,0x38,0x08,0x88,0x88,0xD8,0x78,0x30,0x00,0x00,0x00,0x00,0x18,0x38,0x20,0x20,0x20,0x20,0x31,0x1F,0x0E,0x00,0x00},//3
{0x00,0x00,0x00,0x80,0x40,0x20,0x10,0xF8,0xF8,0x00,0x00,0x00,0x00,0x06,0x05,0x04,0x04,0x24,0x24,0x3F,0x3F,0x24,0x24,0x00},//4
{0x00,0x00,0xF8,0x08,0x88,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x00,0x18,0x19,0x21,0x20,0x20,0x20,0x31,0x1F,0x0F,0x00,0x00},//5
{0x00,0xC0,0xE0,0x30,0x98,0x88,0x88,0x88,0x98,0x10,0x00,0x00,0x00,0x0F,0x1F,0x11,0x20,0x20,0x20,0x20,0x31,0x1F,0x0E,0x00},//6
{0x00,0x00,0x30,0x18,0x08,0x08,0x08,0x88,0x68,0x18,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x3E,0x01,0x00,0x00,0x00,0x00},//7
{0x00,0x70,0xF0,0x98,0x88,0x88,0x08,0x08,0x98,0x70,0x70,0x00,0x00,0x0C,0x1E,0x31,0x20,0x21,0x21,0x21,0x33,0x1E,0x0C,0x00},//8
{0x00,0xE0,0xF0,0x18,0x08,0x08,0x08,0x08,0x10,0xF0,0xE0,0x00,0x00,0x01,0x11,0x33,0x22,0x22,0x22,0x32,0x19,0x0F,0x07,0x00},//9
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//"."
{0x00,0x30,0x90,0x10,0x50,0x0A,0xF4,0x10,0x10,0x30,0x18,0x00,0x00,0x84,0x84,0x47,0x24,0x14,0x0F,0x14,0x24,0x64,0x04,0x00},//实
{0x00,0xFC,0x64,0x9C,0x04,0x44,0x44,0xC4,0x44,0x44,0x44,0x00,0x00,0x7F,0x08,0x0F,0x18,0x06,0x42,0x7F,0x00,0x06,0x18,0x00},//际
{0x00,0x80,0xF8,0x06,0x08,0xC8,0x3C,0x48,0x48,0xE8,0x08,0x00,0x01,0x00,0xFF,0x80,0x80,0x7F,0x95,0x95,0x95,0x7F,0x40,0x00},//值
{0x00,0x40,0xC4,0xC0,0x40,0x3C,0x04,0x04,0x3E,0xA0,0x20,0x00,0x00,0x00,0x0F,0x90,0x88,0x41,0x2F,0x19,0x27,0x41,0x40,0x00},//设
{0x00,0x40,0x5C,0x54,0x4C,0xF4,0x4C,0x54,0xD4,0x5C,0x20,0x00,0x00,0x00,0x40,0x7F,0x6B,0x6A,0x6B,0x6B,0x7F,0x40,0x40,0x00},//置
{0x00,0x80,0xF8,0x06,0x08,0xC8,0x3C,0x48,0x48,0xE8,0x08,0x00,0x01,0x00,0xFF,0x80,0x80,0x7F,0x95,0x95,0x95,0x7F,0x40,0x00}//值
};
//---------------------1ms延时函数
void delayms(uint ii)
{
uint i , x;
for (x = 0 ; x < ii ; x ++)
{
for ( i = 0 ; i < 200 ; i++);
}
}
//----------------------------------------------
//-------------液晶写命令函数-------------------
void LCD_write_com(uchar dt)
{
uchar i;
PORTA &= ~BIT(CS);//片选,低电平有效
PORTA &= ~BIT(DC);//DC为低
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
示输入命令
for(i = 0; i < 8;i ++)
{
PORTA &= ~BIT(SCLK); //sdin在时钟正边沿取样
if(dt & 0x80) //先送入字节高位
PORTA |= BIT(SDIN);
else
PORTA &= ~BIT(SDIN);
PORTA |= BIT(SCLK);
dt = dt << 1; //dt左移一位
}
PORTA |= BIT(DC);
PORTA |= BIT(CS);//片选,低电平有效
PORTA |= BIT(SDIN);
}
//----------------------------------------------
//--------------液晶写数据函数------------------
//com0dat1 :写数据/命令选择; 0 是命令 1是数据
//----------------------------------------------
void LCD_write_dat(uchar dt)
{
uchar i;
PORTA &= ~BIT(CS);//片选,低电平有效
PORTA |= BIT(DC);//dc为高表示输入数据
for(i = 0; i < 8;i ++)
{
PORTA &= ~BIT(SCLK); //sdin在时钟正边沿取样
if(dt & 0x80) //先送入字节高位
PORTA |= BIT(SDIN);
else
PORTA &= ~BIT(SDIN);
PORTA |= BIT(SCLK);
dt = dt << 1; //dt左移一位
}
PORTA |= BIT(DC);
PORTA |= BIT(CS);//片选,低电平有效
PORTA |= BIT(SDIN);
}
/*--------------------------------------- LCD_init: 3310LCD初始化
----------------------------------------- */ void LCD_init(void)
{
DDRA = 0XFF;
PORTA = 0XFF;
PORTA &= ~BIT(RES);//复位脉冲复位寄存器,因为接电源后内部寄存器和RAM的值不确定
delayms(10); //最多是100ms
PORTA |= BIT(RES);
LCD_write_com(0x21);//初始化Lcd,功能设定使用扩充指令
LCD_write_com(0xd0);//设定液晶偏置电压
LCD_write_com(0x20);//使用基本指令
LCD_write_com(0x0C);//设定显示模式,正常显示
// LCD_write_com(0x08);//设定显示为空白显示 屏蔽为白屏
// LCD_write_com(0x09);//设定显示为全部显示 屏幕为黑屏
// LCD_write_com(0x0d);//设定显示是反映射的 底部是黑的字是白的 // LCD_write_com(0x0C);//设定显示是正常模式,底部是白的字是黑的 }
/*------------------------------------------- LCD_set_XY: 设置LCD坐标函数
输入参数:X:0,83 Y:0,5
---------------------------------------------*/
void LCD_set_XY(uchar X, uchar Y) // X为列Y为行
{
LCD_write_com(0x40 | Y);//0x40|Y是由于设置行的命令中有0x40,而行取值为0-5,不会出现0x40,所以要|上
LCD_write_com(0x80 | X);//0x80 |X是由于设置列的命令中有0x80,而列取值为0-83,不会出现0x80,所以要|上
}
/*------------------------------------------ LCD_clear: LCD清屏函数
--------------------------------------------*/ void LCD_clear(void)
{
uchar t;
uchar k;
LCD_set_XY(0,0);
for(t=0;t<6;t++) //因液晶可自动向前推进,所以写
{ //一次地址即可
for(k=0;k<84;k++)
{
LCD_write_dat(0x00);
}
}
}
/*------------------------------------------------------------*/
/* ----------屏幕闪烁函数--制造一种动态效guo------------------*/
/* --------输入参数n是闪烁的次数------------------------------*/
void LCD_scrm_blink( char n)
{
for(;n>0;n--)
{
LCD_write_com(0x08);//显示为空白模式--显示空白不显字
delayms(250);
LCD_write_com(0x0C);//显示为普通模式--正常显示字符
delayms(250);
}
}
/*--------------------------------------------------------------------------------------------------------------------
-
LCD_write_shu: 显示6(宽)*16(高)点阵数字、字母函数 输入参数:c:显示的字符;
----------------------------------------------------------------------------------------------------------------------
-*/
/*void LCD_write_shu(uchar x, uchar y,uchar c[]) //x:列上第几个字 y:行 {
uchar i;
LCD_set_XY(x*12, y);// 列上第几个字符,行
for(i=0; i<6;i++) //写入字符上半部分
{
LCD_write_dat(c[i]);
}
LCD_set_XY(x*12, y+1);
for(i=6; i<12;i++) //写入字符下半部分
{
LCD_write_dat(c[i]);
}
} */
/*------------------------------------------------------------------------------------------------------
LCD_write_hanzi: 显示12(宽)*16(高)点阵汉字函数
输入参数:*p:显示的汉字;
--------------------------------------------------------------------------------------------------------*/
void LCD_write_hanzi_12_16(uchar x, uchar y,uchar *p) //x:列上的第几个汉字 y:行(取0--5)
{
uchar i;
LCD_set_XY(x*12, y);// 列上的第几个汉字,行
for(i=0; i<12;i++) //写汉字的上半部分
{
LCD_write_dat(*(p+i));
}
LCD_set_XY(x*12, y+1);// 列,页
for(i=12; i<24;i++)
{
LCD_write_dat(*(p+i));
}
}
/*------------------------------------------------------------------------------------------------------
write_hanzi: 显示12(宽)*16(高)点阵汉字函数
输入参数:*p:显示的汉字数组--即包括所有取模汉字;//x:列上的第几个汉字 y:行(取0--5)
(x,y)为要写汉字
的起始位置,n为要显示的汉字数
--------------------------------------------------------------------------------------------------------*/
void write_hanzi_12_16(uchar x, uchar y, uchar n, uchar p[21][24])
{
uchar i;
for(i = 0; i < n; i++)
{
if((y + ((x + i) / 7) * 2) < 6)
LCD_write_hanzi_12_16((x + i) % 7, y + ((x + i) / 7) * 2, p[i]);
else
return;
}
}
/*-------------------------------------------------------------------------------------------------------------------
LCD_write_hanzi: 显示12(宽)*12(高)点阵汉字函数***********一个12*12汉字分为上、中、下3部分
输入参数:x:列上的第几个汉字 y:行 *p为上面的汉字,*s为下面的汉字 ---------------------------------------------------------------------------------------------------------------------*
/
/*void LCD_write_hanzi_12_12(uchar x, uchar y,uchar *p,uchar *s)
{
uchar i;
uchar temp;
LCD_set_XY(x*12, y);//列上的第几个汉字,行
for(i=0; i<12;i++) //写上面汉字的上、中部分
{
LCD_write_dat(*(p+i));
}
LCD_set_XY(x*12, y+1);
for(i=0; i<12;i++) //把上面汉字的下部分和下面汉字上部分和起来写
{ temp=*(s+i);
temp=temp<<4;
temp=temp|(*(p+i+12));
LCD_write_dat(temp);
}
LCD_set_XY(x*12, y+2);
for(i=0;i<12;i++) //把下面汉字的中、下部分合起来写
{
temp=((*(s+i)&0xf0)|*(s+i+12));
temp=_crol_(temp,4);//循环左移
LCD_write_dat(temp);
}
}*/
//**************************************主函数
void main()
{
unsigned char k;
DDRA = 0XFF;
PORTA = 0XFF;
PORTA &= ~BIT(RES);
for(k=0;k<250;k++);
PORTA |= BIT(RES);
LCD_init(); //初始化LCD模块
LCD_clear();
write_hanzi_12_16(0, 0, 12, DA);
delayms(1000);
LCD_scrm_blink(5);//屏幕闪烁5次
LCD_write_com(0x09); //黑屏命令
delayms(500);
LCD_write_com(0x0D); //反映射输出(反白显示命令)
while(1) ;
}