浙江万里学院本科毕业论文 27
进入中断屏蔽中断总开关GIE外部中断标志INF=1 NY清TMR2IF中断标志位清INF中断标志位中断保护YAD通道选择AD采样并开始转换过流保护程序处理外部中断标志INF=1检测位置传感器的相位信息三次YNTMR2定时器中断初始化相位有变化?N输出相位驱动信号NAD中断标志位=1?Y保存AD转换结果,输出标志位=1开启总中断开关GIE退出中断计数器=40?Y刹车信号采集标志,计数器+1N计数器=80Y手柄信号采集标志;计数器+1N计数器>=120Y电压信号采集标志;计数器清零计数器+1N开启总中断开关GIE退出中断 图4-2 无刷直流控制器中断流程图
中断处理程序
void interrupt ISR(void) { uchar j;
浙江万里学院本科毕业论文 28 if(INTF==1)//外部INT0 { PEIE=0;
INTF=0; //清除中断标志位 if(counter_temp<1024) {;} else {
int0_flag=1;
counter=counter_temp/256; //counter=counter_temp; counter_temp=0; counter_temp1=0; count_num=0; }
// LED9=!LED9; PEIE=1; }
else if(TMR1IF==1) //定时器中断 TIMER1 {
//time1_flag=1;
TMR1IF=0;//清除中断标志位 TMR1L=T1L;
TMR1H=T1H; //重新设置定时器时间 counter_temp++; counter_temp1++; // LED10=!LED10; } else {;}
浙江万里学院本科毕业论文 29 }
显示程序
void plot1bar(char value, char max_value) {
unsigned int plot_value; int i;
char hibyte_value, lobyte_value; lobyte_value = 0; hibyte_value = 0;
plot_value = (int)(value*15/max_value);
// Computes how many points to plot. Since
// Initial values.
we are using 2 vertical
// 8 bit blocks, we can have 1-16
points for a bar graph.
if((plot_value>0)&&(plot_value<=7)) { }
else if((plot_value>7)&&(plot_value<=15)) // Plots bar graph which are above 8 points up to
for(i=plot_value;i>=0;i--) { }
lobyte_value=0x00;
hibyte_value=hibyte_value>>1; hibyte_value=hibyte_value+0x80;
// Plots bar graph which are below 8 points.
15 points.
{
plot_value = plot_value - 7; for(i=plot_value;i>=0;i--) {
lobyte_value=lobyte_value>>1; lobyte_value=lobyte_value+0x80;
浙江万里学院本科毕业论文 30 }
hibyte_value = 0xFF;
}
else if(plot_value>15) {
lobyte_value = 0xFF;
the maximum of 15. hibyte_value = 0xFF;
} else {
lobyte_value = 0x00;
of pixel on the bargraph). hibyte_value = 0x80;
}
writedata(lobyte_value);
higher 8 bits (which is the low byte)
writedata(hibyte_value);
(which is the high byte) of the graph. }
PWM波控制电机程序
aa++;if(aa>60000){aa=0;cc++;if(cc>2000)cc=0;} bb++;
if(bb>2000)bb=0; if(bb // If beyond 15 points than cap the points at // If below 0 then cap it to 0(which is a unit // A 16 point plotting. Plots the // and then the lower 8 bits
相关推荐: