Hardware Reference
In-Depth Information
Example 14.5
Write a function to clear the ACCERR and PVIOL flags in all four blocks in the HCS12
devices with 256 kB of on-chip flash memory.
Solution: The following function clears the ACCERR and PVIOL flags in all four blocks in the
HCS12 devices with 256 kB of on-chip flash memory:
clearflags
bclr
FCNFG,$03
; select bank 0
movb
#ACCERR 1 PVIOL,FSTAT
; clear the ACCERR and PVIOL flags
bset
FCNFG,$01
; select bank 1
movb
#ACCERR 1 PVIOL,FSTAT
; clear the ACCERR and PVIOL flags
bset
FCNFG,$03
; select bank 3
movb
#ACCERR 1 PVIOL,FSTAT
; clear the ACCERR and PVIOL flags
bclr
FCNFG,$01
; select bank 2
movb
#ACCERR 1 PVIOL,FSTAT
; clear the ACCERR and PVIOL flags
rts
The C language version of the function is as follows:
void clearflags (void)
{
FCNFG
& 5 , 0x03;
// select bank 0
FSTAT 5 ACCERR 1 PVIOL;
// clear the ACCERR and PVIOL flags
FCNFG
| 5 0x01;
// select bank 1
FSTAT 5 ACCERR 1 PVIOL;
// clear the ACCERR and PVIOL flags
FCNFG
| 5 0x03;
// select bank 3
FSTAT 5 ACCERR+PVIOL;
// clear the ACCERR and PVIOL flags
FCNFG
& 5 0xFE;
// select bank 2
FSTAT 5 ACCERR 1 PVIOL;
// clear the ACCERR and PVIOL flags
}
Example 14.6
Write a function that erases a sector of flash memory. Index register X contains a word-
aligned address within the sector to be erased. Return a 1 in B if the command buffer is not
empty.
Solution: The assembly routine that erases the sector pointed to by index register X is as
follows:
EraseFSector brclr FSTAT,CBEIF,err2ES
; erase prohibited if command buffer not empty
std
0,X
; write any data to sector address
movb #SectorErase,FCMD
; write sector erase command
movb #CBEIF,FSTAT
; launch the erase command
brclr FSTAT,ACCERR+PVIOL,OK2ER
; no error flag?
err2ES
ldab #1
; return error code 1
rts
OK2ER
brclr FSTAT,CCIF,OK2ER
; wait until command is completed
ldab #0
; erase successfully, return code 0
rts
 
Search WWH ::




Custom Search