Hello!
I've been trying my hand at Assembler with the PIC16F628A and I have to say it is rather neat!
However, while messing around with my "first program" (of course, trying to blink an LED-- but through interrupts), I am totally stumped. I am sure I made some foolish mistakes, but I can't get the LED to blink! The LED just stays on.
Any help would be greatly appreciated!
Thank you,
-Omar
I've been trying my hand at Assembler with the PIC16F628A and I have to say it is rather neat!
However, while messing around with my "first program" (of course, trying to blink an LED-- but through interrupts), I am totally stumped. I am sure I made some foolish mistakes, but I can't get the LED to blink! The LED just stays on.
Any help would be greatly appreciated!
Thank you,
-Omar
Code:
;Test program-- lots of stolen snippets, hehe.
LIST p=16F628A ;tell assembler what chip we are using
include "P16F628A.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings
ORG 0 ;the start address in program memory is 0
STATUS equ 03h ;equates section
TRISB equ 86h
PORTB equ 06h
INTCON equ 0x0B ;Interrupt register
OPT_REG equ 0x81 ;option register
TMR0 equ 0x01 ;timer register
bsf STATUS, 5 ;switch to bank 1
movlw b'00000000' ;all portb pins will be outputs outputs
movwf TRISB
movlw b'00000111' ;Setting prescaler values
movwf OPT_REG
bcf STATUS, 5 ;back to old bank 0
bsf INTCON, 7 ;GIE - needed to be turned on for interrupts
bsf INTCON, 5 ;TOIE - Enable bit for overflow timer
bcf INTCON, 2 ;Just in case, make sure the overflow flag is off
clrf TMR0 ;clear timer, just in case
movlw b'11111111' ;set all pins high
movwf PORTB
goto Flash
Flash
btfss INTCON, 2 ;test if interrupt occured
goto Flash ;not yet
Interrupt_Section
btfss PORTB,1 ;check if PORTB is on-- turn it off, else turn it on.
goto ON_LED
goto OFF_LED
goto Flash
ON_LED
movlw b'11111111' ;set all pins high
movwf PORTB ;output
bcf INTCON, 2 ;clear the flag before you leave
clrf TMR0
bsf INTCON, 7 ;GIE - needed to be turned on for interrupts
bsf INTCON, 5 ;TOIE - Enable bit for overflow timer
goto Flash
OFF_LED
movlw b'00000000' ;set all pins low
movwf PORTB ;output
bcf INTCON, 2 ;clear the flag before you leave
clrf TMR0
bsf INTCON, 7 ;GIE - needed to be turned on for interrupts
bsf INTCON, 5 ;TOIE - Enable bit for overflow timer
goto Flash
End