From 206db4ea86b08e796aa0c501164e5b5fbf612b65 Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 10 Apr 2005 20:03:34 +0000 Subject: [PATCH] common.inc; routines library; move leds into routines library; minor improvements (no behavioural change) to panic.asm --- cebpic/.cvsignore | 1 + cebpic/Makefile | 15 +++++++-- cebpic/common.inc | 27 +++++++++++++++ cebpic/i2c-test.asm | 26 +++------------ cebpic/nmra-stream.asm | 19 ++--------- cebpic/nmra-test.asm | 15 --------- cebpic/panic.asm | 73 +++++++++++++---------------------------- cebpic/reply-serial.asm | 19 +++-------- cebpic/routines-led.asm | 39 ++++++++++++++++++++++ cebpic/tblrd_test.asm | 20 +++-------- detpic/nmra-stream.asm | 19 ++--------- 11 files changed, 120 insertions(+), 153 deletions(-) create mode 100644 cebpic/common.inc create mode 100644 cebpic/routines-led.asm diff --git a/cebpic/.cvsignore b/cebpic/.cvsignore index 243b0c3..ed00119 100644 --- a/cebpic/.cvsignore +++ b/cebpic/.cvsignore @@ -3,3 +3,4 @@ *.lst idlocs*.asm gpsim.log +routines.lib diff --git a/cebpic/Makefile b/cebpic/Makefile index d6c6509..e45de1c 100644 --- a/cebpic/Makefile +++ b/cebpic/Makefile @@ -3,25 +3,36 @@ PROGRAMS= led-flash send-serial panic reply-serial \ 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 diff --git a/cebpic/common.inc b/cebpic/common.inc new file mode 100644 index 0000000..1ce0cd4 --- /dev/null +++ b/cebpic/common.inc @@ -0,0 +1,27 @@ +;********************************************************************** +; 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 + diff --git a/cebpic/i2c-test.asm b/cebpic/i2c-test.asm index 6eae272..0c7e62a 100644 --- a/cebpic/i2c-test.asm +++ b/cebpic/i2c-test.asm @@ -28,6 +28,10 @@ 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 @@ -483,28 +487,6 @@ wait_for_i2c_interrupt_loop 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; diff --git a/cebpic/nmra-stream.asm b/cebpic/nmra-stream.asm index a5274d8..09976ac 100644 --- a/cebpic/nmra-stream.asm +++ b/cebpic/nmra-stream.asm @@ -17,6 +17,9 @@ TOTRACKBIT equ 0x3 ; byte 3: bit location of pointer within byte BUFFERPAGE equ 5 + extern led_green + extern led_red + extern led_black ifdef SLOW_VERSION messg "hello this is the slow version" @@ -444,22 +447,6 @@ advance_read_buffer ;**************************************************************************** -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 diff --git a/cebpic/nmra-test.asm b/cebpic/nmra-test.asm index 76dfc59..d3eee85 100644 --- a/cebpic/nmra-test.asm +++ b/cebpic/nmra-test.asm @@ -79,21 +79,6 @@ main 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, diff --git a/cebpic/panic.asm b/cebpic/panic.asm index ee93679..4b034ec 100644 --- a/cebpic/panic.asm +++ b/cebpic/panic.asm @@ -8,11 +8,11 @@ ; 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 @@ -25,12 +25,6 @@ TESTFLASH equ 04h ; test LED flash pattern -;--------------------------------------------------------------------------- -; LED colours - -RED equ 0 -GREEN equ 1 - ;--------------------------------------------------------------------------- ; memory location definitions @@ -63,26 +57,10 @@ err_SOS equ 0 ; msg 0 = SOS 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 @@ -99,18 +77,18 @@ ifbit0 macro REGISTER, BITNUMBER ; 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 @@ -123,18 +101,17 @@ readout_loop 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 @@ -245,30 +222,24 @@ informative_panic 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 diff --git a/cebpic/reply-serial.asm b/cebpic/reply-serial.asm index 236c215..fec173b 100644 --- a/cebpic/reply-serial.asm +++ b/cebpic/reply-serial.asm @@ -2,6 +2,10 @@ include /usr/share/gputils/header/p18f458.inc + extern led_green + extern led_red + extern led_black + org 0 goto initialise_serial @@ -63,21 +67,6 @@ main 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, diff --git a/cebpic/routines-led.asm b/cebpic/routines-led.asm new file mode 100644 index 0000000..c405e05 --- /dev/null +++ b/cebpic/routines-led.asm @@ -0,0 +1,39 @@ +;********************************************************************** +; 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 diff --git a/cebpic/tblrd_test.asm b/cebpic/tblrd_test.asm index c95f825..13f1467 100644 --- a/cebpic/tblrd_test.asm +++ b/cebpic/tblrd_test.asm @@ -10,6 +10,10 @@ 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 @@ -212,22 +216,6 @@ serial_receive ;**************************************************************************** -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 diff --git a/detpic/nmra-stream.asm b/detpic/nmra-stream.asm index a5274d8..09976ac 100644 --- a/detpic/nmra-stream.asm +++ b/detpic/nmra-stream.asm @@ -17,6 +17,9 @@ TOTRACKBIT equ 0x3 ; byte 3: bit location of pointer within byte BUFFERPAGE equ 5 + extern led_green + extern led_red + extern led_black ifdef SLOW_VERSION messg "hello this is the slow version" @@ -444,22 +447,6 @@ advance_read_buffer ;**************************************************************************** -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 -- 2.30.2