烧入单片机的代码
#include"reg52.h"
#define J_ON 1
#define J_OFF 0
sbit vibrate = P1^0;
sbit switcher = P1^1;
sbit D0_ON = P1^2;
sbit D0_OFF = P1^3;
void Delay2000ms() //@11.0592MHz
{
unsigned char i, j, k;
//_nop_();
i = 15;
j = 2;
k = 235;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Delay500ms() //@11.0592MHz
{
unsigned char i, j, k;
//_nop_();
i = 4;
j = 129;
k = 119;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void main()
{
int mark=J_OFF;
//²éѯ
while(1)
{
if(D0_ON == 1)//A±»°´Ï£¬¿ªÆô¾¯±¨Ä£Ê½
{
switcher=0;
Delay2000ms();
switcher=1;
mark=J_ON;//É趨¾¯±¨Ä£Ê½±ê¼Ç
}
if(D0_OFF == 1)//B±»°´Ï£¬½â³ý¾¯±¨Ä£Ê½
{
switcher=0;
Delay500ms();
switcher=1;
mark=J_OFF;//É趨½â³ý¾¯±¨Ä£Ê½±ê¼Ç
}
if(mark == J_ON)
{
if(vibrate == 0)
{
switcher=0;
Delay2000ms();
switcher=1;
}
else
{
switcher=1;
}
}
}
}