rendered paste body;File Name: blinky1.asm
;Author: Stephen Shirley
;Date: 2006/02/15
;Version: 1.1
;Description: Lights the leds in sequence
;
;******************************************************************************
list p=12F675 ; list directive to define processor
#include <p12f675.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
;******************************************************************************
;Defines
;******************************************************************************
#define Bank0 0x00
#define Bank1 0x80
#define D01Tris 0x0F
#define D0On 0x10
#define D1On 0x20
#define D23Tris 0x2B
#define D2On 0x10
#define D3On 0x04
#define D45Tris 0x1B
#define D4On 0x20
#define D5On 0x04
#define D67Tris 0x39
#define D6On 0x04
#define D7On 0x02
;******************************************************************************
;General Purpose Registers (GPR's)
;******************************************************************************
cblock 0x20
LedOn ; number of currently on led
Count ; general counting reg
endc
;******************************************************************************
;Reset Vector
;******************************************************************************
ORG 0x000 ; processor reset vector
nop ; required by in circuit debugger
goto Init ; go to beginning of program
;******************************************************************************
;Interrupt Vector
;******************************************************************************
ORG 0x004
return ; interrupt trap - return without re-enabling
GetTrisValue
rrf LedOn,0
andlw 0x3
addwf PCL,1
retlw D01Tris
retlw D23Tris
retlw D45Tris
retlw D67Tris
GetLedValue
addwf PCL,1
retlw D0On
retlw D1On
retlw D2On
retlw D3On
retlw D4On
retlw D5On
retlw D6On
retlw D7On
;******************************************************************************
;Initialization
;******************************************************************************
Init
;call 0x3FF ; retrieve factory calibration value
; comment instruction if using simulator, ICD2, or ICE2000
BANKSEL Bank1 ; BANK1
movwf OSCCAL ; update register with factory cal value
movlw B'11010000' ; Timer0 internal clock, 1:4 prescale
movwf OPTION_REG ; set option register for Timer0 functions
clrf ANSEL ; configure A/D I/O as digital
BANKSEL Bank0 ; switch back to PORT memory bank
clrf GPIO
movlw 0x77 ; configure comparator inputs as digital I/O
movwf CMCON ;
clrf Count ; zero counter
clrf LedOn ; zero LedOn
;******************************************************************************
;Main
;******************************************************************************
Main
BANKSEL Bank0
; Wait for Timer0 overflow
; Timer0 overflows about every 1 millisecond with the internal 4 MHz clock
; and 1:4 prescale
TimerLoop
btfss INTCON,T0IF ; wait for Timer0 overflow
goto TimerLoop ;
bcf INTCON,T0IF ; clear Timer0 overflow flag
decfsz Count,1
goto TimerLoop;
call LightLed ; test switch once every millisecond
LightLed
call GetTrisValue
BANKSEL Bank1
movwf TRISIO
movlw 0x7
andwf LedOn,0
call GetLedValue
BANKSEL Bank0
movwf GPIO
incf LedOn,1 ; Increment LedOn variable
return
;goto Main ; return to monitor loop
END