下面是CYPRESS 68013上的一个读写samsung K9F1G的例子程序,
说明:程序针对mcu:cypress 68013,flash:samsung k9f1g08u,MCU运行于48M,对于其它频率,一些时序常数可能需要修改.程序实现了FLASH的CLEAR,WRITE,READ基本操作.
/******************************************************************/
/*AC Timing Characteristics define for Command / Address / Data Input
/*for cpu frequency 48MHZ,
/******************************************************************/
#define TDS 130
#define TDH 125
#define TWHR 300
/******************************************************************/
//IO PORT MAP
#define POW_LED PD1
#define RUN_LED PD2
//flash control line map
#define SIG_CEn PA4 //o
#define SIG_WEn PA1 //o
#define SIG_REn PA5 //o
#define SIG_CLEp PA3 //o
#define SIG_ALEp PA2 //o
#define SIG_RB PA6 //i
#define SIG_WP PA0 //o
#define SIG_DATA IOB //data bus
#define SIG_DATA_DIR OEB
#define SIG_CON_DIR OEA
#define SIG_LED_DIR OED
#define init_con_io() {SIG_CON_DIR=0xbf;SIG_WP=0x1;SIG_LED_DIR=0XFF;}
/*some macro define
#define LATCH_DATA(LATCH,dataa) {if(LATCH){SIG_DATA_DIR=0xff;SIG_DATA=dataa;}\
else {SIG_DATA_DIR=0x00;dataa=SIG_DATA;}}
#define SIG_INVALIDATE() {SIG_CEn=SIG_WEn=SIG_REn=HIGH;\
SIG_CLEp=SIG_ALEp=LOW; }
#define SIGNAL_SETUP(x) {unsigned char i;for(i=x;i>0;i--)_nop_( );}
#define SIGNAL_HOLD(x) {unsigned char i;for(i=x;i>0;i--)_nop_( );}
/******************************************************************/
/*function: a Command Latch Cycle
/*input: comm: commamd no.
/******************************************************************/
void ss_comm_latch(unsigned char comm,unsigned char wait)
{
SIG_ALEp=SIG_CEn=SIG_WEn=LOW;
SIG_CLEp=HIGH;
SIG_REn=HIGH;
LATCH_DATA(1,comm);
SIGNAL_SETUP(TDS); //tds
SIG_WEn=HIGH;
if(wait)while(SIG_RB);
SIGNAL_HOLD(TDH); //tdh
SIG_INVALIDATE();
}
/******************************************************************/
/*function: Address Latch Cycle
/*input: addr: addr no.
/******************************************************************/
void ss_addr_latch(unsigned char addr)
{
SIG_CLEp=SIG_CEn=SIG_WEn=LOW;
SIG_ALEp=SIG_REn=HIGH;
LATCH_DATA(1,addr);
SIGNAL_SETUP(TDS); //tals
SIG_WEn=HIGH;
SIGNAL_HOLD(TDH); //twh
SIG_INVALIDATE();
}
/******************************************************************/
/*function: Input Data Latch Cycle
/*input: dat: input DATA
/******************************************************************/
void ss_data_latch(unsigned char dat)
{
SIG_ALEp=SIG_CLEp=SIG_CEn=SIG_WEn=LOW;
SIG_REn=HIGH;
LATCH_DATA(1,dat);
SIGNAL_SETUP(TDS); //tds tcs
SIG_WEn=HIGH;
SIGNAL_HOLD(TDH); //tdh,tch
SIG_INVALIDATE();
}
/******************************************************************/
/*function: Serial Access Cycle after Read
/*input: wait: if wait R/B pin
/******************************************************************/
unsigned char ss_serial_acess(unsigned char wait)
{
unsigned char rddata;
if(wait)
while(!SIG_RB); //trr
SIG_CLEp=SIG_ALEp=SIG_REn=SIG_CEn=LOW;
SIG_WEn=HIGH;
SIGNAL_SETUP(TDS); //trea
LATCH_DATA(0,rddata);
SIG_REn=HIGH;
SIGNAL_HOLD(TDH); //treh
SIG_INVALIDATE();
return rddata;
}
/******************************************************************/
/*function: Status Read Cycle
/*input: wait: if wait R/B pin
/******************************************************************/
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |