Blinkin' LEDs on the Lab X-3
30-Dec-2001
This simple bit of code will cause the LED on the LAB-X3 to blink on and off.
;
; BLINKY.ASM
;
; This simple bit of code should allow us to blink two LEDs
; attached to
; The LAB-X3 board.
;
TITLE "Blink the LEDs on LAB-X3"
LIST P=PIC16F628, R=HEX, C=120, N=50
include "P16f628.inc"
;
; Very important! If you're using the LAB_X3 these fuses
; _LVP_OFF - Low Voltage Programming (Disabled)
; _MCLRE_OFF - MCLR/Reset (Disable)
; _LP_OSC - Low Power Crystal Oscillator (Enable)
; Must be set. Otherwise the board just doesn't run.
;
__FUSES _CP_OFF&_LP_OSC&_WDT_OFF&_LVP_OFF&_MCLRE_OFF
;
; Data bits
;
CBLOCK H'20'
COUNT
ENDC
I_CNT EQU H'1' ; Initial Count
LED1 EQU 4
LED2 EQU 5
;
; Initialization
;
ORG H'0000' ; Start VECTOR
NOP ; Space
GOTO MAIN ; Go to MAIN
;
; * * * * * * * * * * * *
; * M A I N *
; * * * * * * * * * * * *
;
; Main Body with initialization Etc.
;
MAIN:
BSF STATUS, RP0 ; Select Bank 1
MOVLW B'0000111' ; Set TMR0 prescaler to 256
MOVWF OPTION_REG ; Store in the OPTION register
BCF PORTB, LED1 ; Enable LED 1 and 2 as outputs
BCF PORTB, LED2 ;
BCF STATUS, RP0 ; Back to page 0
MOVLW I_CNT ; Initial Count load
MOVWF COUNT ; For the first loop
LOOPER:
BTFSS INTCON, T0IF ; Did TMR0 overflow?
GOTO LOOPER ; Nope so keep waiting
BCF INTCON, T0IF ; Reset the TMR0 flag.
DECF COUNT,F ; Decrement Counter
INCFSZ COUNT,W ; check for underflow
GOTO LOOPER ; Nope, keep counting
;
; Timer overflowed Count times so we toggle the LED
;
MOVLW I_CNT ; Restore counter value
MOVWF COUNT ; With default value
BTFSS PORTB, LED1 ; If LED1 is on, turn it off
GOTO $+4 ; If its off jump to turn it on
BCF PORTB, LED1 ; Turn LED1 off and
BSF PORTB, LED2 ; ... LED2 on
GOTO LOOPER
BSF PORTB, LED1 ; Turn LED1 on and
BCF PORTB, LED2 ; ... LED1 off
GOTO LOOPER
END
|
||
| Listing 1: LED Blinking Program |