【发布时间】:2017-10-12 15:01:00
【问题描述】:
我遇到了 timer1 外部时钟中断的问题。
基本上我使用的是内部 4mhz 时钟和一个连接到 T1OSI/T1OSO 引脚的 32khz 晶体发生器。
问题是我无法从外部时钟产生中断。下面是我正在尝试运行的代码:
#define _XTAL_FREQ 4000000
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
void interrupt isr(void){
if(TMR1IF){
RA0=!RA0;
}
}
void main(void) {
CMCON = 0x07; // comparators off
TRISA = 0x00;
RA0=1;
__delay_ms(1000);
RA0=0;
TMR1CS=1;
T1CONbits.nT1SYNC = 0
TMR1IF = 0; // Clear the timer1 interrupt flag
TMR1H = 224;
TMR1L = 0;
TMR1IE = 1;
TMR1ON = 1;
T1CKPS1 = 1;
INTCON = 0b11000000;
while(1);
}
如果使用内部时钟,则此代码有效,但如果配置为使用外部时钟,则会失败。
也许我做错了什么?谢谢你的任何想法。
【问题讨论】:
-
1) 请提及 PIC18 PIC12 等微控制器系列。 2) 我没有看到任何为时钟初始化的引脚。 PIC18F 系列要求引脚为模拟。
-
你好,它是 PIC16(更具体地说是 PIC16F628)(在主题中写)
-
嗨@Seitan 很抱歉我错过了那部分!数据表第 49 页建议了振荡器要求。振荡器在电路中需要特别注意。你能分享一下电容值和晶体零件号吗?
-
晶体谐振器是标准时钟晶体:mouser.com/ds/2/3/ab38t-ab26t-180532.pdf 我尝试了几种电容选项:微芯片手册中所述的 15pf。 22pf,如许多电路所示。结果是一样的——不产生中断。
标签: microchip