Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4746

12F683 Timer1 Code

$
0
0
I am ashamed to show this code, and wouldn't if it didn't sort of work. I am trying to learn how to use timers and interrupts, and this is my first effort.

The LED on GPIO.0 flashes, but it is on far more than it is off. In addition, the off period changes in duration from very short to short, back and forth. Please tell me the things I have done wrong. Thanks.

Code:

'****************************************************************
'*  Name    : Timer1 Interrupt Blinky.pbp                      *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                              *
'*  Date    : 31-Aug-13                                        *
'*  Version : 1.0                                              *
'*  Notes  : 12F683                                            *
'*          :                                                  *
'****************************************************************
#IF __PROCESSOR__ = "12F683"
#config
cfg1 = _INTRC_OSC_NOCLKOUT  ; Internal oscillator
cfg1&= _WDT_ON              ; Watch Dog Timer enabled
cfg1&= _PWRTE_OFF          ; Power-up Timer disabled
cfg1&= _MCLRE_ON            ; Master Clear Reset enabled
cfg1&= _CP_OFF              ; Program Code Protection is disabled
cfg1&= _CPD_OFF            ; Data Code Protection is disabled
cfg1&= _BOD_OFF            ; Brown-out Detect disabled
cfg1&= _IESO_OFF            ; Internal Externa Switchover mode is disabled
cfg1&= _FCMEN_OFF          ; Fail-safe Clock Monitor is disabled
 __CONFIG  cfg1            ; Set the configuration bits 
#ENDCONFIG
#else
 #MSG "Wrong microcontroller selected!"
#endif    CONFIG = %000011100100

PIE1 = %00000001
PIR1 = %00000000
INTCON = %11000000
T1CON = %10110001    'ENABLE TMR1

    ON INTERRUPT GOTO TLOOP

    MAINLOOP:
    'MAIN CODE GOES HERE
    GOTO MAINLOOP

    DISABLE
    TLOOP:
    INTCON.2 = 0:TOGGLE GPIO.0
    RESUME: ENABLE


Viewing all articles
Browse latest Browse all 4746

Trending Articles