; common macros & equs etc. ;********************************************************************** ; 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 include /usr/share/gputils/header/p18f458.inc radix dec ;**************************************************************************** ; 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 ;---------------------------------------- ; debug(BYTE) ; writes BYTE through the serial port ; serial port hardware must be suitably initialised ; serial port transmit interrupts must be disabled ; will spin until the byte is transmitted ; Before After ; W any undefined ; S any undefined ; macro to call subroutine to transmit over serial port for debugging ; takes 8-bit value, puts in W, invokes debug_serial_transmit ifndef SLOW_VERSION debug macro debugvalue endm endif ifdef SLOW_VERSION debug macro debugvalue movlw debugvalue call polling_serial_transmit endm endif ;---------------------------------------- ; debughf(REGISTER) ; reads REGISTER once and writes it to the serial port in hex ; for conditions etc. see "debug", above ; Before After ; W any undefined ; S any undefined ifdef SLOW_VERSION DEBUGHF_VALUE equ 0x040 ; getting on towards end of access bank ; FIXME if all of program used udata that ; would be very nice debughf macro register movff register, DEBUGHF_VALUE call debughf_subroutine endm debughf_subroutine call debughf_digit call debughf_digit return ;-------------------- debughf_digit ; transmits top nybble of DEBUGHF_VALUE in hex ; through serial port, as above, and swaps nybbles ; Before After ; W any undefined ; DEBUGHF_VALUE BBBBaaaa aaaaBBBB (BBBB was sent) swapf DEBUGHF_VALUE,1,0 movf DEBUGHF_VALUE,0,0 andlw 0x0f sublw 10 sublw 0 bn debughf_digit_ifnot_ge10 addlw 'a'-('0'+10) debughf_digit_ifnot_ge10 addlw '0'+10 goto polling_serial_transmit else debughf macro register endm endif ;****************************************************************************