#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
}
void DelayMS(uint x)
{
uchar i
while(x--)
{
for(i=200i>0i--)
}
}
void main()
{
uchar i,k=0x80
while(1)
{
for(i=8i>0i--)
{
P2=0xff
k=_crol_(k,1)
P0=DSY_CODE[8-i]
P2=k
DelayMS(3)
}
}
}
不清楚你的电路构成如何,因此先按下面的假设执行段码及位码的输出;其中,延时值可根据实验效果予以调整;
设 P0 为输出七段码(共阳极数据);
四位数码管有4个阳极,设位码分别与P2.4--P2.7对应,并且=1时表示可点亮数码管;
sbit wma1=b2^4//对应左起第1个数码管的阳极
sbit wma2=b2^5//对应左起第2个数码管的阳极
sbit wma3=b2^6
sbit wma4=b2^7
void main()
{
wma1=0 wma2=0 wma3=0 wma4=0
while(1)
{
P0=table[0] wma1=1 delay(10) wma1=0
P0=table[1] wma1=2 delay(10) wma2=0 P0=table[2] wma1=3 delay(10) wma3=0 P0=table[3] wma1=4 delay(10) wma4=0 P0=table[4] wma1=1 delay(10) wma1=0 P0=table[5] wma1=2 delay(10) wma2=0 P0=table[6] wma1=3 delay(10) wma3=0 P0=table[7] wma1=4 delay(10) wma4=0
}
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num,count,ge,shi
void delayxms(uint)
void display(uchar,uchar)
uchar code table[]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x98}
void main()
{
TMOD=0x01
TH0=(65536-50000)/256
TL0=(65536-50000)%256
EA=1
ET0=1
TR0=1
while(1)
{
display(shi,ge)
}
}
void T0_time() interrupt 1
{
TH0=(65536-45872)/256
TL0=(65536-45872)%256
count++
if(count==5)
{
count=0
num++
if(num==100)
num=0
shi=num/10
ge=num%10
}
}
void delayxms(uint z)
{
uint x,y
for(x=zx>0x--)
for(y=110y>0y--)
}
void display(uchar shi,uchar ge)
{
P2=0x02
P0=table[ge]
delayxms(20)
P2=0x01
P0=table[shi]
delayxms(20)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)