📄 __flash.c
字号:
//===================================================================//
// Project Name : ZBoard
// Module Name : Master Firmware Program
// Product Type : License
// OS/Dev Tool : At89C52, uVision 2
// Original Author : Ray Yang
// Organization : YBWork.com
// Original Date : July, 25, 2001
// Addr : Room 402, No. 131, Meilong No. 9
// TEL : 86-21-54630718
// EMail : rayyang2000@yahoo.com
// Website : http://www.ybwork.com
// Copyright : Copyright (L) YBWork.com, 2001
// Comments :
//
// << History >>
// July, 25, 2001 The first release
//===================================================================//
#include "FLASH.H"
#include "HAL.H"
#include "USBD12.H"
#include "VDOR.H"
extern unsigned char idata GenBuf[GENBUF_LENGH];
extern CODE_DATA idata CodeData;
void FlashDisableSDP(void)
{
// 1st command
outportb(0x5555, 0xaa);
// 2nd command
outportb(0x2aaa, 0x55);
// 3th command
outportb(0x5555, 0x80);
// 4th command
outportb(0x5555, 0xaa);
// 5th command
outportb(0x2aaa, 0x55);
// 6th command
outportb(0x5555, 0x20);
}
void FlashGetSPMI(unsigned char nMID, unsigned char nDID)
{
ENABLE_FLASH;
// 1st command
outportb(0x5555, 0xaa);
// 2nd command
outportb(0x2aaa, 0x55);
// 3th command
outportb(0x5555, 0x90);
// Pause 10 ms
DelayMs(10);
// Get manufaturer code
nMID = inportb(0);
// Get device ID code
nDID = inportb(1);
// 4th command
outportb(0x5555, 0xaa);
// 5th command
outportb(0x2aaa, 0x55);
// 6th command
outportb(0x5555, 0xf0);
// Pause 10 ms
DelayMs(10);
DISABLE_FLASH;
}
void FlashCHipErase(void)
{
DISABLE_FLASH;
// Pause
Delay(10);
// 1st 0xaa -> 0x5555
ENABLE_FLASH;
outportb(0x5555, 0xaa);
DISABLE_FLASH;
// 2nd 0x55 -> 0x2aaa
ENABLE_FLASH;
outportb(0x2aaa, 0x55);
DISABLE_FLASH;
// 3rd 0x80 -> 0x5555
ENABLE_FLASH;
outportb(0x5555, 0x80);
DISABLE_FLASH;
// 4th 0xaa -> 0x5555
ENABLE_FLASH;
outportb(0x5555, 0xaa);
DISABLE_FLASH;
// 5th 0x55 -> 0x2aaa
ENABLE_FLASH;
outportb(0x2aaa, 0x55);
DISABLE_FLASH;
// 6th 0x10 -> 0x5555
ENABLE_FLASH;
outportb(0x5555, 0x10);
DISABLE_FLASH;
// Pause 20 ms
DelayMs(20);
}
unsigned char FlashWrite(unsigned char idata* pSrc, unsigned char xdata* pDst, unsigned char nLen)
{
unsigned char i, j;
// performs 3 steps of SDP sequence
// 1st 0xaa -> 0x5555
ENABLE_FLASH;
outportb(0x5555, 0xaa);
DISABLE_FLASH;
// 2nd 0x55 -> 0x2aaa
ENABLE_FLASH;
outportb(0x2aaa, 0x55);
DISABLE_FLASH;
// 3rd 0xa0 -> 0x05555
ENABLE_FLASH;
outportb(0x5555, 0xa0);
DISABLE_FLASH;
// First, Write every bytes in GenBuf to the flash
for(i=0; i<nLen; i++)
{
ENABLE_FLASH;
outportb(pDst + i, *(pSrc + i));
DISABLE_FLASH;
}
// Pause 20 ms for programming cycle
DelayMs(200);
return j;
}
void FlashRead(unsigned char xdata* pSrc, unsigned char idata* pDst, unsigned char nLen)
{
unsigned char i;
ENABLE_FLASH;
for(i=0; i<nLen; i++)
*(pDst + i) = inportb(pSrc + i);
DISABLE_FLASH;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -