while(--i) ;
}while(--ms);
}
//Read EEPROM using MOVC
void EEPROM_MOVC_read_n(u16 EE_address, u8 *DataAddress, u16 number)
{
u8 code *pc;
pc = EE_address + EEADDR_OFFSET;
do
{
*DataAddress = *pc; //Data be read
DataAddress++;
pc++;
}while(--number);
}
/********************* main function *************************/
void main(void)
{
u8 i;
u16 addr;
UART1_config(); // select baud rate, 2: Use Timer2 as baud rate generator,
//Other values: Use Timer1 as baud rate generator,
EA = 1; //Enable CPU interrupt
PrintString1("STC8 familyMCU
用串口
1
测试
EEPROM
程序
!\r\n"); //UART1send a string
while(1)
{
delay_ms(1);
if(RX1_TimeOut > 0) //timeout count
{
if(--RX1_TimeOut == 0)
{
if(RX1_Buffer[1] == ' ')
{
addr = GetAddress();
if(addr < 63488) //Limited to sectors 0~123
{
if(RX1_Buffer[0] == 'E') //PC requests to erase a sector
{
EEPROM_SectorErase(addr);
PrintString1("
扇区擦除完成
!\r\n");
}
else if(RX1_Buffer[0] == 'W') //PC request to write 64 bytes data to EEPROM
{
EEPROM_write_n(addr,T_Strings,64);
PrintString1("
写入操作完成
!\r\n");
}
else if(RX1_Buffer[0] == 'R') //PC requests to return 64 bytes of EEPROM data
{
PrintString1("IAPData be read
如下:
\r\n");
EEPROM_read_n(addr,tmp,64);