📄 并行-16.txt
字号:
Char_Set_XY(0,0,"ntzhf100@163.com"); //在第0行的第0个位置依次输出文字
Char_Set_XY(2,1,"蓝水天下"); //在第1行的第2个位置依次输出文字
Char_Set_XY(0,2,"我的天下,我的自"); //在第2行的第0个位置依次输出文字
Char_Set_XY(0,3,"由空间!"); //在第3行的第0个位置依次输出文字
Delay(2000); //软件延时2S
Lcd_flash(500,3); //液晶闪烁程序每次500ms的延时,闪动3次
//=========液晶内部的地址=============
//Line1 80H 81H 82H 83H 84H 85H 86H 87H
//Line2 90H 91H 92H 93H 94H 95H 96H 97H
//Line3 88H 89H 8AH 8BH 8CH 8DH 8EH 8FH
//Line4 98H 99H 9AH 9BH 9CH 9DH 9EH 9FH
//因为液晶本身的缺陷,所以移动显示会很丑
Move(8,left,500); //液晶左移程序,移动8步,步与步之间间隔500ms
Delay(2000); //软件延时2S
Move(8,right,500); //液晶右移程序,移动8步,步与步之间间隔500ms
Delay(2000); //软件延时2S
Set_Draw(); //设定为绘图模式
Draw_Pic(0,0,*PIC1); //第一张图片ATMEL的LOGO
Delay(3000); //软件延时3S
Draw_Pic(0,0,*PIC2); //第一张图片AVR的LOGO
Delay(3000); //软件延时3S
Lcd_Init(); //重新设定为普通模式,即输出中英文和字符模式
}
}
/*************************************************/
void Chip_Init(void)
{
DDRA = 0XFF;
PORTA = 0X00;
DDRB = 0X07;
PORTB = 0X00;
}
/*************************************************/
void Lcd_Init(void)
{
uint8_t cmd;
cmd=0x30; //功能设置 8位数据,基本指令
WriteCom(cmd); //写指令
cmd=0x0C; //显示状态 ON,游标OFF,反白OFF
WriteCom(cmd); //写指令
cmd=0x01; //清除显示
WriteCom(cmd); //写指令
cmd=0x02; //地址归位
WriteCom(cmd); //写指令
cmd=0x80; //设置DDRAM地址
WriteCom(cmd); //写指令
Delay(100); //延时
}
/*************************************************/
void Delay(uint16_t ms) //毫秒级延时,当改晶振为几M则xtal设为几
{
uint16_t i;
while(ms--)
{
for(i=1;i<(uint16_t)(xtal*143-2);i++)
;
}
}
/*************************************************/
void Lcd_flash(uint16_t delay_t,uint8_t times)
{
uint8_t j;
for(j=0;j<times;j++)
{
WriteCom(0x08); //关闭显示
Delay(delay_t); //软件延时
WriteCom(0x0c); //开显示
Delay(delay_t); //软件延时
}
}
/*************************************************/
void Move(uint8_t step,uint8_t dirction,uint16_t time)
{
uint8_t i;
for(i=0;i<step-1;i++) //移动的步数
{
WriteCom(dirction); //文字移动方向
Delay(time); //控制移动时间
}
}
/*************************************************/
void WriteCom(uint8_t CMD) //写控制命令函数
{
while(CheckBusy()); //检测液晶内部是否忙
Clr_RS();
Clr_RW();
DATA_PORT = CMD;
Set_EN();
nop();
nop();
Clr_EN();
}
/*************************************************/
void WriteDat(uint8_t DAT) //写数据函数
{
while(CheckBusy()); //检测液晶内部是否忙
Set_RS();
Clr_RW();
DATA_PORT = DAT;
Set_EN();
nop();
nop();
Clr_EN();
}
/*************************************************/
uint8_t CheckBusy(void)
{
uint8_t temp;
DATA_PORT = 0XFF;
Clr_RS();
nop(); //这里的nop不能省略,否则不行
Set_RW();
nop();
Set_EN();
nop();
Set_input();
nop();
temp = PINA;
nop();
Clr_EN();
nop();
Set_output();
temp &= 0x80;
return(temp);
}
/*************************************************/
void Char_Set_XY(uint8_t x, uint8_t y, uint8_t *p)
{
if(y == 0)
{
WriteCom((0x80+x));
}
if(y == 1)
{
WriteCom((0x90+x));
}
if(y == 2)
{
WriteCom((0x88+x));
}
if(y == 3)
{
WriteCom((0x98+x));
}
while(*p != 0)
{
WriteDat(*p++);
}
}
/*************************************************/
void Set_Draw(void)
{
WriteCom(0x01); //清屏
Delay(20); //延时
WriteCom(0x36); //8BIT控制界面,扩充指令集,,绘图显示ON
Delay(20); //延时
}
/*************************************************/
void Draw_Pic(uint8_t x, uint8_t y, const uint8_t *Draw)
{
uint8_t i, j, temp_x, temp_y;
temp_x = x;
temp_y = y;
temp_x |= 0x80;
temp_y |= 0x80;
for(i=0;i<32;i++ )
{
WriteCom(temp_y++); //设置绘图区的Y地址坐标
WriteCom(temp_x); //设置绘图区的X地址坐标
for(j=0;j<16;j++)
{
WriteDat(*Draw);
Draw++;
}
}
temp_x = 0x88;
temp_y = 0x80;
j = 0;
for(;i<64;i++ )
{
WriteCom(temp_y++); //设置绘图区的Y地址坐标
WriteCom(temp_x); //设置绘图区的X地址坐标
for(j=0;j<16;j++)
{
WriteDat(*Draw);
Draw++;
}
}
}
/**************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -