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

📄 startup.c

📁 瑞萨单片机开发软代码.非常实用小巧的平台,很多应用都可以在上面实现.
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <machine.h>
#include "CatProType.h"
#include "sci.h"
#include "stacksct.h"
#include "flashdisk.h"

#include "private_cmd.h"

#pragma entry	SetPowerOnSection
#pragma interrupt (IRQ6_Int)                         // suspend/resume


//****  variables
#pragma section ABS8
FLASH_RW flash_rw;              // 8-bit access global variable
#pragma section             

MSC MBRCache;             // 512 +...
DATA_BUFF Cache[1];
unsigned char debug;   
volatile unsigned char errorcode;      // error code
volatile unsigned char testcode; 
volatile unsigned char pgddr;          // remember pgddr    
volatile unsigned long backup_odd;     // backup blk data for odd address
volatile unsigned long backup_even;    // backup blk data for even address
volatile unsigned char write_protect;  // indicate is the device "1" write protected  
volatile unsigned char report_wp;                                                
volatile unsigned char suspend;        // suspend request "1", suspend/resume
LinkType *jump_ptr[9];                 // interrupt jump[] pointer array 
EpInfoType	*epinfo_ptr[5];                                        

unsigned int test_backup;              // timer to test bad backup block found
unsigned int test_spare;               // timer to test find spare blk action
volatile unsigned char datacomm[6],datarecv[6];
unsigned char count=0,datahand;
void			SetPowerOnSection(void);
void			_INITSCT(void);
void			InitSystem(void);
void			error(void);
unsigned char 	InitStorage(void);
void            IRQ6_Int(void);        // suspend/resume

unsigned char   isShow = 1;
extern FLASH_RW flash_rw;                                    
extern unsigned short g_ShowDelay,PicNumber;
extern void		BranchOfInt(void);
extern void		SCI0RX_Int(void);
extern void		SCI2RX_Int(void);
extern volatile unsigned char rcvdata;
void WaitTime( unsigned short ms);
extern void demo_66766( );
extern void IRQ2_Int(void);
extern void IRQ7_Int(void);
extern void IRQ4_Int(void);
extern void debug_flash();
extern volatile unsigned char EvRcv;                              
#pragma section Start
void	(*const vect_table[])(void) = {
	SetPowerOnSection,SetPowerOnSection,0,0,0,0,0,SetPowerOnSection,0,0,		/*	0-9	Power On Reset , Manual Reset*/
	0,0,0,0,0,0,0,0,IRQ2_Int,0,					/*	10-19	*/
	IRQ4_Int,0,IRQ6_Int,IRQ7_Int,0,0,0,0,0,0, 			/*	20-29	*/   // suspend/resume
	0,0,0,0,0,0,0,0,0,0,					/*	30-39	*/
	0,0,0,0,0,0,0,0,0,0,					/*	40-49	*/
	0,0,0,0,0,0,0,0,0,0,					/*	50-59	*/
	0,0,0,0,0,0,0,0,0,0,					/*	60-69	*/
	0,0,0,0,0,0,0,0,0,0,					/*	70-79	*/
// 	0,0,0,0,0,0,0,0,SCI2RX_Int,SCI2RX_Int,					/*	80-89	*/
	0,0,0,0,0,0,0,0,0,SCI2RX_Int,					/*	80-89	*/
	0,0,0,0,0,0,0,0,0,0,					/*	90-99	*/
	0,0,0,0,BranchOfInt,0,0,0,0,0,			/*	100-109	EXIRQ0	*/
	0,0										/*	110-111	*/
};
#pragma section
                                                                
extern unsigned char init_m3v( );

extern unsigned short* GetImgBuf( int ImgID );
extern int IsExistImgFile( int FileID, unsigned long *FileSize,unsigned short *wWidth, unsigned short *wHeight );
extern int init_img_disk();
extern unsigned short Delaytime,OperateCode;
unsigned char g_filecnt=0, g_FileID=0;
unsigned short CurrentPic;
void SystemInit( )
{
	/*	Set:CPG	*/
	LPW.SCKCR.BYTE = 0x00;	//	0--- 0000	High Speed Mode(Phy/1) , Clock output enable	*/
	LPW.LPWRCR.BYTE = 0x03;	/*	---- 0011	Enable feedback register and duty adjustment circuit	*/
							/*	Frequency multiplication factor = x1 (HM indicate facter setting = bypass)	*/
	/*	Set:MODE	*/
	MCU.SYSCR.BYTE |= 0x29;	/*	--10 10-1   Interrupt control mode 2 , Rising edge of NMI is used , DIsable MRST , Enable internal RAM	*/
	
	/*	Set:Power Management*/
	LPW.SBYCR.BYTE = 0x88;	/*	1000 1---	Shifts to software standby mode when the SLEEP instruction is executed	*/
	LPW.MSTPCRA.BYTE = 0x7F;/*	0111 1111	DMAC  , DTC   , TPU   , TMR_0/1 , --- , --- , A/D , --- 	*/
	LPW.MSTPCRB.BYTE = 0x5F;/*	0101 1111	SCI_0 , SCI_1 , SCI_2 , ---     , --- , --- , --- , USB 	*/
	LPW.MSTPCRC.BYTE = 0xFF;/*	1111 1111	---   , ---   , D/A   , ---     , --- , --- , --- , --- 	*/
	
	BSC.ABWCR.BYTE = 0xCF;	/*	1100 1111	all area are designated for 8-bit access expert area 4*/
	BSC.PFCR.BYTE = 0x00;	/*	--0- 0000	Disable A8 to A13 output	*/
	BSC.ASTCR.BYTE = 0xED;	/*	1111 1101	Area1 = 2-state access */
	BSC.WCRH.BYTE = 0xCC;	/*	1100 1100	Area 6 is designated for 3-state access	*/
	BSC.WCRL.BYTE = 0xF0;	/*	1111 0000	Area 0 & 1 no wait state inserted	*/
//	BSC.ASTCR.BYTE = 0xFD;	/*	1111 1101	Area1 = 2-state access */
//	BSC.WCRH.BYTE = 0xCF;	/*	0000 1111	Area 6 is designated for 3-state access	*/
//	BSC.WCRL.BYTE = 0xF0;	/*	1111 0000	Area 0 & 1 no wait state inserted	*/
	BSC.BCRH.BYTE = 0xD0;	/*	1100 0---	Idle cycle inserted in case of successive external read cycles in different areas	*/
							/*	Idle cycle inserted in case of successive external read and write cycles	*/
	BSC.BCRL.BYTE = 0x08;	/*	1--- 1--1	Enalbe external bus release , Enable wait input	*/
	
	PORT.P1DDR.BYTE = 0xFF;	/*	1111 1111	A23-20 not used, all output "0"	*/
	PORT.P7DDR.BYTE = 0xFF;	/*	1111 1111	CS6 is used	*/
	PORT.PADDR.BYTE = 0xFF;	/*	1111 1111	A19-16 not used, all output "0"	*/
	PORT.PBDDR.BYTE = 0xFF;	/*	1111 1111	A15-8 is used	*/
	PORT.PCDDR.BYTE = 0xFF;	/*	1111 1111	A7-0 not used, all input	*/
	PORT.PEDDR.BYTE = 0xFF;	/*	1111 1111	port E output	*/
	PORT.PFDDR.BYTE = 0xF6;	/*	1111 0110	Some bus control signal used, all other output "0" */
	PORT.PGDDR.BYTE = 0x1F;	/*	---1 1111	CS0-3 is used	*/   

	/*	Set:INTC	*/
	INTC.IPRA.BYTE = 0x00;	/*	-000 -000	*/
	INTC.IPRB.BYTE = 0x55;	/*	-000 -000	*/
	INTC.IPRC.BYTE = 0x50;	/*	-000 -000	Priority level of IRQ6 is 5 */ // suspend/resume
	INTC.IPRD.BYTE = 0x00;	/*	-000 ----	*/
	INTC.IPRF.BYTE = 0x00;	/*	-000 -000	*/
	INTC.IPRG.BYTE = 0x00;	/*	-000 ----	*/
	INTC.IPRJ.BYTE = 0x00;	/*	-000 -000	*/
//	INTC.IPRJ.BYTE = 0x04;	/*	-000 -100	Priority level of SCI0RX */
	INTC.IPRK.BYTE = 0x06;	/*	-000 -000	*/
	INTC.IPRM.BYTE = 0x60;	/*	-110 -000	Priority levels of EXIRQ0 is 6	*/
	INTC.ISCRH.BYTE= 0x51;	/*	0101 0001	Interrupt request is generated by falling edge of IRQ2,4,7	*/
	INTC.ISCRL.BYTE= 0x10;	/*	0001 0000	*/
	INTC.ISR.BYTE  &= 0x00;	/*	Clear interrupt flags	*/
	INTC.IER.BYTE  = 0x94;	/*	0000 0000	Enable IRQ2,4,7	*/
	 
	//DMAC Initialization
    DMAC.DMABCR.FULLADD.SHORT = 0xCA00;   // full addr mode, clear int. source, no interrupt req. 

	//****  I/O Port (flashdisk)
    // Port 1 - no use, all ports output low "0"
    PORT.P1DDR.BYTE = 0x7f;
    PORT.P1DR.BYTE = 0xbf;

    // Port 3 - LED indication port
    PORT.P3DDR.BYTE = 0xFB;
    PORT.P3DR.BYTE = 0x40;			// P36 D+ pull-up init state
    PORT.P3ODR.BYTE = 0x00;  
    
    // Port A - only SCI2 function, all other output low "0"
    PORT.PADDR.BYTE = 0xFF;
    PORT.PADR.BYTE = 0x00;

    // PORT B - address bus
    PORT.PBDDR.BYTE = 0xFF;
    PORT.PBDR.BYTE = 0x30;
    PORT.PBPCR.BYTE = 0x00;
    
    // PORT D -
    PORT.PDPCR.BYTE = 0xFF;     // pull-up for data input

    // PORT E - FLASH Memory I/O data port, normal output low
    PORT.PEDDR.BYTE = 0x6F;
    PORT.PEDR.BYTE = 0x00;
    PORT.PEPCR.BYTE = 0x90;
    
    // PORT F - all output port "0", except used bus control signal
    PORT.PFDR.BYTE = 0x00;

	DISABLE_DPLUS_PULLUP

	_INITSCT();	/*	copy initial value to RAM area	*/
}

/***************************************************************************
Function Name	:SetPowerOnSection(void)
Working			:Initializing Microcomputer
Return Value	:void
Created			:{Author : T.Ishikawa[2001.Nov.28]}
***************************************************************************/
void	SetPowerOnSection(void) 
{
	unsigned int i;
	set_imask_ccr(1);       // disable all interrupt
	SystemInit( );
	SCIInit();     

	SCI_Str("\r\nStart-v12-MD");
	SCI_HexB(MCU.MDCR.BYTE&0x07);
	 
	errorcode = 0;
	testcode=0;                                                                 
	debug = 0;                                                       
	report_wp = 0;
	suspend = 0;		    // clear suspend request, suspend/resume
	write_protect = 0;		// not write protect

	// Cache interrupt jump table
	for (i=0;i<9;i++)
	 jump_ptr[i] = &jump[i];     

	for (i=0;i<5;i++)
	 epinfo_ptr[i] = &EpInfo[i];

	// Flash Memory initialization 
    InitStorage();                    
    // USB initialization
	InitSystem();
	init_img_disk();
	PORT.PADDR.BIT.PA0DDR = 1;
	PORT.PADR.BIT.PA0DR = 0;
	WaitTime( 200 );
	PORT.PADR.BIT.PA0DR = 1;
	WaitTime( 150 );
//	AAT3113ON();
//	InitHD66766U( );
//	InitS6B33B5( );
//	InitS6B33B2( );
	init_lcd(); //hddd789
//	init_lcdPCF8839();
 // for(i=0;i<48;i++)ShowPicture( i, 128, 96 ); //BASKETBALL VIDEO
	for(i=0;i<8;i++)ShowPicture( i, 176, 220 );
   while( 1 )
	{      
		switch( OperateCode )
		{
		case 0x0001:
			ShowPicture( 1, 176, 220 );
			OperateCode = 0;
			SCI_Str("\nFill the data 0xffff.");
			break;
		case 0x0002:
			OperateCode = 0;
			ShowPicture( 2, 176, 220 );
			SCI_Str("\nFill the data Monochrom.");
			break;
		case 0x0003:
			OperateCode = 0;
			while(1)Write766u();
			SCI_Str("\nShow 8 lines.");
			break;
		case 0x0004:
			OperateCode = 0;
			InitHD66766U( );
			SCI_Str("\nMode 4.");
			break;
		case 0x0005:
//			OperateCode = 0;
//			for(i=0;i<8;i++)ShowPicture( i, 176, 220 );
			while(1){
		   for(i=1;i<18;i++)
		   {
		    //ShowPicture( i, 128, 96 );
			WaitTime( Delaytime);
			}
			}
			SCI_Str("\nMode 5.");
			break;

		case 0:
			break;

		default:
			OperateCode = 0;
			SCI_Str("\nInvalid command.");
			break;
		}
	    process_rs232_data( );

		// check internal error
		if (errorcode!=0)      
		{
			SCI_Str("Internal ERROR!!!!(0x");
			SCI_HexB(errorcode);
			errorcode = 0;
		}

		if( isShow )
		{
			//if( g_FileID >= g_filecnt )
			//	g_FileID = 0;
	 	//if(CurrentPic!=PicNumber)ShowPicture( PicNumber, 176, 220 );
		CurrentPic=PicNumber;
			//ShowPicture( g_FileID++,176, 220 );
		   //for(i=1;i<48;i++)
		   //{//ShowPicture( i, 128, 96 );
		//	WaitTime( Delaytime);
		//	}
		WaitTime( 1000);
		}

		// check suspend mode request, suspend/resume
		if (suspend!=0)
		{
			sleep();                      
		}
	}// while(1) -- main loop

	SCI_Str("\r\nStart receive data:\r\n");
	while(0){
		while(1)
		{
	    if(EvRcv)//如果接收到主机端发送过来的握手信号
		{
			if(rcvdata==MACHINECOMM_OK){EvRcv=FALSE;break;}//SCI_Char(MACHINECOMM_RET);
		}
		}//end while
	    count=0;
		while(1)
		{if(EvRcv){
				datarecv[count]=rcvdata;
				count++;
				EvRcv=FALSE;
	    		}
		 if(count==6)break;
  		}//end while5
    	if(datarecv[0]==MACHINECOMM_DATAHEAD&&datarecv[5]==MACHINECOMM_DATAEND)
		{
		SCI_Str("\r\n data receive success!");

⌨️ 快捷键说明

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