求助——单片机小程序:用定时器以间隔500MS在6位数码管上依次显示0,1,2,3….C,D,E,F,重复

以下是程序,为什么数码管上显示乱码呢?
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar num=0;
uchar tt=0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void main()
{TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
wela=1;
P0=0xc0;
wela=0;
if(tt==10)
{
tt=0;
if(num>15)
{
num=0;
}
dula=1;
P0=table[num];
num++;
dula=0;
}
}
}
void exter0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
}

第1个回答  2013-02-01
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar num=0;
uchar tt=0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void main()
{TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
EA=1;
ET0=1;
TR0=1;
ET1=1;
TR1=1;
while(1);
}
void exter0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
}
void t1_isr() interrupt 3
{
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
wela=1;
P0=0xc0;
wela=0;
if(tt>=10)
{
tt=0;
if(num>15)
{
num=0;
}
dula=1;
P0=table[num];
num++;
dula=0;
}
}
}
第2个回答  推荐于2016-06-11
程序这样写看看
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar num=0;
uchar tt=0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
wela=1;
P0=0xc0;
wela=0;

while(1)
{
dula=1;
P0=table[num];
dula=0;
}
}
void exter0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(tt==10)
{
tt=0;
num++;
if(num>15)
{
num=0;
}
}
}追问

还是不行啊,数码管全都显示0;还一直在闪

追答

void exter0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(tt==10)
{
tt=0;
num++;
if(num>15) //这里改一下 if(num == 16)
{
num=0;
}
}

本回答被提问者采纳