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

📄 v3k_fram_uart_demo1_sdcc.c

📁 DEMO程序 单周期8051内核 8K铁电FRAM 56IO 4KRAM 40MIPS
💻 C
📖 第 1 页 / 共 2 页
字号:
//-------------------------------------------------------------------------------------------------------//
// V3K_FRAM_UART_Demo1_SDCC.c    //
//------------------------------//
//
// This program perform the following :
//	-Initialise the UART0 at 115200 (with SOSC = 40MHz)
//	-Enable Timer 0
//	-Enables the FRAM memory
//	-Enables the UART0 RX and INT0 interrupt
//
// Initialize the FRAM as follow:
//	0k-1k:  A,Z,A,Z...
//	1k-2k:  B,Y,B,Y...
//	2k-3k:  C,X,C,X...
//	3k-4k:  D,W,D,W...
//	4k-5k:  E,V,E-V...
//	5k-6k:  F,U,F,U...
//	6k-7k:  G,T,F,U...
//	7k-8k:  H,T,F,U...
//
// Activate FRAM Write Protect
// Try to overwrite FRAM content with ascii 'z' (FRAM block protected so No write occurs)
// Read FRAM content 1 byte every 16 from 0x0000 and  display as Ascii on UART0
//
// The UART and INT0 are configured and the program enters in infinite loop waiting for an interrupt
// As soon as a character is received it is transmitted back on TXD0
// If INT0 is received the program transmit "EXT INT0 received" on TXD0
//
//The program then perform read back of the FRAM memory content and send the result on the UART0
//
// The program also feature a set of extra FRAM interface functions
//
//-------------------------------------------------------------------------------------------------------//
//
//			www.ramtron.com
//
// Rev 		1.0
// Date:       April, 2006
//-------------------------------------------------------------------------------------------------------//

#include <VRS51L3074_SDCC.h>

// --- function prototypes
void txmit0( unsigned char charact);
void uart0config(void);
void bin2bcdser0(unsigned int );
void Uart0HexSer4(int value);
void Uart0HexSer2(char value);
void delay(unsigned int );


//--Fram Function prototype
char ReadFram( int );
void WriteFram( int , char );
void ReadFramUart0( int );
void WriteReadFramUart0( int , char );
void FramProtect(char);
int FramInit(char );

//--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.


//--Message to display on UART0
char msg[] = "FRAM Memory Demo \0";
char msgint0[] = "EXT INT0 received";


//////////////////////////////////////////////////////////////////
///////////////////////  MAIN FUNCTION ///////////////////////////
//////////////////////////////////////////////////////////////////

 void main (void){
	char letter;						//Variable used for FRAM initialization

	int  cptr= 0x00;					//general purpose counter

	PERIPHEN1 = 0x09;					//Enable UART0 + Timer0
	PERIPHEN2 = 0x08;					//Enable IO Ports

	uart0config();						//Configure Uart0

	//--Wait for Character on UART0 interrupt
	// Once a character is received, grab it and send it back

	GENINTEN = 0x02;					//Set the PININTCFG bit before configuring the INT0 pin event
									//This will prevent receiving an inadvertant INT0 interrupt to be triggered
									//at the moment INT0 trigerring event is configured as Rising edge

	INTSRC1 = 0x01;					//INT0 vector source = INT0 pin
	IPINSENS1 = 0x01;					//Set INT0 sensitive on edge(1) or Level(0)
	IPININV1 = 0x00;					//Set INT0 Pin sensitivity on Low Level/Inversion
	INTEN1 = 0x21;						//Enable INT0 (bit0) and UART0 (bit5) Interrupt
	GENINTEN = 0x01;					//Enable Global interrupt

	DEVMEMCFG  |= 0xC0;					//Activate the FRAM


//--Fill first 1K of FRAM with 'A', 'Z' character
	letter = 'A';
	for(cptr = 0; cptr < 0x400; cptr++)
		{
		*(framptr+cptr) = letter;

		if(letter == 'A')
			letter = 'Z';
			else
				letter = 'A';
		}//end of for cptr

//--Fill 1K-2K of FRAM with 'B', 'Y' character
	letter = 'B';
	for(cptr = 0x400; cptr < 0x800; cptr++)
		{
		*(framptr+cptr) = letter;

		if(letter == 'B')
			letter = 'Y';
			else
				letter = 'B';
		}//end of for cptr

//--Fill 2K-3K of FRAM with 'C', 'X' character
	letter = 'C';
	for(cptr = 0x800; cptr < 0xC00; cptr++)
		{
		*(framptr+cptr) = letter;
		if(letter == 'C')
			letter = 'X';
			else
				letter = 'C';
		}//end of for cptr


//--Fill 3K-4K of FRAM with 'D', 'W' character
	letter = 'D';
	for(cptr = 0xC00; cptr < 0x1000; cptr++)
		{
		*(framptr+cptr) = letter;
 		if(letter == 'D')
			letter = 'W';
			else
				letter = 'D';
		}//end of for cptr

//--Fill 4K-5K of FRAM with 'E', 'V' character
	letter = 'E';
	for(cptr = 0x1000; cptr < 0x1400; cptr++)
		{
		*(framptr+cptr) = letter;
 		if(letter == 'E')
			letter = 'V';
			else
				letter = 'E';
		}//end of for cptr

//--Fill 5K-6K of FRAM with 'F', 'U' character
	letter = 'F';
	for(cptr = 0x1400; cptr < 0x1800; cptr++)
		{
		*(framptr+cptr) = letter;
		if(letter == 'F')
			letter = 'U';
			else
				letter = 'F';
		}//end of for cptr

//--Fill 6K-7K of FRAM with 'G', 'T' character
	letter = 'G';
	for(cptr = 0x1800; cptr < 0x1C00; cptr++)
		{
		*(framptr+cptr) = letter;
		if(letter == 'G')
			letter = 'T';
			else
				letter = 'G';
		}//end of for cptr


//--Fill 7K-8K of FRAM with 'H', 'S' character
	letter = 'H';
	for(cptr = 0x1C00; cptr < 0x2000; cptr++)
		{
		*(framptr+cptr) = letter;
		if(letter == 'H')
			letter = 'S';
			else
			     letter = 'H';
		}//end of for cptr

//-- Activate FRAM Write Protect
//	FramProtect(0x03);						//Perform block Protect of all FRAM
/*
	 
//--Try to overwrite FRAM content with ascii 'z'
//  (if FRAM is left unprotected, write operation will succeed)
	for(cptr = 0x000; cptr < 0x0100; cptr++)
		*(framptr + cptr) = 'z';
*/

 //--Generate 10 CR+LF on terminal program for display purposes
	for( cptr = 0; cptr < 010; cptr++)
		{
		txmit0(13);                   //send CR+LF
		txmit0(10);
		}

	//-- Send message "FRAM Memory test \0" on UART0
	cptr = 0x00;
	do{
		txmit0(msg[cptr++]);
		}while(msg[cptr]!= '\0');

	txmit0(13);					//Send Carriage Return
	txmit0(10);					//Send Line Feed


	//--Read FRAM content 2 consecutive bytes every 16 from 0x0000 and  display as Ascii on UART0
	for(cptr = 0x000; cptr < 0x1C00; cptr+= 0x010)
	 {
	 	ReadFramUart0(cptr);
	 	ReadFramUart0(cptr+1);
	 	delay(70);
   	 };


	while(1);

}//end of Main




//----------------------------//
//--- Interrupt Functions ----//
//----------------------------//

//----------------------------//
//----- Interrupt INT0 ------//
//---------------------------//

void INT0Interrupt(void) interrupt 0
	{
	
	int bof=0x00;
	//-- Send "EXT INT0 Received" on UART0
	char cptr = 0x00;					// Init cptr to pint to message beginning
	INTEN1 = 0x00;						//Disable UART0 Interrupt

	do{
		B = msgint0[cptr++];
		txmit0(B);
		}while(msgint0[cptr]!= '\0');

		txmit0(13);					//Send Carriage Return
		txmit0(10);					//Send Line Feed

	INTEN1 = 0x21;						//Enable UART0 Interrupt + INT0
	}//end of INT0 interrupt


//----------------------------//
//--- UART0 Interrupt --------//
//----------------------------//
void UART0Interrupt(void) interrupt 5
{
char genvar;

	INTEN1 = 0x00;						//Disable UART0 Interrupt

	//Check if interrupt was caused by RX AVAIL
	genvar = UART0INT;

	if(genvar & 0x02)
		txmit0(UART0BUF);				//Send back the received character

//Check if interrupt was caused by RX OVERRUN

	if(genvar &= 0x04)
		{
		genvar = UART0BUF;				//Read S0BUF to clear RX OV condition...
									//***This is mandatory because otherwise the RX OV condition keep
									//interrupt activated
		txmit0(' ');					//Send " OV!" on serial port
		txmit0('O');					//
		txmit0('V');					//
		txmit0('!');					//
		}


	INTEN1 = 0x21;						//Enable UART0 Interrupt + INT0

}//end of uart0 interrupt


//----------------- Individual Functions ---------------------

//--------------------------------------------------------------------------------//
// UART0 CONFIG with S0REL
//
// Configure the UART0 to operate in RS232 mode at 115200bps
// with self oscillator at 39.2MHz
//
//--------------------------------------------------------------------------------//
void uart0config()
	{
//--initialize UART0 at 115200bps @ 39.2MHz

	UART0CFG = 0x90;					//No Fine adjustment on baud rate
									//Use internal clock
									//9th bit not used
									//only one stop bit

	UART0INT = 0x62;					//Enable RX AV + RXO V int + Enable Reception
	UART0EXT = 0x00;					//Not using UART0 Extensions

	UART0BRL = 0x09;					//Reload for 115200
	UART0BRH = 0x00;					//

	}//end of uart0ws0relcfg() function


//--------------------------------------------------------------------------------//
// TXMIT0
//
// Transmit one byte on the UART0
//
//--------------------------------------------------------------------------------//
void txmit0( unsigned char charact){
//	char patof;
	UART0BUF = charact;					//Send Character
	while(!(UART0INT & 0x01));

     }//end of txmit0() function

///////////////////////////////////////////////////////////////
// void bin2bcdser1(int)
//
// BINARY TO BCD CONVERSION + TXMIT ON SERIAL UART0
//
//
///////////////////////////////////////////////////////////////
void bin2bcdser0(unsigned int  number){

//unsigned char dixmille;
     unsigned char x;
     unsigned char zerodisplay = 0;     //intialise startdisplay to 0 -> do not display if number is zero


	x = (number/10000);				// Define number of then's of thousands
	if(x>0)						// If number > 0 display it
		{
		zerodisplay = 1;			// number > 0 -> when zero is next encountered, display it
		number = number - (x*10000);
		txmit0((x+'0'));
      	}
      	else
      		txmit0(' ');			//display a blank space instead

	x = (number/1000);				//Define the number of thousands

	if( (zerodisplay !=0)|| (x !=0))
//     if( (x !=0))
		txmit0((x+'0'));
		else
			txmit0(' ');			//display a blank space instead

	if(x>0)
		{
		zerodisplay = 1;
		number = number - (x*1000);

⌨️ 快捷键说明

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