用的是AT89C51单片机,编程软件之前试过uvision4,错误特别多,然后又尝试了uvision2,结果下载完显示是uvision3,我也不知道怎么回事,出现的错误比uvision4少一些,我需要生成hex文件用在proteus里,程序是在网上搜的,请各位指导,拜托了。
程序如下:
#define uc unsigned char
#define ut unsigned int
#define FOSC 18432000L
#define T1MS 1536//1ms定时器
#define unsigned int p3
sbit relay=p3^7;//继电器输出
sbit touch=p1^0;//触摸检测
uc sec,temp;
ut milsec;
void delay(uc i)
{
while(i) i--;
}
void InitUart(void);
void InintTimer0(void);
void InitADC(void);
uc GetADCResult(uc ch);
void main()
{
bit chanal;
ut save_times,light,voice;
AUXR=0x00;
InintTimer0();
InitADC();
sec=0;
relay=0;
while(1)
{
if(chanal)
{
light+=GetADCResult(2);//光照强度检测
save_times++;
}
else
{
voice+=GetADCResult(6);//声音分贝检测
}
chanal=~chanal;
if(save_times==256) //消抖
{
save_times=0;
light/=256;
voice/=256;
}
if((light>200)||(voice>50)||(touch==0))relay=1;
if(sec>=20)relay=0; //延时输出20秒后灭灯
delay(200);
delay(200);
}
}
void InitUart(void)
{
SCON=0x5a; //8个数据位,无校验
TMOD=0x20; //8位自动装载
TH1=TL1=-(FOSC/12/32/BAUD);//设置波特率
TR1=1; //使能定时1
}
void InintTimer0(void)
{
TMOD|=0x01;
TL0=T1MS;
TH0=T1MS>>8;
TR0=1;
ET0=1;
EA=1;
}
void InitADC(void)
{
P1=P1M0=0xff;
P1M1=0x00;
ADC_DATA=0;
ADC_CONTR=ADC_POWER|ADC_SPEEDLL;
delay(2);
}
uc GetADCResult(uc ch)
{
ADC_CONTR=ADC_POWER|ADC_SPEEDLL|ch|ADC_START;
_nop_();
_nop_();
_nop_();
_nop_();
while(!(ADC_CONTR & ADC_FLAG));//Wait complete flag
ADC_CONTR &=~ADC_FLAG;
return ADC_DATA;
}
void tm0_isr() interrupt 1 using 1
{
TL0=T1MS;
TH0=T1MS>>8;
milsec++;
if(milsec==1000)
{
if(sec<20)sec++;
}
}
end if
end
错误如下:
Build target 'Target 1'
assembling bulubulu.ASM...
F:\bulubulu.ASM(9): error A9: SYNTAX ERROR
F:\bulubulu.ASM(10): error A9: SYNTAX ERROR
F:\bulubulu.ASM(12): error A9: SYNTAX ERROR
F:\bulubulu.ASM(13): error A9: SYNTAX ERROR
F:\bulubulu.ASM(14): error A9: SYNTAX ERROR
F:\bulubulu.ASM(15): error A9: SYNTAX ERROR
F:\bulubulu.ASM(16): error A9: SYNTAX ERROR
F:\bulubulu.ASM(17): error A9: SYNTAX ERROR
F:\bulubulu.ASM(18): error A9: SYNTAX ERROR
F:\bulubulu.ASM(19): error A9: SYNTAX ERROR
F:\bulubulu.ASM(21): error A9: SYNTAX ERROR
F:\bulubulu.ASM(22): error A9: SYNTAX ERROR
F:\bulubulu.ASM(23): error A9: SYNTAX ERROR
F:\bulubulu.ASM(24): error A9: SYNTAX ERROR
F:\bulubulu.ASM(25): error A9: SYNTAX ERROR
F:\bulubulu.ASM(26): error A9: SYNTAX ERROR
F:\bulubulu.ASM(27): error A9: SYNTAX ERROR
F:\bulubulu.ASM(28): error A9: SYNTAX ERROR
F:\bulubulu.ASM(29): error A9: SYNTAX ERROR
F:\bulubulu.ASM(30): error A9: SYNTAX ERROR
F:\bulubulu.ASM(31): error A9: SYNTAX ERROR
F:\bulubulu.ASM(32): error A21: EXPRESSION WITH FORWARD REFERENCE NOT PERMITTED
F:\bulubulu.ASM(32): error A45: UNDEFINED SYMBOL (PASS-2)
F:\bulubulu.ASM(38): error A9: SYNTAX ERROR
F:\bulubulu.ASM(39): error A9: SYNTAX ERROR
F:\bulubulu.ASM(40): error A9: SYNTAX ERROR
F:\bulubulu.ASM(41): error A9: SYNTAX ERROR
F:\bulubulu.ASM(42): error A21: EXPRESSION WITH FORWARD REFERENCE NOT PERMITTED
F:\bulubulu.ASM(42): error A45: UNDEFINED SYMBOL (PASS-2)
F:\bulubulu.ASM(104): error A56: UNBALANCED IF-ENDIF CONTROLS
F:\bulubulu.ASM(104): warning A41: MISSING 'END' STATEMENT
Target not created
|