【发布时间】:2013-11-16 15:11:13
【问题描述】:
我正在使用 PIC16F887 44 引脚演示板。
我正在尝试这样做
- 用户按下开关
- 定时器启动
- 如果在 3 秒内再次按下开关,则打开 LED 0,否则打开 LED 1
由于 Timer0 的预分频器设置为 255,将在 65536 μs 后溢出,我需要计算它溢出的次数并检查它是否达到该数量。 那将是 46 次。
这些是我的代码的相关摘录
movlw B'10000111' ; configure Prescaler on Timer0, max prescale (/256)
movwf OPTION_REG ; configure
MOVLW B'10100000' ; enable Timer 0 and global interrupts
MOVWF INTCON
MainLoop:
BTFSS PORTB,0 ; is the switch pressed (0)
GOTO EndMainLoop ; Lights up LED 0
MOVF TimerCount, w
XORLW .46 ; Check whether XOR TimerCount with 46
BTFSS STATUS,Z ; returns a 0
GOTO MainLoop
GOTO State2 ; Lights up LED 1
TimerCount 在代码的中断部分中递增,如下所示
org 4
ServiceTimer0:
bcf STATUS,RP0 ; Ensure ISR executes in Register Bank 0
bcf STATUS,RP1
BCF INTCON,T0IF ; clear the interrupt flag.
INCF TimerCount,f ; Increment TimerCount
RETFIE ; Return from the interrupt
但是 Timer0 永远不会溢出,并且由于某种原因永远不会调用中断例程。 有谁知道我做错了什么?
【问题讨论】: