1 ; This program copies the values of flash memory bytes 20 0000h and
2 ; 20 0001h into program memory an then transmits them over the
6 ; pin 21 (per-pic-led, RD2/PSP2/C1IN) states:
7 ; high H = green, low L = red, float Z = black
11 include /usr/share/gputils/header/p18f458.inc
12 include ../iwjpictest/clockvaries.inc
20 NMRACTRL equ 0x4 ; byte 4: state relevant to NMRA control
21 TRANSMITBIT equ 0x7 ; bit 7: 0/1 bit currently being transmitted
22 NEXTACTION equ 0x6 ; bit 6: change polarity on next interrupt y/n
24 FROMSERIAL equ 0x1 ; byte 1: from-serial buffer location (in BSR5)
25 TOTRACK equ 0x2 ; byte 2: to-track buffer location (in BSR5)
26 TOTRACKBIT equ 0x3 ; byte 3: bit location of pointer within byte
30 ; flash locations for PIC-dependent info:
32 F_PIC_NO_U equ 20h ; flash location of PIC number
36 F_I2C_CTRL_U equ 20h ; flash location of i2c control byte
42 I2C_BUFF_PAGE equ 4 ; put i2c relevant stuff into buffer page 4
43 PIC_NO equ 00h ; pic no goes to 400h
44 I2C_CTRL equ 01h ; i2c ctrl bit goes to 401h
50 messg "hello this is the slow version"
54 messg "hello this is the fast version"
66 ;****************************************************************************
68 ; high priority interrupt
73 ; low priority interrupt
78 ;****************************************************************************
82 ;****************************************************************************
86 ; macro to call subroutine to transmit over serial port for debugging
87 ; takes 8-bit value, puts in W, invokes debug_serial_transmit
90 debug macro debugvalue
95 debug macro debugvalue
97 call debug_serial_transmit
101 debug_serial_transmit
102 movwf TXREG,0 ; move contents of W (i.e. debugvalue)
103 ; to TXREG for transmission
109 ;****************************************************************************
115 ; initial config - TXSTA register p181
116 bcf TXSTA,6,0 ; p181, set 8-bit mode
117 bsf TXSTA,5,0 ; transmit enable
118 bcf TXSTA,4,0 ; asynchronous mode
119 bsc_txsta_brgh ; set high or low baud rate
121 ; initial config - RCSTA register p182
122 bsf RCSTA,7,0 ; serial port enable (p182)
123 bcf RCSTA,6,0 ; 8-bit reception
124 bsf RCSTA,4,0 ; enable continuous receive
126 ; set SPBRG to get correct baud rate
130 ; interrupt set-up for serial receive
131 bcf IPR1,5,0 ; set to low-priority interrupt
134 ;----------------------------------------------------------------------------
136 ; copy PIC-dependent info out of flash memory
138 movlw F_PIC_NO_U ; set table pointer to point to
139 movwf TBLPTRU ; PIC number in flash
145 tblrd *+ ; read then increment pointer
146 ; (now points to i2c control byte)
148 movlb I2C_BUFF_PAGE ; ser BSR=i2c BSR (4)
149 movf TABLAT,0,0 ; move pic number into normal memory
154 movf TABLAT,0,0 ; move i2c_ctrl byte into normal memory
157 ; now have: PIC number in 400h, i2c control byte in 401h
160 ;----------------------------------------------------------------------------
164 ; globally enable interrupts - p77
165 bsf RCON,7,0 ; enable priority levels
166 bsf INTCON,7,0 ; enable high-priority interrupts
167 bsf INTCON,6,0 ; enable low-priority interrupts
168 bsf PIE1,5,0 ; enable USART receive interrupt (p85)
171 ;****************************************************************************
175 movlb I2C_BUFF_PAGE ; ser BSR=i2c BSR (4)
192 ;****************************************************************************
199 ;****************************************************************************
203 ; check which interrupt.
209 ;****************************************************************************
215 ;****************************************************************************
220 clrf INTCON,0 ; disable all interrupts EVER
222 bcf PORTC,1,0 ; switch off booster
228 ;****************************************************************************