⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 周立功2103开发板CD资料
💻 C
字号:
#define IN_MAIN
#include "config.h"
#include "IAP.h"

#pragma import(__use_no_semihosting_swi)        //don't delete this line

#define		BEEP	(1<<7)
/*********************************************************************************************************
** Function name:	IRQ_Exception
** Descriptions:	interrupt exceptional handler , change it as needed
**					don't delete this function 
********************************************************************************************************/
void  IRQ_Exception(void)
{
}
/*********************************************************************************************************
** 函数名称:	Main()
** 函数功能:	IAP函数测试。
** 说明:		需要将JP9跳线短接。
********************************************************************************************************/
void Main(void)
{
	uint8	*point;
	uint32	i;
	uint32	rcv_back[8];
    TargetInit(VPBDIV_DATA, PLLCFG_DATA, MAMTIM_DATA);      // don't delete
	while((PLLSTAT & (1 << 10)) == 0);                      // can delete
    
	IO0DIR = BEEP;
	IO0SET = BEEP;
	ReadParID(rcv_back);
	BootCodeID(rcv_back);   
   
	point = (uint8 *)0x40001000;	//初始化RAM中的数据
	for(i=0;i<512;i++)
	{
		*point++ = 0x55;
	}
 //先写入0x55
 	if(WriteFlash(0x00002000,0x40001000,512) != 0)	//写数据到扇区1 
	{
 		IO0CLR = BEEP;				//如果出错,则蜂鸣器一直鸣叫
  		while(1);
	}
	if(Compare(0x00002000, 0x40001000, 512) != 0)    // 比较数据
	{
 		IO0CLR = BEEP;
  		while(1);
	}
	point = (uint8 *)0x00002000;
	for(i=0;i<512;i++)				//直接读取FLASH中的数据,判断写入数据的准确性
	{
		if(*point++ != 0x55)
		{
			IO0CLR = BEEP;			//如果出错,则蜂鸣器一直鸣叫
			while(1);
		}
	}

 //再写入0xaa 
	point = (uint8 *)0x40001000;	//更新RAM中的数据
	for(i=0;i<512;i++)
	{
		*point++ = 0xaa;
	}
 	if(WriteFlash(0x00002000,0x40001000,512) != 0)	//写数据到扇区1 
	{
 		IO0CLR = BEEP;				//如果出错,则蜂鸣器一直鸣叫
  		while(1);
	}
	
	if(Compare(0x00002000, 0x40001000, 512) != 0)    // 利用IAP提供的比较命令
	{
		IO0CLR = BEEP;				//如果出错,则蜂鸣器一直鸣叫
			while(1);
	}
	point = (uint8 *)0x00002000;
	for(i=0;i<512;i++)				//直接读取FLASH中的数据,判断写入数据的准确性
	{
		if(*point++ != 0xaa)		//如果写入出错,则蜂鸣器一直鸣叫
		{
			IO0CLR = BEEP;
			while(1);
		}
	}   
  	/*成功,蜂鸣一声*/
	IO0CLR = BEEP;
	for(i=0;i<800000;i++);
	IO0SET = BEEP;
	while(1);
}
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -