/*==================================================================================
最简单数字点火系统,630的11脚(ra2)检测触发脉冲计算转速(判断触发脉冲高低电平持续时间),
10脚rc0触发可控硅点火;
发动机旋转一圈出现一个触发脉冲,一个触发脉冲包括一个高电平和一个低电平
=================================================================================*/
#include <pic.h>
#include <pic16630.h>
__config( wdtdis & pwrten & intoscio & mclrdis);
#define uchar unsigned char
#define uint unsigned int
#define in1 ra2 //11脚触发信号
#define out rc0 //10脚输出
//#define in2 rc1 //9脚触发
const uchar cs@0x3ff;
uchar tmp1;
uchar tmp2;
uchar tmp3;
uchar tlow; //触发脉冲高电平
uchar thigh; //触发脉冲低电平
uchar jg;
uchar zhouqi1;
uchar jg1;
uchar cishu;
uchar lable;
bit stop;
bit run;
bit speed1;//发动机转速低于1200转/分钟标志
bit speed2; //发动机转速低于于2400转/分钟标志
bit speed3;//高于2400
void interrupt isr (void)
{
if(t0if) //time0 50us中断0.05ms
{
t0if=0;
tmr0=196;
if(!in2)//发动机开始旋转
{
if((tlow>=2 && tlow>=4)&&(thigh>=20 && thigh<=50))//1200转以下
{
speed1=1;
}
else if((tlow>=1 && tlow>=3)&&(thigh>=50 && thigh<=80))//2400转以下
{
speed2=1;
}
else
{
speed3=1;
}
}
/* if(run)
{
out=1;
tmp1++;
if(tmp1==20)
{
tmp1=0;
tmp2++;
if(tmp2==30)
{
tmp2=0;
out=0;
run=0;
}
}
}
}*/
if(tmr1if) //10脚输出脉冲宽度
{
tmr1if=0;
tmr1h=0xcf;
tmr1l=0x2b; //timer1 0.1s定时100ms
if(run)
{
out=1;
tmp1++;
if(tmp1==2)
{
tmp1=0;
out=0;
run=0;
}
}
} */
}
void main(void)
{
osccal=cs;
portc=0x20;
porta=0x00;
cmcon=0x07;
trisa=0x3f;
trisc=0x0a;
wpua=0x35;
ioca=0x04;
option=0x0e;
tmr0=196;
intcon=0xe0; //使能timer0;
t0if=0;
t0ie=1; //使能timer0;
if(in2==1)
{stop=1;}
tmr1h=0xcf;
tmr1l=0x2b; //time1 0.025s*8预分频定时
//t1con=0x30; //关闭timer1 设置1:8预分频
pie1=0x01; //使能time1定时中断
tmr1if=0;
tmr1on=1; //启动timer1
while(1)
{
if(!in1)
{
if(speed1 && !speed2)//判断转速决定点火时刻
run=1;
if
.......................
}
else {run=0;}
}
}
不知这样编写对不。请高手指点