单片机:stc89c52rc
实验版:tx-1c
数码管部分代码:
for(i=0;i<10;i++){
for(j=0;j<w;j++){
P0=mybit[5-j];
wela=1;
wela=0;
P0=num[a[j]];
dula=1;
dula=0;
delay(3);
}
}
问题:数码管总是出现右边一位的影子。
全部代码:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define NUMBER 199
sbit dula=P2^6;
sbit wela=P2^7;
sbit f=P2^3;
void delay(int t){
int i,j;
for(i=0;i<t;i++)
for(j=0;j<100;j++);
}
void number(){
int i,j,a[6],w;
uchar code num[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71},
mybit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
static long int n=NUMBER;
long int m;
m=n;
n--;
if(n<0){
n=NUMBER;
wela=1;
P0=0;
wela=0;
dula=1;
P0=0xff;
dula=0;
P1=0;
f=0;
delay(1500);
f=1;
}
for(w=0;m!=0;w++){
a[w]=m%10;
m/=10;
}
for(i=0;i<10;i++){
for(j=0;j<w;j++){
P0=mybit[5-j];
wela=1;
wela=0;
P0=num[a[j]];
dula=1;
dula=0;
delay(3);
}
}
}
void led(){
static int i=0,flag=1;
static uchar light,light1=0xfe,light2=0x7f;
light=light1&light2;
P1=light;
light1=_crol_(light1,flag);
light2=_crol_(light2,-flag);
i++;
flag=(i%3==0)?-flag:flag;
}
void main(){
while(1){
led();
number();
}
} |