A. 用51单片机中1602做一个4位显示的秒表
#defineLCD1602_FLAG
#defineLCD1602_PORTP0
#include<reg51.h>
#include<stddef.h>
#defineucharunsignedchar
sbitlcd1602_rs=P2^0;
sbitlcd1602_e=P2^2;
sbitlcd1602_rw=P2^1;
sbitlcd1602_busy=P0^7;
ucharstr[]="StopWatch";
uchartime,disdat[4];
uchardat,sec,key;
voiddelay(uchara)
{
uchari;
while(a--)for(i=0;i<120;i++);
}
/*
************************************
*函数名称:lcd1602_CheckBusy()
*函数功能:状态查询
************************************
*/
voidlcd1602_CheckBusy()
{
do
{
lcd1602_busy=1;
lcd1602_rs=0;
lcd1602_rw=1;
lcd1602_e=0;
lcd1602_e=1;
}
while(lcd1602_busy);
}
/*
***************************************
*函数名称:lcd1602_WriteCmd()
*函数功能:写命令
*入口参数:命令字
*出口参数:无
***************************************
*/
voidlcd1602_WriteCmd(constucharcmd)
{
lcd1602_CheckBusy();
lcd1602_rs=0;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=cmd;
lcd1602_e=0;
}
/*
*******************************************
*函数名称:lcd1602_WriteData()
*函数功能:写数据
*入口参数:c--待写数据
*出口参数:无
*********************************************
*/
voidlcd1602_WriteData(constucharc)
{
lcd1602_CheckBusy();
lcd1602_rs=1;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=c;
lcd1602_e=0;
}
/*
***********************************************
*函数名称:lcd1602_Init()
*函数功能:初始化LCD
*入口参数:无
*出口参数:无
***********************************************
*/
voidlcd1602_Init()
{
lcd1602_WriteCmd(0x38); //显示模式为8位2行5*7点阵
lcd1602_WriteCmd(0x0c);//displayenable,flagenable,flashenable,
lcd1602_WriteCmd(0x06);//flagmovetoright,screendon'tmove
lcd1602_WriteCmd(0x01);//clearscreen
}
/*
************************************************
*函数名称:lcd1602_Display()
*函数功能:字符显示
*入口参数:ptr--字符或字符串指针
*出口参数:无
*说明:用户可通过以下方式来调用:
*1)lcd1602_Display("Hello,world!");
*2)INT8U存储类型txt[]="要显示的字符串";
*或者INT8U存储类型txt[]={'t','x','t',..,'