chiark / gitweb /
common.inc; routines library; move leds into routines library; minor improvements...
authorian <ian>
Sun, 10 Apr 2005 20:03:34 +0000 (20:03 +0000)
committerian <ian>
Sun, 10 Apr 2005 20:03:34 +0000 (20:03 +0000)
cebpic/.cvsignore
cebpic/Makefile
cebpic/common.inc [new file with mode: 0644]
cebpic/i2c-test.asm
cebpic/nmra-stream.asm
cebpic/nmra-test.asm
cebpic/panic.asm
cebpic/reply-serial.asm
cebpic/routines-led.asm [new file with mode: 0644]
cebpic/tblrd_test.asm
detpic/nmra-stream.asm

index 243b0c33664c7f1ec821f7e45463982bb397b8a5..ed00119a330e6dc42cf31c7062b3194449a51ccb 100644 (file)
@@ -3,3 +3,4 @@
 *.lst
 idlocs*.asm
 gpsim.log
+routines.lib
index d6c6509fcfcafd1f937ebe370ddf6c3ec6c29e26..e45de1c0b1656530eca59f7b8e43690dfae42e77 100644 (file)
@@ -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 (file)
index 0000000..1ce0cd4
--- /dev/null
@@ -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
+
index 6eae272d0007adc5c4bb80b3ea889b8434809915..0c7e62a914b0cf7b98c8d3ed2139a2fcbbcfac4e 100644 (file)
         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;
 
index a5274d8498b358c6958ec6eb333f015bdc4e0e4c..09976ac422dbfb32d296ef75f34e74cd923c7283 100644 (file)
@@ -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
index 76dfc595d9df4f9a53c16f0c00460a9f1714e691..d3eee857c0ff9eb2290738aa3eac5fd0baa837db 100644 (file)
@@ -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,
index ee93679eb321d2aa56ad86b3a00bcce69cae2b87..4b034eca7e10a28ed4d92c1d070316871a94c143 100644 (file)
@@ -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
index 236c215d12d61479a17eb689181b3580d168d983..fec173bd5c4365ac86c7ddd73900839cab89c53c 100644 (file)
@@ -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 (file)
index 0000000..c405e05
--- /dev/null
@@ -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
index c95f82588a6efccb187994dbcf8173e4874c3886..13f1467e506b2fa1df4840ada03ce634fbbbffc9 100644 (file)
 
         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
index a5274d8498b358c6958ec6eb333f015bdc4e0e4c..09976ac422dbfb32d296ef75f34e74cd923c7283 100644 (file)
@@ -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