程序完成功用:adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=ef3913f3f2527a90&k=%B0%B4%BC%FC&k0=%B0%B4%BC%FC&kdi0=0&luki=1&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=907a52f2f31339ef&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2108%2Ehtml&urlid=0″ id=”1_nwl” mpid=”1″ target=”_blank”>按键调光,按键带蜂鸣器响声。
#define KEY RC5
#define LED RC2
int b;
void key(unsigned *p)
{
static bit valid=0;
static bit finish=0;
if(valid==0)
{
if(KEY==0)
{
if(finish==0)
{
finish=1;
RC0=1;//蜂鸣器接这儿
b=50;
while(b–);
RC0=0;
if(*p>251)
{
*p=0x01;
}
else
{
*p+=50;
}
}
}
else
{
valid=0;
finish=0;
}
}
else
{
if(KEY==0)valid=1;
}
}
void tiaoguang(unsigned PWM)
{
unsigned char PwmH;
unsigned char PwmL;
unsigned char i;
for(i=0;i<20;i++)
{
PwmH=PWM;
PwmL=255-PWM;
while(PwmH–);
LED=0;
while(PwmL–);
void main()
{
unsigned char PWM=0;
RC2=0;
TRISC=0b00100000;
while(1)
{
key(&PWM);
tiaoguang(PWM);
程序思路:设定PWM变量,每按一次,PWM添加50个单位,加到到250,归零。