80c552做计数编码器信号的程序,请大家指点看看是不是有问题呀?谢谢
用外部中断1,记录编码器A象信号,用T1记录B象脉冲信号,同时把B项信号,接到p1.0,用来测试外部中断发生脉冲触发时候,B项状态,判断转向。定时设置0.1s进行采样计数
#include <REG552.H>
sbit P1_0 = P1^0;
sbit P1_1 = P1^1;
sbit P1_2 = P1^2;
sbit P1_3 = P1^3;
/*------------------------------------------------------------------------------
main() : Runs a while loop as the PWM automatically loops
------------------------------------------------------------------------------*/
unsigned char Counter;
unsigned int Pluse;
void main( void )
{
Counter = 2;
P1_0 = 0x01;
P1_2 = 0X01;
P1_3 =0X01;
PWMP = 0x0A; //Set the repition frequenct to 2.14kHz
PWM1 = 0x00; //Set the Duty cycle to 100%
EA=1; //总中断允许
IT1=1; //外部中断1为边沿触发方式
EX1=1; //外部中断1允许
TMOD=0x51;
TH0 = 0x3C;
TL0 = 0XB0;
TH1 = 0X00;
TL1 = 0X00;
TR0 = 1;
TR1 = 1;
while (1);
}
void Timer(void) interrupt 1 {
Counter --;
if (Counter==0)
{
P1_0 = 0X00;
TH1 = 0X00;
TL1 = 0X00;
}
TH0 = 0x3C;
TL0 = 0XB0;
TR1 = 1;
TR0 = 1;
}
void encoder(void) interrupt 2 { //外部中断1
if (INT1)
{ if (P1_1)
{
P1_2 = 0X00;
P1_3 =0X00;
EX1=0;
}
else
{
P1_2 = 0X00;
P1_3 =0X00;
EX1=0;
}
P1_0 = 0X00;
}
}
请问有问题么?
发表时间:2006年7月12日22:35:46