*.lst
idlocs*.asm
gpsim.log
+routines.lib
i2c-test i2c-test,slow
# booster-output-low -disabled because you forgot to cvs add it
+ROUTINES= routines-led
+
+INCLUDES= common.inc
+
PICNOS= 0 1 3
TARGETS= $(foreach i, $(PICNOS), perpic$i.hex)
+LIBS= routines.lib
+
include ../pic.make
clean: pic-clean
rm -f idlocs*.asm
+routines.lib: $(addsuffix .o, $(ROUTINES))
+ rm -f $@.new
+ gplib -c $@.new $^
+ mv -f $@.new $@
+
%,slow.o: %.asm
$(ASSEMBLE) -D SLOW_VERSION -c -o $@ $<
idlocs%.asm: make-idlocs
./$< $* >$@.new && mv -f $@.new $@
-perpic%.hex: config.o idlocs%.o
+perpic%.hex: config.o idlocs%.o $(LIBS()
$(LINK)
-%-entire0.hex: %.o config.o idlocs0.o
+%-entire0.hex: %.o config.o idlocs0.o routines.lib
$(LINK)
.PRECIOUS: idlocs%.asm
--- /dev/null
+;**********************************************************************
+; boilerplate.inc
+; Include this at the top of each file.
+; Does the following things:
+; includes the PIC18F458 definitions file (register and bit names)
+; switches to decimal by default
+; defines various useful macros
+
+ include /usr/share/gputils/header/p18f458.inc
+ radix dec
+
+;----------------------------------------
+; ifbit1(REGISTER,BITNUMBER)
+; executes the next instruction but only if bit BITNUMBER
+; in REGISTER (which must be in the access bank) is set
+ifbit1 macro REGISTER, BITNUMBER
+ btfsc REGISTER, BITNUMBER, 0
+ endm
+
+;----------------------------------------
+; ifbit0(REGISTER,BITNUMBER)
+; executes the next instruction but only if bit BITNUMBER
+; in REGISTER (which must be in the access bank) is clear
+ifbit0 macro REGISTER, BITNUMBER
+ btfss REGISTER, BITNUMBER, 0
+ endm
+
include /usr/share/gputils/header/p18f458.inc
radix dec
+ extern led_green
+ extern led_red
+ extern led_black
+
ifdef SLOW_VERSION
messg "hello this is the slow version"
endif
return
-;***************************************************************************
-; PER-PIC LED
-
-;----------------------------------------
-led_green
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bsf LATD,2,0 ; set pin RD2 H (green)
- return
-
-;----------------------------------------
-led_black
- bsf TRISD,2,0 ; make pin RD2 an input (i.e. set Z, black)
- ; (DS100)
- return
-
-;----------------------------------------
-led_red
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bcf LATD,2,0 ; set pin RD2 L (red)
- return
-
-
;***************************************************************************
; GENERALLY-USEFUL SUBROUTINES;
BUFFERPAGE equ 5
+ extern led_green
+ extern led_red
+ extern led_black
ifdef SLOW_VERSION
messg "hello this is the slow version"
;****************************************************************************
-led_green
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bsf LATD,2,0 ; set pin RD2 H (green)
- return
-
-led_black
- bsf TRISD,2,0 ; make pin RD2 an input (i.e. set Z, black)
- ; (DS100)
- return
-
-led_red
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bcf LATD,2,0 ; set pin RD2 L (red)
- return
-
-
panic
debug 'x'
clrf INTCON,0 ; disable all interrupts EVER
goto main
-led_green
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bsf LATD,2,0 ; set pin RD2 H (green)
- return
-
-led_black
- bsf TRISD,2,0 ; make pin RD2 an input (i.e. set Z, black) (DS100)
- return
-
-led_red
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bcf LATD,2,0 ; set pin RD2 L (red)
- return
-
-
waiting
bcf INTCON,2,0 ; clear timer0 interrupt bit (p109)
clrf TMR0H,0 ; p107 set high bit of timer0 to 0 (buffered,
; to start, need to write into flash, starting at 30 0000h:
; 10 10 10 00 | 1110 1110 | 1110 00 10 | 10 10
-;---------------------------------------------------------------------------
-; boilerplate:
+ include common.inc
- include /usr/share/gputils/header/p18f458.inc
- radix dec
+ extern led_green
+ extern led_red
+ extern led_black
;---------------------------------------------------------------------------
; reserved access bank locations
-;---------------------------------------------------------------------------
-; LED colours
-
-RED equ 0
-GREEN equ 1
-
;---------------------------------------------------------------------------
; memory location definitions
org 000018h
goto interrupt_low
-
+;
;****************************************************************************
; MACROS
-;----------------------------------------
-; ifbit1(REGISTER,BITNUMBER)
-; executes the next instruction but only if bit BITNUMBER
-; in REGISTER (which must be in the access bank) is set
-ifbit1 macro REGISTER, BITNUMBER
- btfsc REGISTER, BITNUMBER, 0
- endm
-
-;----------------------------------------
-; ifbit0(REGISTER,BITNUMBER)
-; executes the next instruction but only if bit BITNUMBER
-; in REGISTER (which must be in the access bank) is clear
-ifbit0 macro REGISTER, BITNUMBER
- btfss REGISTER, BITNUMBER, 0
- endm
-
;----------------------------------------
; errmsg(ERRCODE,COLOUR)
; reads the chosen error msg out of flash and transmits by
; endm
;----------------------------------------
-; readout(READOUTREG,COLOUR)
+; readout(READOUTREG,GREEN)
; transmits the contents of the chosen byte by flashing LED
-; in chosen colour [1 = blue (=green), 0 = orange (=red)]
+; in chosen colour [GREEN=1: green (=blue); GREEN=0: red (=orange)]
; NB using WREG2 as copy of READOUTREG contents
-; using WREG3 as COLOUR store
+; using WREG3 as GREEN store
; using WREG4 as counter
-readout macro ERRCODE, COLOUR
- movlw COLOUR
- movwf WREG3,0 ; copy COLOUR into WREG3
+readout macro ERRCODE, GREEN
+ movlw GREEN
+ movwf WREG3,0 ; copy GREEN into WREG3
clrf WREG4,0 ; clear loop counter (WREG4)
movff ERRCODE,WREG2 ; copy ERRCODE into WREG2
bra readout_led_on
readout_led_on
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- ifbit0 WREG3,0
- bcf LATD,2,0 ; led red
+ ifbit0 WREG3,0 ; check desired colour
+ call led_red
ifbit1 WREG3,0
- bsf TRISD,2,0 ; led black
+ call led_green
incf WREG4,1,0 ; increment loop counter
call waiting
goto readout_loop
readout_led_off
- bsf TRISD,2,0 ; make pin RD2 an input (i.e. set Z, black)
+ call led_black
incf WREG4,1,0 ; increment loop counter
call waiting
goto readout_loop
clrf BLANK,0
panic_loop
-; errmsg err_SOS,RED ; transmit SOS in red
- readout TESTFLASH,RED ; transmit contents of SSPCON1 in red
-; readout BLANK,RED ; transmit blank buffer
+; errmsg err_SOS,0 ; transmit SOS in red
+ readout TESTFLASH,0 ; transmit contents of SSPCON1 in red
+; readout BLANK,0 ; transmit blank buffer
call led_green
call waiting
goto panic_loop
;****************************************************************************
; GENERAL SUBROUTINES
-; subroutine for turning LED green
-
-led_green
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bsf LATD,2,0 ; set pin RD2 H (green)
- return
;----------------------------------------
-; wait for timer0 interrupt
-
waiting
+; waits for a fixed interval, depending on the configuration of TMR0
+
bcf INTCON,2,0 ; clear timer0 interrupt bit (p109)
- clrf TMR0H,0 ; p107 set high bit of timer0 to 0 (buffered,
+ clrf TMR0H,0 ; p107 set high byte of timer0 to 0 (buffered,
; only actually set when write to tmr0l occurs)
- clrf TMR0L,0 ; set low bit o timer0 - timer now set to 0000h
+ clrf TMR0L,0 ; set timer0 low byte - timer now set to 0000h
loop
btfss INTCON,2,0 ; check whether timer0 interrupt has been set -
; skip next instruction if so
include /usr/share/gputils/header/p18f458.inc
+ extern led_green
+ extern led_red
+ extern led_black
+
org 0
goto initialise_serial
goto main
-led_green
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bsf LATD,2,0 ; set pin RD2 H (green)
- return
-
-led_black
- bsf TRISD,2,0 ; make pin RD2 an input (i.e. set Z, black) (DS100)
- return
-
-led_red
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bcf LATD,2,0 ; set pin RD2 L (red)
- return
-
-
waiting
bcf INTCON,2,0 ; clear timer0 interrupt bit (p109)
clrf TMR0H,0 ; p107 set high bit of timer0 to 0 (buffered,
--- /dev/null
+;**********************************************************************
+; routines-led
+; subroutines for controlling the per-pic LED (pin 21, DS100)
+
+ include common.inc
+
+ global led_green
+ global led_red
+ global led_black
+
+ code
+
+;----------------------------------------
+led_red
+; makes the LED be red (or orange), no matter its previous state
+; no RAM locations used or modified
+; W is unchanged
+ bcf LATD, 2, 0 ; output low
+ bcf TRISD, 2, 0 ; output enabled
+ return
+
+;----------------------------------------
+led_green
+; makes the LED be green (or blue), no matter its previous state
+; no RAM locations used or modified
+; W is unchanged
+ bsf LATD, 2, 0 ; output high
+ bcf TRISD, 2, 0 ; output enabled
+ return
+
+;----------------------------------------
+led_black
+; makes the LED be black (off), no matter its previous state
+; no RAM locations used or modified
+; W is unchanged
+ bsf TRISD, 2, 0 ; disable flasher output
+ return
+
+ end
include /usr/share/gputils/header/p18f458.inc
+ extern led_green
+ extern led_red
+ extern led_black
+
; reserved for NMRA:
NMRACTRL equ 0x4 ; byte 4: state relevant to NMRA control
;****************************************************************************
-led_green
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bsf LATD,2,0 ; set pin RD2 H (green)
- return
-
-led_black
- bsf TRISD,2,0 ; make pin RD2 an input (i.e. set Z, black)
- ; (DS100)
- return
-
-led_red
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bcf LATD,2,0 ; set pin RD2 L (red)
- return
-
-
panic
debug 'x'
clrf INTCON,0 ; disable all interrupts EVER
BUFFERPAGE equ 5
+ extern led_green
+ extern led_red
+ extern led_black
ifdef SLOW_VERSION
messg "hello this is the slow version"
;****************************************************************************
-led_green
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bsf LATD,2,0 ; set pin RD2 H (green)
- return
-
-led_black
- bsf TRISD,2,0 ; make pin RD2 an input (i.e. set Z, black)
- ; (DS100)
- return
-
-led_red
- bcf TRISD,2,0 ; make pin RD2 an output (DS100)
- bcf LATD,2,0 ; set pin RD2 L (red)
- return
-
-
panic
debug 'x'
clrf INTCON,0 ; disable all interrupts EVER