求解,这个程序在keil中无法编译。
# define uchar unsigned char
# define uint unsigned int
uchar code dis[]= {x0c0,oxf9}; //共阳数码管显示代码0~1
void delay(void)
{
uchar i,j;
for(i=100;i>0;i--)
for(j=500;j>0;j--);
}
void main()
{ uchar i;
while(1)
{
P1= dis[0]; //显示0
delay();
P1= dis[1]; //显示1
delay();
}
}
提示错误是:SHUMAXIANSHI.C(17): error C202: 'P1': undefined identifier
S HUMAXIANSHI.C(15): error C202: 'P1': undefined identifier
没有定义P1,可能你装的keil有问题
123.c(2): warning C318: can't open file 'regh51.h'
123.C(5): error C202: 'x0c0': undefined identifier
123.C(5): error C202: 'oxf9': undefined identifier
123.C(16): error C202: 'P1': undefined identifier
123.C(18): error C202: 'P1': undefined identifie
Target not created我编译一下,不止一个错误啊,头文件就错了,reg52.h 0xc0, 0xf9 P1无定义r
头文件不对吧
#include<reg51.h>或#include<reg52.h>
估计头文件错误#include<reg51.h>还有你给延时函数i,j变量定义的时候有点小错误!uchar只能定义<128的!
unsigned char 的范围是0到255
char 的范围是-127到127
#include<reg52.h>
# define uchar unsigned char
# define uint unsigned int
//#define P1
uchar code dis[2]= {0xc0,0xf9}; //共阳数码管显示代码0~1
void delay(void)
{
uchar i,j;
for(i=100;i>0;i--)
for(j=500;j>0;j--);
}
void main()
{ uchar i;
while(1)
{
P1=dis[1]; //显示0
delay();
P1=dis[2]; //显示1
delay();
}
}
兄弟,有二处错误
1.头文件写成了regh51.h
2.十六进数写错了x0c0,oxf9.
只要细心就可以了
过来看看
