这个程序的功能是单片机点亮第一个流水灯,想做些扩展但是做不下去了,求指出错误所在
一。C语言代码如下:
#include
sbit LED=P0^0;
sbit ENLED=P1^4;
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
main()
{
ENLED=0;
ADDR0=0;ADDR1=1;ADDR2=1;ADDR3=1;
char i=0;
while(1)
{
LED=0;
}
}
在没有加 char i=0;之前程序正常运行,单片机正常运转。加了这句之后错误提示如下:
Build target 'Target 1'
assembling STARTUP.A51...
compiling Text1.c...
TEXT1.C(13): error C141: syntax error near 'char'
TEXT1.C(13): error C202: 'i': undefined identifier
Target not created
二。好,在此又发现了一个问题:
#include <reg52.h>
sbit LED=P0^0;
sbit ENLED=P1^4;
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
main()
{
char i;
ENLED=0;
ADDR0=0;ADDR1=1;ADDR2=1;ADDR3=1;
while(1)
{
for(i=0;;)
LED=0;
}
}
发现没有问题了!这个我在学C语言这么久都没有出现的错误!!!
三。改下定义方式:
#include <reg52.h>
sbit LED=P0^0;
sbit ENLED=P1^4;
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
typedef unsigned char uint8;
main()
{
ENLED=0;
ADDR0=0;ADDR1=1;ADDR2=1;ADDR3=1;
uint8 i;
while(1)
{
for(i=0;;)
LED=0;
}
}
还是同样的错误;;;;