On-Chip FLASH Programming Routines, Rev. 4
26
Freescale Semiconductor
On-Chip Routines Source Code
;*********************************************************************
;* NAME: GetByte
;* PURPOSE:
;* Get one byte data through PTA0 serially. This routine supports
;* a baud rate 9600 bps at internal 4MHz and external 2.4576MHz bus
;* frequencies. A clock is distinguished by the state of ECGST bit
;* (bit 0) in OSCSTAT. When ECGST=1, an external clock is selected.
;* ENTRY CONDITIONS:
;* PTA0 configured as an input.
;* EXIT CONDITIONS:
;* A contains a byte received when START bit is detected
;* C-bit in CCR indicates a framing error
;* If C-bit is cleared, a framing error is indicated because
;* the STOP bit was detected as a 0 instead of a 1
;* PTA0 configured as an input
;* SUBROUTINES CALLED: GetBit
;* VARIABLES READ:
;* VARIABLES MODIFIED:
;* STACK USED: 6 (including the call to this routine)
;* SIZE: 18 bytes
;* DESCRIPTION: EXECUTED OUT OF ROM
;* Once called, program will remain in GetByte until a byte is
;* received. Signal to start receiving a byte is a valid
;* (low) START bit.
;* This routine does not service COP.
;* NOTE: Cycle path for each bit reception must be kept the same to
;* maintain a steady baud rate.
;* When OSCSTAT[0]=0 (internal clock is selected):
;* 9+(28+10*38)= 417 cycles @ 4.0 MHZ=104.3 us=9592 bps
;* (closest PC baud rate 9,600 bps)
;* When OSCSTAT[0]=1 (external clock is selected):
;* 9+(27+10*22) = 256 cycles @ 2.4576 MHZ = 104 us = 9,600 bps
;*********************************************************************
GetByte: brset 0,PTA,GetByte ;[.r...] loop till PTA0=0 (start)
bsr GetBit ;[4+GetBit] check sense of start bit
bcs GetByte ;[3] C-bit should be 0, else noise
lda #$80 ;[2] Rx byte done when 1 RORs into C
NextBit: ; top of loop to get 8 bits
bsr GetBit ;[4+GetBit] sense level of next bit
rora ;[1] rotate into A from left
nop ;[1] pad to tune timing
bcc NextBit ;[3] continue 'till 1 RORs into C
stpBit: bsr GetBit ;[4+GetBit] sense level of stop bit
rts ;[4]
;* GetByte DONE ******************
;*********************************************************************
;* NAME: PutByte
;* PURPOSE:
;* Send one byte data through PTA0 serially. This routine supports
;* a baud rate 9600 bps at internal 4MHz and external 2.4576MHz bus
;* frequencies. A clock is distinguished by the state of ECGST bit
;* (bit 0) in OSCSTAT. When ECGST=1, an external clock is selected.
;* ENTRY CONDITIONS:
;* PTA0 configured as an input, PTA0 data bit = 0
;* A contains data to be sent
;* EXIT CONDITIONS: