需要一个程序,用51单片机控制led每一秒钟闪烁一次,并在1602显示闪烁次数,不要汇编语言,速求
3个回答
展开全部
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED=P1^3;
sbit RS=P1^0;
sbit RW=P1^1;
sbit E=P2^5;
sbit dula=P2^6;
sbit wela=P2^7;
uchar bai,ge;
uchar code table[]="0123456789";
uchar sh,ss,second,sg;
uchar min;
uchar h,tt;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
write_com(uchar com)
{
RS=0;
RW=0;
P0=com;
delay(5);
E=1;
delay(5);
E=0;
delay(5);
}
write_dat(uchar dat)
{
RS=1;
RW=0;
P0=dat;
delay(5);
E=1;
delay(5);
E=0;
delay(5);
}
void init()
{
dula=0;
wela=0;
tt=0;
h=0;
min=0;
write_com(0x38) ;
write_com(0x0f) ;
write_com(0x06);
write_com(0x80+2);
}
void main()
{
init();
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
IT0=0;
ET0=1;
TR0=1;
LED=1;
while(1) {
if(tt==20) {
tt=0;
second++;
LED=~LED;
if(second==60) second=0;
ss=second/10;
sg=second%10;
write_dat(0x3a); delay(20);
write_com(0x80+5); delay(20); write_dat(0x3a); delay(20);
write_com(0x80+6); delay(20); write_dat(table[ss]); delay(20);
write_com(0x80+7); delay(20); write_dat(table[sg]); delay(20);
}
}
}void t0()interrupt 1 using 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
}
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED=P1^3;
sbit RS=P1^0;
sbit RW=P1^1;
sbit E=P2^5;
sbit dula=P2^6;
sbit wela=P2^7;
uchar bai,ge;
uchar code table[]="0123456789";
uchar sh,ss,second,sg;
uchar min;
uchar h,tt;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
write_com(uchar com)
{
RS=0;
RW=0;
P0=com;
delay(5);
E=1;
delay(5);
E=0;
delay(5);
}
write_dat(uchar dat)
{
RS=1;
RW=0;
P0=dat;
delay(5);
E=1;
delay(5);
E=0;
delay(5);
}
void init()
{
dula=0;
wela=0;
tt=0;
h=0;
min=0;
write_com(0x38) ;
write_com(0x0f) ;
write_com(0x06);
write_com(0x80+2);
}
void main()
{
init();
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
IT0=0;
ET0=1;
TR0=1;
LED=1;
while(1) {
if(tt==20) {
tt=0;
second++;
LED=~LED;
if(second==60) second=0;
ss=second/10;
sg=second%10;
write_dat(0x3a); delay(20);
write_com(0x80+5); delay(20); write_dat(0x3a); delay(20);
write_com(0x80+6); delay(20); write_dat(table[ss]); delay(20);
write_com(0x80+7); delay(20); write_dat(table[sg]); delay(20);
}
}
}void t0()interrupt 1 using 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询