chiark / gitweb /
detect.asm just calls panis
[trains.git] / detpic / common.inc
1 ; common macros & equs etc.
2
3 ;**********************************************************************
4 ; boilerplate.inc
5 ;  Include this at the top of each file.
6 ;  Does the following things:
7 ;   includes the PIC18F458 definitions file (register and bit names)
8 ;   switches to decimal by default
9
10         include         /usr/share/gputils/header/p18f458.inc
11         radix           dec 
12
13 ;****************************************************************************
14 ; MACROS
15
16 ;----------------------------------------
17 ; ifbit1(REGISTER,BITNUMBER)
18 ;       executes the next instruction but only if bit BITNUMBER
19 ;       in REGISTER (which must be in the access bank) is set
20 ifbit1 macro REGISTER, BITNUMBER
21         btfsc   REGISTER, BITNUMBER, 0
22         endm
23
24 ;----------------------------------------
25 ; ifbit0(REGISTER,BITNUMBER)
26 ;       executes the next instruction but only if bit BITNUMBER
27 ;       in REGISTER (which must be in the access bank) is clear
28 ifbit0 macro REGISTER, BITNUMBER
29         btfss   REGISTER, BITNUMBER, 0
30         endm
31
32 ;----------------------------------------
33 ; debug(BYTE)
34 ;       writes BYTE through the serial port
35 ;       serial port hardware must be suitably initialised
36 ;       serial port transmit interrupts must be disabled
37 ;       will spin until the byte is transmitted
38 ;               Before          After
39 ;       W       any             undefined
40 ;       S       any             undefined
41
42 ; macro to call subroutine to transmit over serial port for debugging
43 ; takes 8-bit value, puts in W, invokes debug_serial_transmit
44         ifndef  SLOW_VERSION
45 debug macro debugvalue
46         endm
47         endif
48
49         ifdef   SLOW_VERSION
50 debug macro debugvalue
51         movlw   debugvalue
52         call    polling_serial_transmit
53         endm
54         endif
55
56 ;----------------------------------------
57 ; debughf(REGISTER)
58 ;       reads REGISTER once and writes it to the serial port in hex
59 ;       for conditions etc. see "debug", above
60 ;               Before          After
61 ;       W       any             undefined
62 ;       S       any             undefined
63  ifdef  SLOW_VERSION
64 DEBUGHF_VALUE   equ     0x040   ; getting on towards end of access bank
65                                 ; FIXME if all of program used udata that
66                                 ; would be very nice
67
68 debughf macro register
69         movff   register, DEBUGHF_VALUE
70         call    debughf_subroutine
71         endm
72
73 debughf_subroutine
74         call    debughf_digit
75         call    debughf_digit
76         return
77
78 ;--------------------
79 debughf_digit
80 ;       transmits top nybble of DEBUGHF_VALUE in hex
81 ;       through serial port, as above, and swaps nybbles
82 ;                       Before          After
83 ;       W               any             undefined
84 ; DEBUGHF_VALUE         BBBBaaaa        aaaaBBBB        (BBBB was sent)
85
86         swapf   DEBUGHF_VALUE,1,0
87         movf    DEBUGHF_VALUE,0,0
88         andlw   0x0f
89         sublw   10
90         sublw   0
91         bn      debughf_digit_ifnot_ge10
92         addlw   'a'-('0'+10)
93 debughf_digit_ifnot_ge10
94         addlw   '0'+10
95         goto    polling_serial_transmit
96
97  else
98 debughf macro register
99         endm
100  endif
101
102
103         
104 ;****************************************************************************
105