?? iap.h
字號(hào):
#include <reg52.h>
#include <intrins.h> /* use _nop_() function */
/* 新增特殊功能寄存器定義 */
sfr ISP_DATA = 0xe2; /* ISP_DATA DATA 0E2H; 匯編程序定義 or EQU */
sfr ISP_ADDRH = 0xe3; /* ISP_ADDRH DATA 0E3H; 匯編程序定義 */
sfr ISP_ADDRL = 0xe4; /* ISP_ADDRL DATA 0E4H; 匯編程序定義 */
sfr ISP_CMD = 0xe5; /* ISP_CMD DATA 0E5H; 匯編程序定義 */
sfr ISP_TRIG = 0xe6; /* ISP_TRIG DATA 0E6H; 匯編程序定義 */
sfr ISP_CONTR = 0xe7; /* ISP_CONTR DATA 0E7H; 匯編程序定義 */
/* SFR: ISP_DATA (ISP Flash Data Register): E2H ------------------------*/
/*--| b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |---*/
/*--| Data to be written into flash, or Data got from flash |---*/
/* SFR: ISP_ADDRH (ISP Flash Address High): E3H --------------------*/
/*--| b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |---*/
/*--| High byte of the address pointing to flash |---*/
/* SFR: ISP_ADDRL (ISP Flash Address Low): E4H --------------------*/
/*--| b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |---*/
/*--| Low byte of the address pointing to flash |---*/
/* SFR: ISP_CMD (ISP Flash Mode Table): E5H --------------------*/
/*--| b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |---*/
/*--| reserved | Mode Selection |---*/
//0 0 0-none,0 0 1-read,0 1 0-wtire,0 1 1-erase
/* SFR: ISP_TRIG (Sequential Command Data register for ISP): E6H ----*/
/*--| b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |---*/
/*--| ISP-Command |---*/
// -> 0x46 -> 0xb9
/* SFR: ISP_CONTR (ISP Control register): E7H --------------------*/
/*--| b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |---*/
/*--| ISPEN | SWBS | SWRST | - | - | WAIT |---*/
/*-- ISPEN: ISP function enabling bit ----------------*/
/*-- 0: Disable ISP program to change flash ----------------*/
/*-- 1: Enable ISP program to change flash ----------------*/
/*-- SWBS: Secondary Booting program selecting ----------------*/
/*-- 0: Boot from AP-Memory / Main-Memory ----------------*/
/*-- 1: Boot from ISP-Memory ----------------*/
/*-- SWRST: Software reset trigger ----------------*/
/*-- 0: No operation ----------------*/
/*-- 1: Generate software system reset. It will be cleared by hardware automatically ---*/
/* 定義命令 */
#define READ_Command 0x01 /* 字節(jié)讀應(yīng)用程序區(qū)和數(shù)據(jù)存儲(chǔ)區(qū) */
#define PROGRAM_Command 0x02 /* 字節(jié)編程應(yīng)用程序區(qū)和數(shù)據(jù)存儲(chǔ)區(qū) */
#define ERASE_Command 0x03 /* 扇區(qū)擦除應(yīng)用程序區(qū)和數(shù)據(jù)存儲(chǔ)區(qū) */
typedef unsigned char INT8U; /* 8 bit 無符號(hào)整型 */
typedef unsigned int INT16U; /* 16 bit 無符號(hào)整型 */
#define DELAY_CONST 60000
/* 定義常量 */
#define ERROR 0 //錯(cuò)誤
#define OK 1 //正確
/* 定義Flash 操作等待時(shí)間 */
//#define MCU_CLOCK_40MHz
//#define MCU_CLOCK_20MHz
#define MCU_CLOCK_10MHz
//#define MCU_CLOCK_5MHz
#ifdef MCU_CLOCK_40MHz
#define WAIT_TIME 0x00
#endif
#ifdef MCU_CLOCK_20MHz
#define WAIT_TIME 0x01
#endif
#ifdef MCU_CLOCK_10MHz
#define WAIT_TIME 0x02
#endif
#ifdef MCU_CLOCK_5MHz
#define WAIT_TIME 0x03
#endif
/* 調(diào)試控制項(xiàng) */
//#define DEBUG_STC89C_LE516RD
//#define DEBUG_STC89C_LE58RD
#define DEBUG_STC89C_LE54RD
//#define DEBUG_STC89C_LE53RC
//#define DEBUG_STC89C_LE52RC
//#define DEBUG_STC89C_LE51RC
//#define USED_BYTE_QTY_IN_ONE_SECTOR 1
//#define USED_BYTE_QTY_IN_ONE_SECTOR 2
//#define USED_BYTE_QTY_IN_ONE_SECTOR 4
//#define USED_BYTE_QTY_IN_ONE_SECTOR 8
//#define USED_BYTE_QTY_IN_ONE_SECTOR 16
//#define USED_BYTE_QTY_IN_ONE_SECTOR 32
//#define USED_BYTE_QTY_IN_ONE_SECTOR 64
#define USED_BYTE_QTY_IN_ONE_SECTOR 128
//#define USED_BYTE_QTY_IN_ONE_SECTOR 256
//#define USED_BYTE_QTY_IN_ONE_SECTOR 512
//INT8U xdata protect_buffer[USED_BYTE_QTY_IN_ONE_SECTOR];
#ifdef DEBUG_STC89C_LE516RD //STC89C516RD+, 89LE516RD+
#define DEBUG_AP_Memory_Begin_Sector_addr 0x0000
#define DEBUG_AP_Memory_End_Sector_addr 0xf600
#define DEBUG_AP_Memory_End_Byte_addr 0xf7ff
#endif
#ifdef DEBUG_STC89C_LE58RD //STC89C58RD+, 89LE58RD+
#define DEBUG_AP_Memory_Begin_Sector_addr 0x0000
#define DEBUG_AP_Memory_End_Sector_addr 0x7e00
#define DEBUG_AP_Memory_End_Byte_addr 0x7fff
#define DEBUG_Data_Memory_Begin_Sector_addr 0x8000
#define DEBUG_Data_Memory_End_Sector_addr 0xf600
#define DEBUG_Data_Memory_End_Byte_addr 0xf7ff
#endif
#ifdef DEBUG_STC89C_LE54RD //STC89C54RD+, 89LE54RD+
#define DEBUG_AP_Memory_Begin_Sector_addr 0x0000
#define DEBUG_AP_Memory_End_Sector_addr 0x3e00
#define DEBUG_AP_Memory_End_Byte_addr 0x3fff
#define DEBUG_Data_Memory_Begin_Sector_addr 0x8000
#define DEBUG_Data_Memory_End_Sector_addr 0xf000
#define DEBUG_Data_Memory_End_Byte_addr 0xf2ff
// #define DEBUG_Data_Memory_End_Sector_addr 0xf600
// #define DEBUG_Data_Memory_End_Byte_addr 0xf7ff
#endif
#ifdef DEBUG_STC89C_LE53RC //STC89C53RC, 89LE53RC
#define DEBUG_AP_Memory_Begin_Sector_addr 0x0000
#define DEBUG_AP_Memory_End_Sector_addr 0x3600
#define DEBUG_AP_Memory_End_Byte_addr 0x37ff
#endif
#ifdef DEBUG_STC89C_LE52RC //STC89C52RC, 89LE52RC
#define DEBUG_AP_Memory_Begin_Sector_addr 0x0000
#define DEBUG_AP_Memory_End_Sector_addr 0x1e00
#define DEBUG_AP_Memory_End_Byte_addr 0x1fff
#define DEBUG_Data_Memory_Begin_Sector_addr 0x2000
#define DEBUG_Data_Memory_End_Sector_addr 0x2e00
#define DEBUG_Data_Memory_End_Byte_addr 0x2fff
// #define DEBUG_Data_Memory_End_Sector_addr 0x3600
// #define DEBUG_Data_Memory_End_Byte_addr 0x37ff
#endif
#ifdef DEBUG_STC89C_LE51RC //STC89C51RC, 89LE51RC
#define DEBUG_AP_Memory_Begin_Sector_addr 0x0000
#define DEBUG_AP_Memory_End_Sector_addr 0x0e00
#define DEBUG_AP_Memory_End_Byte_addr 0x0fff
#define DEBUG_Data_Memory_Begin_Sector_addr 0x1000
#define DEBUG_Data_Memory_End_Sector_addr 0x1e00
#define DEBUG_Data_Memory_End_Byte_addr 0x1fff
// #define DEBUG_Data_Memory_End_Sector_addr 0x3600
// #define DEBUG_Data_Memory_End_Byte_addr 0x37ff
#endif
/* 測(cè)試常量數(shù)組 */
INT8U sector_erase(INT16U sector_addr); //扇區(qū)擦除
INT8U Byte_flash(INT16U byte_addr, INT8U original_data); //字節(jié)編程并校驗(yàn)
/* 寫數(shù)據(jù)進(jìn)數(shù)據(jù)Flash存儲(chǔ)器, 只在同一個(gè)扇區(qū)內(nèi)寫,不保留原有數(shù)據(jù) */
/* begin_addr,被寫數(shù)據(jù)Flash開始地址;counter,連續(xù)寫多少個(gè)字節(jié); array[],數(shù)據(jù)來源 */
INT8U Sequential_write_flash(INT16U begin_addr, INT16U counter, INT8U array[]);
/* 寫數(shù)據(jù)進(jìn)數(shù)據(jù)Flash存儲(chǔ)器(EEPROM), 只在同一個(gè)扇區(qū)內(nèi)寫,保留同一扇區(qū)中不需修改的數(shù)據(jù) */
/* begin_addr,被寫數(shù)據(jù)Flash開始地址;counter,連續(xù)寫多少個(gè)字節(jié); array[],數(shù)據(jù)來源 */
INT8U Write_flash(INT16U begin_addr, INT16U counter, INT8U array[]);
INT8U Read_flash(INT16U begin_addr, INT16U counter, INT8U array[]); //讀FLASH
void delay(INT16U counter); //延時(shí)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -