新闻中心

EEPW首页>嵌入式系统>设计应用> 51单片机电子时钟程序

51单片机电子时钟程序

作者: 时间:2016-12-01 来源:网络 收藏

unsigned char busy(void)//判忙函数
{
bit result;
RS=0;
RW=1;
E=1;
_nop_();
_nop_();
_nop_();
_nop_();
result=BF;
E=0;
return result;
}
void writeinstruction(uchar dictate)//写指令
{
while(busy()==1);
RS=0;
RW=0;
E=0;
_nop_();
_nop_();
P0=dictate;
_nop_();
_nop_();
_nop_();
_nop_();
E=1;
_nop_();
_nop_();
_nop_();
_nop_();
E=0;
}
void writeaddress(uchar x)//写地址
{
writeinstruction(x|0x80);
}
void wretedata(uchar y)//写数据
{
while(busy()==1);
RS=1;
RW=0;
E=0;
P0=y;
_nop_();
_nop_();
_nop_();
_nop_();
E=1;
_nop_();
_nop_();
_nop_();
_nop_();
E=0;
}
void init(void)//初始化
{
d=0;
delay(15);
writeinstruction(0x38);//工作方式:8位总线,2行,5*7点阵
delay(5);
writeinstruction(0x38);//工作方式:8位总线,2行,5*7点阵
delay(5);
writeinstruction(0x38);//工作方式:8位总线,2行,5*7点阵
delay(5);
writeinstruction(0x0f);//显示状态:显示开,有光标,光标闪烁
delay(5);
writeinstruction(0x06);//光标移动:光标右移,字符不移
delay(5);
writeinstruction(0x01);
delay(5);
}
void main(void)
{
unsigned char D1,D2,D3,D4,D5; //定义变量i指向字符串数组元素
unsigned int x; //定义变量,储存检测结果
unsigned char i;
init();
delay(10);
writeaddress(0x02);
i=0;
while(string[i]!=0)
{
wretedata(string[i]);
i++;
}
while(1)
{
x=rand();
D1=x%10;
D2=x%10000%1000%100/10;
D3=x%10000%1000/100;
D4=x%10000/1000;
D5=x/10000;
writeaddress(0x45);
wretedata(digit[D5]);
wretedata(digit[D4]);
wretedata(digit[D3]);
wretedata(digit[D2]);
wretedata(.);
wretedata(digit[D1]);
for(i=0;i<4;i++)
delay(250);
}
}


上一页 1 2 下一页

关键词:51单片机电子时

评论


技术专区

关闭