CCP1引脚输入1KHZ的方波,我用示波器看过,已经进入CCP1中断,但是中断中读取CCPR1H:CCPR1L,但是读出的总是随机数,给位帮我看看是什么问题,
1.上电,运行,几分钟都是CCPR1H=0xF0,CCPR1L=0xC0,
2.断电,电容放电,上电,运行,几分钟都是CCPR1H=0xCA,CCPR1L=0x56,
3.PIC程序清除,断电,电容放电,上电,运行,几分钟都是CCPR1H=0xDF,CCPR1L=0xFF,
4......
#include <p18f2480.h>
unsigned char cap_high; unsigned char cap_low;
void VectorHigh (void); void HandlerHigh (void);
#pragma code VectorHigh = 0x08 void VectorHigh (void) { _asm goto HandlerHigh //jump to interrupt routine _endasm } #pragma code
#pragma interrupt HandlerHigh void HandlerHigh () { //CCP1中断----------------------------------
if(PIR1bits.CCP1IF) { PIR1bits.CCP1IF = 0; //一定要在中断里面赋值 cap_low=CCPR1L; cap_high=CCPR1H;
CCPR1H=0; CCPR1L=0; }
} #pragma code
void main() { TRISCbits.TRISC2= 1; //设定RC2为输入
CCP1CON = 0x04;//CCP1下降沿捕捉模式
T3CON = 0;
CCPR1H=0; CCPR1L=0;
PIE1bits.CCP1IE=1;//CCP1中断打开 PIR1bits.CCP1IF=0;//CCP1溢出标志 IPR1bits.CCP1IP = 1;//CCP1溢出中断优先级为高中断
T1CON = 0x00;//关闭定时器1
PIE1bits.TMR1IE=1;//定时器1中断打开 PIR1bits.TMR1IF=0;//定时器1溢出标志 IPR1bits.TMR1IP = 1;//定时器1溢出中断优先级为高中断
INTCONbits.GIE = 1;//全局中断打开 INTCONbits.PEIE=1;//外围设备中断打开
for(;;); }
帮帮我吧,崩溃了
|