按键消斗程序;菜鸟第二波
时间:10-02
整理:3721RD
点击:
#include <reg51.h>
#define LED1_ON() P1^2 = 0
#define LED1_OFF() P1^2 = 1
sbit KEY1 = P3^2;
void delay100us(unsigned int uiDly)
{
unsigned char i; //延时100us
do{
i=46;
do{
} while(--i!=0);
} while(--uiDly!=0);
}
void main (void)
{
while(1){
KEY1=1;//等待按键按下
while(1) {
while(KEY1==1) { } //循环检测?
delay100us(100);
if(KEY1!=1) {
break;
}
}
LED1_ON();//点亮LED
/*
* 等待释放按键
*/
while(1){
while(KEY1==0) { } //检测是否释放
delay100us(100);
if(KEY1!=0){
break;
}
}
LED1_OFF();//熄灭LED
}
}
错误是:00.c(1): warning C500: LICENSE ERROR (R207: REGISTRY READ ERROR)
00.c(74): error C141: syntax error near '='
00.c(52): error C141: syntax error near '='
是哪里问题呢
#define LED1_ON() P1^2 = 0
#define LED1_OFF() P1^2 = 1
sbit KEY1 = P3^2;
void delay100us(unsigned int uiDly)
{
unsigned char i; //延时100us
do{
i=46;
do{
} while(--i!=0);
} while(--uiDly!=0);
}
void main (void)
{
while(1){
KEY1=1;//等待按键按下
while(1) {
while(KEY1==1) { } //循环检测?
delay100us(100);
if(KEY1!=1) {
break;
}
}
LED1_ON();//点亮LED
/*
* 等待释放按键
*/
while(1){
while(KEY1==0) { } //检测是否释放
delay100us(100);
if(KEY1!=0){
break;
}
}
LED1_OFF();//熄灭LED
}
}
错误是:00.c(1): warning C500: LICENSE ERROR (R207: REGISTRY READ ERROR)
00.c(74): error C141: syntax error near '='
00.c(52): error C141: syntax error near '='
是哪里问题呢
这句while(KEY==1){}改成while(KEY==1); 或者在在括号里加个 ; 也行
问题已解决,谢谢
学习一下!