目标:在0x0E区域写入0x20,在0x2E区域写入0x21,在0x4E区域写入0x22 先放效果图: 断电后,将写入程序删掉,再上电: 代码部分: 首先本代码依据赛元官方DEMO代码所作修改,官方地址:赛元芯片官方DEMO
main函数部分
#include "H/Function_Init.H"
#include "stdio.h"
#define Test 5
extern uchar IapReadData;
void main(void)
{
IO_Init();
WDTCON |= 0x10;
Uart0_Init();
printf("Write Data:\r\n0x0E->0x20\r\n0x2E->0x21\r\n0x4E->0x22\r\n");
IAPWrite(0x0E,0x20,IapEPPROM);
IAPWrite(0x2E,0x21,IapEPPROM);
IAPWrite(0x4E,0x22,IapEPPROM);
printf("waiting...\r\n");
IapReadData = IAPRead(0x0E,IapEPPROM);
IAPADE = 0x00;
printf("Read 0x0E Data:%x\r\n",IapReadData);
IapReadData = IAPRead(0x2E,IapEPPROM);
IAPADE = 0x00;
printf("Read 0x2E Data:%x\r\n",IapReadData);
IapReadData = IAPRead(0x4E,IapEPPROM);
IAPADE = 0x00;
printf("Read 0x4E Data:%x\r\n",IapReadData);
switch(Test)
{
case 0: BTM_Test();
break;
case 1: EXTI_Test();
break;
case 2: Timer_Test();
break;
case 3: LCD_Test();
break;
case 4: PWM_Test();
break;
case 5:
break;
case 7: ADC_Test();
break;
case 8:
break;
default:
break;
}
}
IAP_INIT部分:
#include "H/Function_Init.H"
unsigned char code *IapAddr = 0x00;
void IAPWrite(uint Addr,uchar Value,uchar IAPArea);
uchar IAPRead(uint Addr,uchar IAPArea);
uchar IapReadData = 0x00;
void IAP_Test(uint Address,uchar IAPArea)
{
IAPWrite(Address,0xff,IAPArea);
IapReadData = IAPRead(Address,IAPArea);
IAPADE = 0x00;
while(1)
{
if(IapReadData == 0xff)
{
P20 = ~P20;
}
else
{
P21 = ~P21;
}
}
}
void IAPWrite(uint Addr,uchar Value,uchar IAPArea)
{
EA = 0;
IAPDAT = Value;
IAPADH = ((Addr>>8)&0X7F);
IAPADL = Addr;
IAPADE = IAPArea;
IAPKEY = 240;
IAPCTL = 0x06;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
IAPADE = 0x00;
EA = 1;
}
uchar IAPRead(uint Addr,uchar IAPArea)
{
uchar ReadValue = 0x00;
EA = 0;
IAPADE = IAPArea;
ReadValue = *(IapAddr+Addr);
IAPADE = 0x00;
EA = 1;
return ReadValue;
}
function_INIT部分:
#ifndef _Function_Init_H_
#define _Function_Init_H_
#include "SC92F732x_C.H"
#include "intrins.H"
#define uchar unsigned char
#define uint unsigned int
#define IapROM 0x00
#define IapEPPROM 0x02
extern void IO_Init(void);
extern void BTM_Test(void);
extern void EXTI_Test(void);
extern void Timer_Test(void);
extern void LCD_Test(void);
extern void PWM_Test(void);
extern void ADC_Test(void);
extern void IAP_Test(uint Address,uchar IAPArea);
void Uart0_Init(void);
void UartSendBit(unsigned char c);
void IAPWrite(uint Addr,uchar Value,uchar IAPArea);
uchar IAPRead(uint Addr,uchar IAPArea);
#define SC92F7323 0
#define SC92F7322 1
#define SC92F7321 2
#define SC92F7320 3
#define IC_MODEL SC92F7321
#endif
|