网上看的程序,编译不通过。你看下不知那里有问题!
/****************************************************************
STC15L104W触摸灯
***************************************************************/
#include <STC15F2K60S2.H>
#include "intrins.h"
typedef unsigned char uchar;
typedef unsigned intuint;
//#define P3Set_IO(x) P3M1&=~(1<<x);P3M0&=~(1<<x)
//#define P3Set_PP(x) P3M1&=~(1<<x);P3M0|=1<<x
//#define P3Set_IN(x) P3M1|=1<<x;P3M0&=~(1<<x)
//#define P3Set_OD(x) P3M1|=1<<x;P3M0|=1<<x
sbit KEY =P3^2;
sbit PWM_Out =P3^5;
//#define TRUN_1T
//#define SYSTEM_CLOOK 5.5296f
#define Up 1
#define Down 0
sbit KEY_Flag = Up;
#define ON 1
#define OFF 0
#define bLightSwitch TR0
ucharucHighDuty = 150;
#define Sycle 200
void Delay(ucharxms)
{
unsigned char i;
do{
while(i--);
}while(xms--);
}
void T0_ISR() interrupt 1
{
staticuchar Count;
Count++;
if(Count>ucHighDuty&&PWM_Out==1)
PWM_Out=~PWM_Out;
else if(Count>Sycle)
{
Count=0;
PWM_Out=~PWM_Out;
}
}
void INT0_ISR() interrupt 0
{
bKEY_Flag = Down;
}
void main(void)
{
bitbFlag,jieneng = 1;
CLK_DIV|=0xC1;//P3.4输出RC时钟/4 系统时钟=RC二分频,二分频可以省0.5mA.
// P3M0=0x00;
P3M1|=0x0F; //P3.0-4 设置为高阻
// T0=lnit();
AUXR|=0x80;
TH0=0xFF;
TL0=0x9C;
IE|=0x83; //开启EA T0 INT0
//IT0=1; // 1 下降沿中断 0 边沿中断
while(1)
{
if(bKEY_Flag==Down)
{
Delay(255);
if(KEY==Up)
{
bLightSwitch = !bLightSwitch;
jieneng = !jieneng;
if(bLightSwitch == OFF)
{
PWM_Out = 1;
TH0 = 0xFF;
TL0 = 0x9C;
}
while(KEY==Down);
}
else if(bLightSwitch == ON)
{
do{
if(bFlag == 1&&ucHighDuty<Sycle)
ucHighDuty+=1;
else if(ucHighDuty>0)
ucHighDuty-=1;
Delay(10);
}
while(KEY==Down);
bFlag=!bFlag;
}
bKEY_Flag=Up;
}
if(jieneng==1)
{
PCON|=0x01;
Delay(255);
while(KEY==Down)
{
TH0=0xF4;
TL0=0x48;
}
}
}
}
|