哥哥姐姐们谁有空帮忙看看这个程序啊
#include <intrins.h>
#define uchar unsigned char;
#define uint unsigned int;
uchar i,j,aa,h,num1,num2;
uchar code table1 []={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar code table2 []={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void init();
void main ()
{
init();
P2=table1[num1];
P0=table2[num2];
while(1)
{
num1++;
num2++;
if(aa==20)
aa=0;
P2=table1 [num1];
if(num1==8)
num1=0;
P0=table2 [num2];
if(num2==16)
num2=0;
}
}
void dingshi() interrupt 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
void init()
{
aa=0;
num1=0;
num2=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
功能:8个数码管循环显示0-F 具体的注释我已经帮你注释了 程序最好养成良好的编程习惯
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char;
#define uint unsigned int;
uchar i,j,aa,h,num1,num2;
uchar code table1 []={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar code table2 []={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//共阴极数码管0-F断码
void init();
//函数声明
void main ()
{
init();
//定时器初始化,
P2=table1[num1];
P0=table2[num2];
while(1)
{
num1++;
num2++;
if(aa==20)
aa=0;
P2=table1 [num1];
//P2口用来选择点亮的数码管即位选
if(num1==8)
num1=0;
//8个数码管循环显示
P0=table2 [num2];
//P0口用来显示断码
if(num2==16)
num2=0;
//0-F循环显示
}
}
void dingshi() interrupt 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
//定时中断
}
void init()
{
aa=0;
num1=0;
num2=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
这个程序应该可以啊?看什么?
不对啊
下次记得把问题 描述清楚些。
你查一下define 的用法, 习惯上,不需要加分号。 然后根据你后面的代码段, 加上分号后就会报错了......
- #define uchar unsigned char;
- #define uint unsigned int;
定时器中断进入错误吧interrupt 1而不是 interrupt 0
少了几个括号;
如下:
if(aa==20)
{ aa=0;
num1++;
num2++;
P2=table1 [num1];
if(num1==8)
num1=0;
P0=table2 [num2];
if(num2==16)
num2=0;}