单片机:6个数码管动态显示
鬼影
消除后,就变成这样
方法一:字形码法
void T0ser() interrupt 1
{
TH0 = -5000>>8;
TL0 = -5000;
if(++p>5)
{
p=0;
}
Send(0);
CS(p);
Send(zxm);
}
这个地方:
Send(0);//就是这个,在选择第x个管显示时,先让它黑屏
CS(p);
Send(zxm);
总的代码
/****
*Time: 20220429
*Author:LaoGu
*purpose:数码管动态显示数字:消隐方式一 字形码黑屏
****/
#include "reg51.h"
sbit SH = P1^0;
sbit DS = P1^1;
sbit ST = P1^2;
sbit a = P1^3;
sbit b = P1^4;
sbit c = P1^5;
char zxm[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x3c,0x07,0x7f,0x37};
char p;
void Send(char n)
{
char i;
for(i=0;i<8;i++)
{
if(n&0x80)
{
DS = 1;
}
else
DS = 0;
SH = 0;
SH = 1;
n<<=1;
}
ST = 0;
ST = 1;
}
void CS(char n)
{
c = n/4;
b = n%4/2;
a = n%2;
}
void InitT0()
{
TMOD = 0x01;
IE = 0x82;
TH0 = -5000>>8;
TL0 = -5000;
TR0 = 1;
}
void T0ser() interrupt 1
{
TH0 = -5000>>8;
TL0 = -5000;
if(++p>5)
{
p=0;
}
Send(0);
CS(p);
Send(zxm);
}
void main()
{
InitT0();
while(1)
{
}
}
方法二:片选法
将上面那部分内容,改为下面的就行,其他不变
CS(6); //CS(7)也可以
Send(zxm);
CS(p);
总的:
void T0ser() interrupt 1
{
TH0 = -5000>>8;
TL0 = -5000;
if(++p>5)
{
p=0;
}
CS(6); //CS(7)也可以
Send(zxm);
CS(p);
}
超棒 {:5_108:}
页:
[1]