本帖最后由 colin_lyq 于 2014-7-27 13:41 编辑
初学者疑问,为什么不能用T0中断切换LED点灯数呢!
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar T0_namber;
uint num;
uchar code namber[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void init(void);
//--------------
void main()
{
init();
while(1)
{
P0=namber[num];
}
}
///////////////////
void init(void)
{
TMOD=0x01;
TH0=(65536-15536)/256;
TL0=(65536-15536)%256;
EA=1;
ET0=1;
TR0=1;
}
////////////////////
void T0_
time()interrupt 1
{
TH0=(65536-15536)/256;
TL0=(65536-15536)%256;
T0_namber++;
if(T0_namber==50)
{
T0_namber=0;
num++;
}
}
按上面的提示做了些修改,但是还不行!各位再看一下,谢了!
#include<reg51.h>#define uchar unsigned char
#define uint unsigned int
uchar code dx516[3] _at_ 0x003b;//仿真语句
sbit led=P0^0;
uchar T0_number,num;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void init();
//--------------
void main()
{
init();
while(1)
{
if(num==9)
{
num=0;
}
P0=table[num];
}
}
///////////////////
void init()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
T0_number=0;//初始0
num=0;//初始0
}
////////////////////
void T0_time()interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
T0_number++;
if(T0_number==20)
{
T0_number=0;
num++;
led=~led;//1S闪烁
}
}
一周热门 更多>