📄 tr220flash.c
字号:
/* common macro & function */
#include "Tr220com.h"
unsigned char ucFlash_Status=0xFF;
/************************************************************************/
/* PROCEDURE: vSST25_Init */
/* */
/* This procedure initializes the SCK to low. Must be called prior to */
/* setting up mode 0. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* SCK */
/************************************************************************/
void vSST25_Init(void)
{
m25VF020_SCK_OFF; /* set clock to low initial state */
asm(" nop ");
asm(" nop ");
asm(" nop ");
asm(" nop ");
asm(" nop ");
asm(" nop ");
}
/************************************************************************/
/* PROCEDURE: vSST25_Send_Byte */
/* */
/* This procedure outputs a byte shifting out 1-bit per clock rising */
/* edge on the the SI pin(LSB 1st). */
/* */
/* Input: */
/* out */
/* */
/* Output: */
/* SI */
/************************************************************************/
void vSST25_Send_Byte(unsigned char out)
{
unsigned char i = 0;
for (i = 0; i < 8; i++)
{
if ((out & 0x80) == 0x80) /* check if MSB is high */
{
m25VF020_SI_ON;
asm(" nop ");
asm(" nop ");
asm(" nop ");
}
else
{
m25VF020_SI_OFF; /* if not, set to low */
asm(" nop ");
asm(" nop ");
asm(" nop ");
}
m25VF020_SCK_OFF; /* toggle clock low */
asm(" nop ");
asm(" nop ");
asm(" nop ");
m25VF020_SCK_ON; /* toggle clock high */
asm(" nop ");
asm(" nop ");
asm(" nop ");
out = (out << 1); /* shift 1 place for next bit */
}
}
/************************************************************************/
/* PROCEDURE: ucSST25_Get_Byte */
/* */
/* This procedure inputs a byte shifting in 1-bit per clock falling */
/* edge on the SO pin(LSB 1st). */
/* */
/* Input: */
/* SO */
/* */
/* Output: */
/* None */
/************************************************************************/
unsigned char ucSST25_Get_Byte(void)
{
unsigned char i = 0, in = 0xff;
for (i = 0; i < 8; i++)
{
m25VF020_SCK_OFF; /* toggle clock low */
asm(" nop ");
asm(" nop ");
asm(" nop ");
in = (in << 1); /* shift 1 place to the left or shift in 0 */
asm(" mvmd SPSD1,_iBsp1_in ");
if((m25VF020_Data_In)==0x00)in=in & 0xfe;
else in=in | 0x01;
asm(" nop ");
asm(" nop ");
asm(" nop ");
m25VF020_SCK_ON; /* toggle clock high */
asm(" nop ");
asm(" nop ");
asm(" nop ");
}
in=in & 0xff; // Add by zhx to meet the char is 16bit character 040730
return in;
}
/************************************************************************/
/* PROCEDURE: vSST25_CE_High */
/* */
/* This procedure set CE = High. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* CE */
/* */
/************************************************************************/
void vSST25_CE_High(void)
{
m25VF020_CS_ON; /* set CE high */
}
/************************************************************************/
/* PROCEDURE: vSST25_CE_Low */
/* */
/* This procedure drives the CE of the device to low. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* CE */
/* */
/************************************************************************/
void vSST25_CE_Low(void)
{
m25VF020_CS_OFF; /* clear CE low */
asm(" nop ");
}
/************************************************************************/
/* PROCEDURE: Read_Status_Register */
/* */
/* This procedure read the status register and returns the byte. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* byte */
/************************************************************************/
unsigned char Read_Status_Register(void)
{
unsigned char byte = 0;
vSST25_CE_Low(); /* enable device */
vSST25_Send_Byte(0x05); /* send RDSR command */
byte = ucSST25_Get_Byte(); /* receive byte */
vSST25_CE_High(); /* disable device */
return byte;
}
/************************************************************************/
/* PROCEDURE: EWSR */
/* */
/* This procedure Enables Write Status Register. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
void EWSR(void)
{
vSST25_CE_Low(); /* enable device */
vSST25_Send_Byte(0x50); /* enable writing to the status register */
vSST25_CE_High(); /* disable device */
}
/************************************************************************/
/* PROCEDURE: WRSR */
/* */
/* This procedure writes a byte to the Status Register. */
/* */
/* Input: */
/* byte */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
void WRSR(unsigned char byte)
{
vSST25_CE_Low(); /* enable device */
vSST25_Send_Byte(0x01); /* select write to status register */
vSST25_Send_Byte(byte); /* data that will change the status of BPx
or BPL (only bits 2,3,7 can be written) */
vSST25_CE_High(); /* disable the device */
Wait_Busy();
}
/************************************************************************/
/* PROCEDURE: WREN */
/* */
/* This procedure enables the Write Enable Latch. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
void WREN(void)
{
vSST25_CE_Low(); /* enable device */
vSST25_Send_Byte(0x06); /* send WREN command */
vSST25_CE_High(); /* disable device */
}
/************************************************************************/
/* PROCEDURE: WRDI */
/* */
/* This procedure disables the Write Enable Latch. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
/************************************************************************/
/* PROCEDURE: Read_ID */
/* */
/* This procedure Reads the manufacturer's ID and device ID. It will */
/* use 90h or ABh as the command to read the ID (90h in this sample). */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -