
#define LCD1602_FLAG
#define LCD1602_PORT P1
#include<reg51.h>
#include<stddef.h>
#define uchar unsigned char
sbit lcd1602_rs=P3^0
sbit lcd1602_e=P3^5
sbit lcd1602_rw=P3^1
sbit lcd1602_busy=P0^7
uchar str[]="StopWatch"
uchar time,disdat[4]
uchar dat,sec,key
void delay(uchar a)
{
uchar i
while(a--)for(i=0i<120i++)
}
/*
************************************
* 函数功能:状态查询
************************************
*/
void lcd1602_CheckBusy()
{
do
{
lcd1602_busy=1
lcd1602_rs=0
lcd1602_rw=1
lcd1602_e=0
lcd1602_e=1
}
while(lcd1602_busy)
}
/*
***************************************
* 函数名称: lcd1602_WriteCmd()
* 函数功能:写命令
* 入口参数:命令字
* 出口参数:无
***************************************
*/
void lcd1602_WriteCmd(const uchar cmd)
{
lcd1602_CheckBusy()
lcd1602_rs=0
lcd1602_rw=0
lcd1602_e=1
LCD1602_PORT=cmd
lcd1602_e=0
}
/*
*******************************************
* 函数名称:lcd1602_WriteData()
* 函数功能:写数据
* 入口参数:c--待写数据
* 出口参数:无
*********************************************
*/
void lcd1602_WriteData(const uchar c)
{
lcd1602_CheckBusy()
lcd1602_rs=1
lcd1602_rw=0
lcd1602_e=1
LCD1602_PORT=c
lcd1602_e=0
}
/*
***********************************************
* 函数名称:lcd1602_Init()
* 函数功能:初始化LCD
* 和液入口参数:无
* 出口参数:无
***********************************************
*/
void lcd1602_Init()
{
lcd1602_WriteCmd(0x38) //显示模式为8位2行5*7点阵
lcd1602_WriteCmd(0x0c) //display enable,flag enable,flash enable,
lcd1602_WriteCmd(0x06) //flag move to right,screen don't move
lcd1602_WriteCmd(0x01) //clear screen
}
/*
************************************************
* 函数名称:lcd1602_Display()
* 函数功能: 字符显示
* 入口参数:ptr--字符或字符串指针
* 出口参数:无
* 说 明:用户可通过以下方式来调用:
* 1)lcd1602_Display("Hello,world!")
* 2) INT8U 存储类型 txt[]="要显示的字符串"
* 或者 INT8U 存储类型 txt[]={'t','x','t',..,'\0'}
* INT8U *ptr
* 唤袭物 ptr=&txt
* lcd1602_Display(ptr)
* 禅局 或 lcd1602_Display(txt)
* 或 lcd1602_Display(&txt)
************************************************
*/
void lcd1602_Display(const uchar *ptr,uchar line)
{
uchar data i=0
uchar *data q
q=ptr
switch(line)
{
case 0:
lcd1602_WriteCmd(0x80)
while(q!=NULL && (*q!='\0') && i<16)
{
lcd1602_WriteData(*q)
q++
i++
}
break
case 1:
lcd1602_WriteCmd(0xc0)
while(q!=NULL && (*q!='\0') && i<16)
{
lcd1602_WriteData(*q)
q++
i++
}
break
}
}
void dischg()
{
disdat[3]=dat+0x30
disdat[2]='.'
disdat[1]=sec%10+0x30
disdat[0]=sec/10+0x30
lcd1602_Display(disdat,1)
}
void ext0() interrupt 0
{
key++
key%=3
}
void t0isr() interrupt 1 //秒计时
{
TH0=0x3c
TL0=0xb0
time++
if(time==2)
{
time=0
dat++
if(dat>=10)
{
dat=0
sec++
if(sec>59)sec=0
}
dischg()
}
}
main()
{
TMOD=0x01
TH0=0x3c
TL0=0xb0
TR0=1
ET0=1
EX0=1
IT0=1
EA=1
time=0
dischg()
lcd1602_Init()
lcd1602_Display(str,0)
lcd1602_Display(disdat,1)
while(1)
}
写入1602速度并不是很慢,每次数据更新时都要将十位和个位重新写入LCD如果不想显示 01 前面的0,可加判断语句,如果十位>0,则显示十位,碧信指否则悔配直接显示个位
你说1602不能连续写入,指的是什么坦数?1602列地址会自动加1,给一个地址可写多个数据
单片机一定要ATmega16的,LCD是1602的,秒表程序是c语言编的,要是能带注释名称:液晶控制与显示程序 说明:本程序毕郑是埋缓通用的1602液晶手液颂AVR6.31A,仿真为欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)