我在EasyArm2131上做了一个测速程序(如下),在p0.22和p0.28未接任何信号的情况下(只接一小段导线),显示屏上居然有转速显示。请问是什么原因,谢谢!
/********************速度测量********************/
//volatile uint32 engine=0; //volatile uint32 cylinder=0; //volatile uint32 zayu=0; int engine=0; int cylinder=0; int zayu=0;
void __irq IRQ_timer0() {
if((T0IR&(0x01<<4))==(0x01<<4)) //发动机脉冲计数pat0.0,p0.22 { T0IR=0x01<<4; engine++; //VICVectAddr=0x00; } if((T0IR&(0x01<<5))==(0x01<<5)) //滚筒速度脉冲计数pat0.1,p0.27 { T0IR=0x01<<5; cylinder++; //VICVectAddr=0x00; } if((T0IR&(0x01<<6))==(0x01<<6)) //xingzou速度脉冲计数 pat0.2,p0.28 { T0IR=0x01<<6; zayu++; //VICVectAddr=0x00; }
VICVectAddr=0x00; }
/********************压力测量,速度控制********************/
void __irq IRQ_timer1() { uint32 V_engine,V_cylinder,V_zayu; char str1[4],str2[4],str3[4];
V_engine=engine*15;
V_cylinder=cylinder*15;
V_zayu=zayu*15;
sprintf(str1, "%4d",V_engine);//速度显示 lcd_COM(0x85); lcd_seri(str1); sprintf(str2, "%4d",V_cylinder); lcd_COM(0x94); lcd_seri(str2); sprintf(str3, "%4d",V_zayu); lcd_COM(0x8d); lcd_seri(str3); engine=0; cylinder=0; zayu=0; T1IR=0x01; VICVectAddr=0x00; }
/******************************主程序*********************************************** ** ** *************************************************************************************/
int main (void) {
IO0CLR=rst; DelayNS(100); IO0SET=rst; DelayNS(100); PINSEL0=(PINSEL0&(~0x0f))|(0x05); PINSEL0=PINSEL0&(~0x0f<<12); PINSEL2=PINSEL2&(~(0x08)); //设置lcd数据线p1.16-1.23
IO1DIR=lcds8; //设置数据线输出方向 IO0DIR=IO0DIR|(0x0f<<12);
PINSEL1=(PINSEL1&0xfffff000)|(0xfd5);/*设置键盘喂入量捕获定时期1*/ PINSEL1=(PINSEL1&(~(0x03<<12)))|(0x01<<13);/*设置p0.22位发动机速度捕获0*/ PINSEL1=(PINSEL1&(~(0x03<<22)))|(0x01<<23);/*设置p0.27滚筒速度捕获1*/ PINSEL1=(PINSEL1&(~(0x03<<24)))|(0x01<<25);/*设置p0.28.,行走于速度捕获2,*/ //PINSEL1=(PINSEL1&0xfff7ffff)|(0x08<<18);/*设置p0.25压力AD转换4*/ PINSEL1=(PINSEL1&(~(0x03<<28)))|(0x01<<28); //设置p0.30压力AD转换4 IO1SET=lcds8;/*置位p0.4~p0.12*/ IO1SET=lcds8; short_delay (1);/*延时*/ lcd_Imim();/*初始化*/ lcd_clr(); Hanz1(); Hanz2(); Hanz3();
T0PR = 19; T1PR = 1; T0CCR =(1<<0)| // 设置timer0 三路捕获,上升、下降沿,允许产生中断 (1<<1)| (1<<2)| (1<<3)| (1<<4)| (1<<5)| (1<<6)| (1<<7)| (1<<8); T1MCR=(1<<0)| (1<<1); //timer1,1s 定时允许中断,算速度 T1MR0=Fpclk; T0TC = 0; T0TCR = 0x03; T0TCR = 0x01; // 启动定时器 T1TC = 0; T1TCR = 0x03; T1TCR = 0x01; IRQEnable(); // 使能IRQ中断 // 设置Timer1中断 VICIntSelect = 0x00000000; // 设置所有的通道为IRQ中断
VICVectCntl1 = 0x20 | 5; // timer1分配到IRQ slot1, VICVectAddr1 = (uint32)IRQ_timer1; VICVectCntl0 = 0x20 | 4; // timer0分配到IRQ slot2, VICVectAddr0 = (uint32)IRQ_timer0; VICIntEnable = (1 << 4)| (1 << 5); while (1); return 0; } /********************************************************************************************************* ** End Of File ********************************************************************************************************/
|