Hardware Reference
In-Depth Information
programmed. A 0 is returned in accumulator B if the command is performed correctly; other-
wise, a 1 is returned.
Solution: The function that performs the specified function is as follows:
eeprogram
movb
#ACCERR 1 PVIOL,ESTAT
; clear error flags
brclr
ESTAT,CBEIF,cantPRE
; command buffer not empty
std
0,x
; write data to EEPROM address
movb
#Program,ECMD
; write the command
movb
#CBEIF,ESTAT
; launch the erase and check command
brclr
ESTAT,ACCERR 1 PVIOL,EEPROK
cantPRE
ldab
#1
; return error code 1
rts
EEPROK
brclr
ESTAT,CCIF,EEPROK
; wait until command is done
clrb
; successful program code is 0
rts
The C language version of the function is as follows:
int eeprogram (unsigned int data, unsigned int *ptr)
{
ESTAT 5 ACCERR 1 PVIOL; // clear error flag
if(!(ESTAT&CBEIF))
return 1;
*ptr 5 data;
// write data to word-aligned address
ECMD 5 Program;
// write program command
ESTAT 5 CBEIF;
// launch command
if(ESTAT &(ACCERR|PVIOL))
return 1;
while(!(ESTAT&CCIF));
// wait for command to complete
return 0;
}
Example 14.14
Write a function that executes the sector-modify command to change the contents of an
EEPROM sector. The index register X holds the word-aligned address of the first EEPROM word
to be modified. The index register Y holds the word-aligned address of the first word of data to
be programmed.
Solution: The assembly function that performs the desired function is as follows:
eesectormodify
movb
#ACCERR 1 PVIOL,ESTAT
; clear error flags
brclr
ESTAT,CBEIF,cantmod
; command buffer not empty
movw
0,Y,0,X
; write data to EEPROM address
movb
#SectorModify,ECMD
; write sector-modify command
movb
#CBEIF,ESTAT
; launch the erase and check command
brclr
ESTAT,ACCERR 1 PVIOL,EEModOK
cantmod
ldab
#1
; return error code 1
rts
 
Search WWH ::




Custom Search