金牌会员
- 积分
- 2513
- 威望
- 279
- 贡献
- 2130
- 兑换币
- 0
- 注册时间
- 2010-12-29
- 在线时间
- 52 小时
|
我用示波器看编码器输出是方波,但是写的单片机程序显示计数器,求高手帮助- #include <hidef.h>
- #include <MC9S12XS128.h>
- #pragma LINK_INFO DERIVATIVE "mc9s12xs128"
- //接口定义: 编码器脉冲中断信号接PT7
- void shijian(void);
- void chaopin(void); //超频程序
- void TIM_init(void);//定时程序
- int chesudu;
-
- void main(void)
- {
-
- chaopin(); //超频函数初始化
- shijian() ;
- TIM_init();//计数器函数初始化
-
- for(;;)
-
- {
-
- //把要处理的函数放在这里
-
-
- }
- }
- void chaopin(void)//64M
- {
- CLKSEL=0X00;
- PLLCTL_PLLON=1;
- SYNR =0xc0 | 0x07;
- REFDV=0xc0 | 0x01;
- POSTDIV=0x00;
- _asm(nop);
- _asm(nop);
- _asm(nop);
- _asm(nop);
- while(!(CRGFLG_LOCK==1));
- CLKSEL_PLLSEL =1;
- }
- void TIM_init(void)
- {
- PACTL=0X50; //Pulse Accumulator Control Register 01010000,捕捉上升沿,Use timer prescaler clock as timer counter clock
- PACNT=0X0000; //Pulse Accumulators Count Registers
-
-
- }
- void shijian(void) { //Periodic Interrupt Timer
- PITCFLMT_PITE=0; //PIT is disabled
- PITCE_PCE0=1; //PIT chanel_0 定时器0 (共四个定时器)enabled
- PITLD0=9999; //1毫秒 PIT Load Register
- PITMTLD0=5; //time-out period = (PITMTLD + 1) * (PITLD + 1) / fBUS
- PITMUX=0x00; //0 The corresponding 16-bit timer counts with micro time base 0
- PITINTE_PINTE0=1; //PIT Interrupt Enable Register
- PITCFLMT_PITE=1; //PIT is enabled
-
-
- }
- //=======速度采集中断函数,已经完全可以采集速度的=========
- #pragma CODE_SEG NON_BANKED
- void interrupt 66 PIT0Interrupt(void)//测速的中断程序
- {
- chesudu=PACNT;//车速度值
-
- PITTF_PTF0=1; //定时器1标志位清零
- PACNT=0X0000;
- }
- #pragma CODE_SEG DEFAULT
-
复制代码 |
|