一般都这样写,这是两组20MS 50K的 要求不高,就这样写了。上图那个0.4US的是另一组功能。我用0.5US试过,直接卡死
void key_service() 大循环扫描串口缓存
{
key_service_lock=0; 串口标志位
switch(buf[1])
{
case 0X79:
if( buf[3]==0x09)
{
memset(buf, 0, 16); //清串口缓存
if(clok<20)
{
clok++;
Energy_TXD(clok, 0x03 ,Energy_current_X[1],Energy_current_X2[1]); //发送屏幕显示
}
}
if( buf[3]==0x10)
{
memset(buf, 0, 16);
if(clok>=1)
{
clok--;
Energy_TXD(clok, 0x03 ,Energy_current_X[1],Energy_current_X2[1]);
}
if( buf[3]==0x12)
{
memset(buf, 0, 16);
if(RF>=1)
{
RF--;
Energy_TXD(RF, 0x03,Energy_current_X[2],Energy_current_X2[2]);
}
}
if( buf[3]==0x13)
{
memset(buf, 0, 16);
if(ul<20)
{
ul++;
Energy_TXD(ul, 0x03,Energy_current_X[3],Energy_current_X2[3]);
}
break;
case 0X78:
break; default:break;
**********************
**********************
}
code unsigned char ul_PWMCounterSATAT[52]={0,1,2,3,4,******************,0};
code unsigned char clok_PWMCounterSATAT[52]={0,1,2,3,4,******************,0};
void InterruptTimer0() interrupt 1 //400US一次 20MS 50K 16位自动重装
{
if (ul_satar|clok_satar) 大循环标志位,两个功能 P2.0 P2.1
{
PWMCounter++;
if(ul_satar) //P2.0
{
if(PWMCounter<=ul_PWMCounterSATAT[ul])
PWM=1;
else PWM=0;
}
if (clok_satar) // P2.1
{
if(PWMCounter<=clok_PWMCounterSATAT[clok])
clok_PWM=0;
else clok_PWM=1;
}
if(PWMCounter>=50)
PWMCounter=0;
}
else
{
PWMCounter=0;
}
}
***********************************************************用0.5US做PWM 程序不动,卡死。
void TM1_Isr() interrupt 3 0.5US
{
RF_PWMCounter++;
if(RF_PWMCounter<=40)
P1_1=1;
else P1_1=0;
if(RF_PWMCounter>=200)
RF_PWMCounter=0;
}
|