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

📄 isp.c

📁 SM5964在系统编程的源代码,通过COMM串行口进行程序下载,方便嵌入式系统开发
💻 C
字号:
#include "main.h"
#include "isp.h"
#include <intrins.h>

#define NOP _nop_()

void ChipErase();
void PageErase(unsigned char pageNo);
void SetChipProtect();
void ChipWrite(unsigned int addr,unsigned char chValue);
unsigned char ChipRead(unsigned int addr);

/////////////////////////////////////////////////////////
void ChipErase()
{
	
	WatchDog();

	#ifdef MY_DEBUG
	SCONF	=VALUE_SCONF;//允许IPSE OME 
	ISPFD	=0x55;
	ISPFD	=0xaa;
	ISPFD	=0x55;	
	#endif


	ISPC	=0x83;

	WatchDog();	
	
}

//页擦除512字节
void PageErase(unsigned char pageNo)
{
	
	unsigned char temp;
	unsigned int  addr;

	//$XY00 to $X(Y+1)FF (Y:even number), or
	//$X(Y-1) 00 to $XYFF (Y:odd number)

	WatchDog();

	#ifdef MY_DEBUG
	SCONF	=VALUE_SCONF;//允许IPSE OME 
	ISPFD	=0x55;
	ISPFD	=0xaa;
	ISPFD	=0x55;
	#endif

	
	addr=pageNo;
	addr*=512;
	

	temp=((addr>>8)&0xff);
	ISPFAH	=temp;
	temp=(addr & 0xff);
	ISPFAL	=addr & 0xff;
	

	ISPC	=0x82;

	WatchDog();


}

void SetChipProtect()
{

	#ifdef MY_DEBUG
	SCONF	=VALUE_SCONF;//允许IPSE OME 
	ISPFD	=0x55;
	ISPFD	=0xaa;
	ISPFD	=0x55;
	#endif
	
	ISPC	=0x81;

}




/*
**************************************************************
MOV SCONF,#04H ; enable SM5964 ISP function
MOV ISPFAH,#10H ; set flash address-high, 10H
MOV ISPFAL,#05H ; set flash address-low, 05H
MOV ISPFD,#22H ; set flash data to be programmed, data = 22H
MOV ISPC,#80H ; start to program #22H to the flash address $1005H
; after byte program finished, START bit of ISPC will be reset to 0 automatically
; program counter then point to the next instruction
**************************************************************
*/
void ChipWrite(unsigned int addr,unsigned char chValue)
{
	
	unsigned char temp;
	
	#ifdef MY_DEBUG
	SCONF	=VALUE_SCONF;//允许IPSE OME 
	ISPFD	=0x55;
	ISPFD	=0xaa;
	ISPFD	=0x55;
	#endif
	

	
		
	temp=((addr>>8)&0xff);
	ISPFAH	=temp;

	temp=(addr & 0xff);
	ISPFAL	=temp;


	temp=chValue;
	ISPFD	=temp;

	ISPC	=0x80;		


}

unsigned char ChipRead(unsigned int addr)
{
	unsigned char temp;

	unsigned char code *pt;


	pt=addr;

	temp=*pt;


	return temp;
}


⌨️ 快捷键说明

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