On-Chip Routines Source Code
On-Chip FLASH Programming Routines, Rev. 4
Freescale Semiconductor
27
;* A and X is restored to entry values
;* PTA0 configured as an input (PTA0=high idle line)
;* SUBROUTINES CALLED:
;* VARIABLES READ:
;* VARIABLES MODIFIED:
;* STACK USED: 4 (including the call to this routine)
;* SIZE: 46 bytes
;* DESCRIPTION: EXECUTED OUT OF ROM
;* After ~2 bit times delay, a character in A is sent via PTA0
;* Once called, program will remain in PutByte until PTA0=high
;* This routine does not service COP
;*********************************************************************
PutByte: pshx ;[2] save X
psha ;[2] temp save Tx data
lda #10 ;[2] start, 8 data, stop = 10 loops
brclr 0,PTA,* ;[.r...] wait for PTA0 high (idle)
ldx #BitX2 ;[2] load constant for Ext
;* delay ~2 bit times before transmitting data (time not critical)
;* Ext 2 bit is 25% longer and Int 2 bit is 23% shorter
delay: dbnzx delay ;[3] loop 3 cyc * BitX2I
sec ;[1] becomes stop bit after 9 RORs
bra outLow ;[3] Tx a low for start bit
PutLoop: ror 1,SP ;[5] LSB to C-bit, Tx that level
bcc outLow ;[3] if C=0 Tx low, else Tx high
outHi: bclr 0,DDRA ;[4] PTA0 input pulls up to high
bra outDelay ;[3] go to time 1 bit delay
outLow: bset 0,DDRA ;[4] PTA0 output makes pin drive low
bra outDelay ;[3] time 1 bit delay (match time)
outDelay: ldx OSCSTAT ;[3] check for Int/Ext clk
bne BitE ;[3] branch if Ext (OSCSTAT!=$00)
ldx #BitTimeI ;[2] load Int bit delay
bra delOut ;[3] skip to delOut
BitE: nop ;[1] timing adjust
ldx #BitTimeE ;[2] load Ext bit delay
delOut: dbnzx delOut ;[3] loop 3~ * (value in X)
nop ;[1] timing adjust
dbnza PutLoop ;[3] repeat for start, 8 data, stop
pula ;[2] restore Tx data
pulx ;[2] restore X
rts ;[4]
;* PutByte DONE ******************
;*********************************************************************
;* NAME: GetBit
;* PURPOSE:
;* Receive one serial bit via PTA0 and return it in C-bit
;* ENTRY CONDITIONS:
;* PTA0 configured as an input.
;* EXIT CONDITIONS:
;* A and X is restored to entry values
;* Bit level is returned to C bit in CCR
;* PTA0 configured as an input.
;* SUBROUTINES CALLED: GetBit
;* VARIABLES READ: