51单片机写的时间,用了138译码器,感觉时钟没用上,秒钟不对
答案:1 悬赏:20 手机版
解决时间 2021-03-17 05:52
- 提问者网友:孤山下
- 2021-03-16 18:02
51单片机写的时间,用了138译码器,感觉时钟没用上,秒钟不对
最佳答案
- 五星知识达人网友:第幾種人
- 2021-03-16 19:23
是用38译码来扫描LED数码管吗?
我贴一个我以前写的程序吧也是用38译码器作为选通控制的时钟程序,只不过只能显示6位,希望能帮到你 P0接的数码管,P20-P23接的38译码器
#include
sbit P20=P2^0; / /A
sbit P21=P2^1; //B
sbit P22=P2^2; //C
sbit P23=P2^3; //38译码器使能端
#define uint unsigned int //定义uint代替unsigned int
#define uchar unsigned char //定义uchar代替unsigned char
uchar n,h,s,m,h_1,h_0,m_1,m_0,s_1,s_0;
uint i;
unsigned char code duanx[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay();
void display(uchar,uchar,uchar,uchar,uchar,uchar);
void main ()
{
EA=1;
ET1=1;
TMOD=0x10;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
TR1=1;
while(1)
{
if(s==60)
{
s=0;
m++;
if(m==60)
{
m=0;
h++;
if(h==24)
h=0;
}
}
s_1=s/10;
s_0=s%10;
m_1=m/10;
m_0=m%10;
h_1=h/10;
h_0=h%10;
display(h_1,h_0,m_1,m_0,s_1,s_0);
}
}
void zd() interrupt 3
{
n++;
if(n==20)
{
n=0;
s++;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
TR1=1;
}
}
void delay()
{
i=200;
while(i--);
}
void display(uchar h_1,uchar h_0,uchar m_1,uchar m_0,uchar s_1,uchar s_0)
{
P23=0;
P20=0;
P21=0;
P22=0;
P0=duanx[h_1];
delay();
P20=1;
P21=0;
P22=0;
P0=duanx[h_0]|0x80;
delay();
P20=0;
P21=1;
P22=0;
P0=duanx[m_1];
delay();
P20=1;
P21=1;
P22=0;
P0=duanx[m_0]|0x80;
delay();
P20=0;
P21=0;
P22=1;
P0=duanx[s_1];
delay();
P20=1;
P21=0;
P22=1;
P0=duanx[s_0];
delay();
}
我贴一个我以前写的程序吧也是用38译码器作为选通控制的时钟程序,只不过只能显示6位,希望能帮到你 P0接的数码管,P20-P23接的38译码器
#include
sbit P20=P2^0; / /A
sbit P21=P2^1; //B
sbit P22=P2^2; //C
sbit P23=P2^3; //38译码器使能端
#define uint unsigned int //定义uint代替unsigned int
#define uchar unsigned char //定义uchar代替unsigned char
uchar n,h,s,m,h_1,h_0,m_1,m_0,s_1,s_0;
uint i;
unsigned char code duanx[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay();
void display(uchar,uchar,uchar,uchar,uchar,uchar);
void main ()
{
EA=1;
ET1=1;
TMOD=0x10;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
TR1=1;
while(1)
{
if(s==60)
{
s=0;
m++;
if(m==60)
{
m=0;
h++;
if(h==24)
h=0;
}
}
s_1=s/10;
s_0=s%10;
m_1=m/10;
m_0=m%10;
h_1=h/10;
h_0=h%10;
display(h_1,h_0,m_1,m_0,s_1,s_0);
}
}
void zd() interrupt 3
{
n++;
if(n==20)
{
n=0;
s++;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
TR1=1;
}
}
void delay()
{
i=200;
while(i--);
}
void display(uchar h_1,uchar h_0,uchar m_1,uchar m_0,uchar s_1,uchar s_0)
{
P23=0;
P20=0;
P21=0;
P22=0;
P0=duanx[h_1];
delay();
P20=1;
P21=0;
P22=0;
P0=duanx[h_0]|0x80;
delay();
P20=0;
P21=1;
P22=0;
P0=duanx[m_1];
delay();
P20=1;
P21=1;
P22=0;
P0=duanx[m_0]|0x80;
delay();
P20=0;
P21=0;
P22=1;
P0=duanx[s_1];
delay();
P20=1;
P21=0;
P22=1;
P0=duanx[s_0];
delay();
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯