;------------------------------------------------------------------------------- ; FILE: Timer ; AUTH: Ed's Projects ; DATE: 26/03/2017 ; DESC: Flashing LED using Timer 0 on PortA 0 (pin 2) ;------------------------------------------------------------------------------- LIST P=18F4520, R=DEC ; All numbers Decimal format unless otherwise stated. include ; Define configurations, registers, etc. CONFIG OSC = INTIO67 ; 8 MHz internal oscillator CONFIG FCMEN = OFF ; Failsafe clock monitor off CONFIG IESO = OFF ; Internal / External oscillator switchover off CONFIG PWRT = ON ; Power up timer on CONFIG BOREN = OFF ; Brown out reset off CONFIG WDT = OFF ; Watchdog timer off CONFIG MCLRE = OFF ; Master reset pin off CONFIG LPT1OSC = OFF ; Low power timer 1 off CONFIG PBADEN = OFF ; PortB 4 to 0 digital on reset CONFIG LVP = OFF ; Low voltage programming off CONFIG XINST = OFF ; Extended instruction set enabled ;------------------------------------------------------------------------------- ;-------------------------------- Variables ---------------------------------- ;------------------------------------------------------------------------------- cblock 0x000 endc ;------------------------------------------------------------------------------- ;------------------------------ Define Symbols ------------------------------- ;------------------------------------------------------------------------------- #define LED LATA, 0, 1 ;------------------------------------------------------------------------------- ;------------------------------- Program Code -------------------------------- ;------------------------------------------------------------------------------- ORG 0x0 ; Reset Vector goto Init ORG 0x0008 ; High Priority Interrupt Vector goto HintVect ORG 0x0018 ; Low Priority Interrupt Vector ;------------------------------------------------------------------------------- ;----------------------- Low Priority Interrupt Vector ----------------------- ;------------------------------------------------------------------------------- LintVect retfie ;------------------------------------------------------------------------------- ;---------------------- High Priority Interrupt Vector ----------------------- ;------------------------------------------------------------------------------- HintVect btg LED bcf INTCON, TMR0IF, 1 ; Clear timer flag movlw 0x85 movwf TMR0H, 1 movlw 0xEE movwf TMR0L, 1 retfie ;------------------------------------------------------------------------------- ;-------------------------- Initialisation of Ports -------------------------- ;------------------------------------------------------------------------------- Init movlb d'15' ; Set BSR to bank 15 clrf ADCON0 ; Turn off analogue module movlw 00001111b movwf ADCON1 ; Configure all pins as digital movlw 00000111b movwf CMCON ; Turn off comparators clrf TRISA, 1 clrf TRISB, 1 clrf TRISC, 1 clrf TRISD, 1 ; Set all ports as outputs clrf TRISE, 1 movlw 01110000b movwf OSCCON ; 8MHz Internal oscillator movlw 01000000b movwf OSCTUNE ; Enable PLL ; 32MHz with PLL bsf RCON, IPEN, 1 ; Turn on Priority Interrupts movlw 00000111b movwf T0CON, 1 ; Set internal timer, 256 prescaler, 16 bit bsf INTCON, TMR0IE, 1 ; Enable timer 0 interrupt bsf INTCON2, TMR0IP, 1 ; Set timer 0 priority high ;------------------------------------------------------------------------------- ;------------------------------- Main Program -------------------------------- ;------------------------------------------------------------------------------- Main bcf LED movlw 0x85 movwf TMR0H, 1 movlw 0xEE movwf TMR0L, 1 bsf INTCON, GIE, 1 ; Turn on interrupts bsf T0CON, TMR0ON, 1 ; Start Timer goto $ end