为什么把代码下到单片机上运行先开始数码管有显示,但不正确,最后八个数码管都灭了。。。。请教各位
#include <reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
uchar code shumashuzi[ ]={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E }; //共阳
uint TH00,TL00;
uchar x=0;
uint b=0;
uchar c=0;
sbit yi=P2^0;
sbit er=P2^1; //38译码器控制
sbit san=P2^2;
#define xianshi P0
uchar shumashuzi_[ ]={0x00};
void delay_ms(uint );
void unit( );
void main ( ){
unsigned long sum=0;
unit ( );
while(1){
if(x==1){
x=0;
sum++;
shumashuzi_[7]=shumashuzi[sum%10];
shumashuzi_[6]=shumashuzi[sum/10%10];
shumashuzi_[5]=shumashuzi[sum/100/10%10];
shumashuzi_[4]=shumashuzi[sum/1000/100/10%10]; //八个数码管每个的显示
shumashuzi_[3]=shumashuzi[sum/10000/1000/100/10%10];
shumashuzi_[2]=shumashuzi[sum/100000/10000/1000/100/10%10];
shumashuzi_[1]=shumashuzi[sum/1000000/100000/10000/1000/100/10%10];
shumashuzi_[0]=shumashuzi[sum/10000000/1000000/100000/10000/1000/100/10%10];
}
}
}
void delay_ms(uint time ){
uint i,j;
for(i=0;i<time;i++)
for(j=0;j<124;j++);
}
void unit ( ){
uint s;
s=65536-1000; //1ms定时
TH00=(uchar)(s>>8);
TL00=(uchar)s;
EA=1;
TMOD=0x01;
TH0=TH00;
TL0=TL00; //启用定时器0
ET0=1;
TR0=1;
}
void zhongduan0( ) interrupt 1 using 1
{
TH0=TH00;
TL0=TL00;
b++;
if(b==1000){
b=0;
x=1;
}
xianshi=0x00;
switch(c){
case 0:yi=0;er=0;san=0;c++;xianshi=~shumashuzi_[c];break;
case 1:yi=1;er=0;san=0;c++;xianshi=~shumashuzi_[c];break;
case 2:yi=0;er=1;san=0;c++;xianshi=~shumashuzi_[c];break;
case 3:yi=1;er=1;san=0;c++;xianshi=~shumashuzi_[c];break; //数码管的动态刷新
case 4:yi=0;er=0;san=1;c++;xianshi=~shumashuzi_[c];break;
case 5:yi=1;er=0;san=1;c++;xianshi=~shumashuzi_[c];break;
case 6:yi=0;er=1;san=1;c++;xianshi=~shumashuzi_[c];break;
case 7:yi=1;er=1;san=1;c=0;xianshi=~shumashuzi_[c];break; //该行控制数码管个位,以上一次递增
}
}
此帖出自
小平头技术问答
嗯嗯,说的是,会注意的
一周热门 更多>