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

📄 v3k_fram_use_example_sdcc.c

📁 这是ramtron公司的铁电单片机的开发程序
💻 C
字号:
//-------------------------------------------------------------------------------------------------------//
// V3K_FRAM_Use_Example_SDCC.c  //
//------------------------------//
//
// This program show how to perform the following operations:
//
// -Enables the FRAM memory
// -Deactivate the FRAM protection (This step is optional)
// -Fill the FRAM with 0x55
// -Read FRAM address 0x8100
// -Write 0x23 at FRAM address 0x8100
// -Read Content of address 0x8100 
// - Activate FRAM Write Protect
// -"Try" clearing the (protected) FRAM 
// -Deactivate the FRAM protection
// -Clear the FRAM
// -Show how to Read the FRAM Block protect configuration
//
// Rev 1.0	
// www.ramtron.com
//-------------------------------------------------------------------------------------------------------//
#include <VRS51L3074_SDCC.h>


//--Init pointer to FRAM base address
xdata at 0x8000 unsigned char frambase;				//Init  a char variable pointing to FRAM
xdata unsigned char * data framptr = &frambase ;		//Init a pointer in IRAM pointing to the frambase var.


//-----------------------------------------//
//             MAIN FUNCTION               //
//-----------------------------------------//
 void main (void){
	volatile idata int  cptr= 0x00;					   //general purpose counter
	volatile idata char framread = 0x00;
	
	DEVMEMCFG  |= 0xC0;					     //Activate the FRAM

//-- Deactivate FRAM Write Protect (Not needed if FRAM not initialy protected)
	FRAMCFG1 = 0x01;						//Set FRAMWEL = 1 Enable Write  (FRAMOP = 00)
	while(!(FRAMCFG1&0x80));					//Wait FREADIDLE == 1  (FRAM IDLE)

	FRAMCFG2 = 0x00;						//Configure FRAMCFG2 to remove FRAM content Protection 
	FRAMCFG1 = 0x07;						//Execute Transfert of FRAMCFG2 module to FRAM Module
	while(!(FRAMCFG1&0x80));					//Wait FREADIDLE == 1  (FRAM IDLE)

	FRAMCFG1 = 0x03;						//Disable the write operations 
                                                  //from FRAMCFG2 to the FRAM Module
	while(!(FRAMCFG1&0x80));					//Wait FREADIDLE == 1  (FRAM IDLE)
	

//--Fill the FRAM with 0x55
	for(cptr = 0; cptr < 0x2000; cptr++)
  		*(framptr+cptr) = 0x55;


//--Read Content of address 0x8100 and place it into framread 
		framread = *(framptr + 0x0100);         //framread will contain 0x55
				
//--Write 0x23 at address 0x8100 in FRAM (offset of 0x0100)
		*(framptr + 0x0100) = 0x23;

//--Read Content of address 0x8100 and place it into framread
		framread = *(framptr + 0x0100);        //framread will contain 0x23
          framread = *(framptr + 0x0101);         //framread will contain 0x55

	
//-- Activate FRAM Write Protect

	FRAMCFG1 = 0x01;						//Set FRAMWEL = 1 Enable Write  (FRAMOP = 00)
	while(!(FRAMCFG1&0x80));					//Wait FREADIDLE == 1  (FRAM IDLE)

	FRAMCFG2 = 0x0C;						//Configure FRAMCFG2 to protect the entire FRAM

	FRAMCFG1 = 0x07;						//Execute Transfert of FRAMCFG2 module to FRAM Module
	while(!(FRAMCFG1&0x80));					//Wait FREADIDLE == 1  (FRAM IDLE)

	FRAMCFG1 = 0x03;						//Clear FRAMWEL (FRAMOP = 01)
	while(!(FRAMCFG1&0x80));					//Wait FREADIDLE == 1  (FRAM IDLE)




//--Clear the FRAM content (will not work if FRAM protected)
	for(cptr = 0; cptr < 0x2000; cptr++)
  		*(framptr+cptr) = 0x00;		

//-- Deactivate FRAM Write Protect (Not needed if FRAM not initialy protected)
	FRAMCFG1 = 0x01;						//Set FRAMWEL = 1 Enable Write  (FRAMOP = 00)
	while(!(FRAMCFG1&0x80));					//Wait FREADIDLE == 1  (FRAM IDLE)

	FRAMCFG2 = 0x00;						//Configure FRAMCFG2 to remove FRAM content Protection 
	FRAMCFG1 = 0x07;						//Execute Transfert of FRAMCFG2 module to FRAM Module
	while(!(FRAMCFG1&0x80));					//Wait FREADIDLE == 1  (FRAM IDLE)

	FRAMCFG1 = 0x03;						//Disable the write operations 
                                                  //from FRAMCFG2 to the FRAM Module
	while(!(FRAMCFG1&0x80));					//Wait FREADIDLE == 1  (FRAM IDLE)
		
//--Clear the FRAM content (Will work unless FRAM is configured as Read Only at programming time )
	for(cptr = 0; cptr < 0x2000; cptr++)
  		*(framptr+cptr) = 0x00;		
	

	while(1);

//--Optional Read of the FRAM Block protect configuration
	//FRAMCFG1 = 0x05;						//read FRAMCFG2
	//while(!(FRAMCFG1&0x80));				//Wait FREADIDLE == 1  (FRAM IDLE)
	//x = FRAMCFG2							//Read the FRAMCFG2 register

	//(...)




}//end of Main






⌨️ 快捷键说明

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