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

📄 startup.c

📁 16位单片机H8的例子源代码
💻 C
字号:
/*
****************************************************************************
					H I T A C H I    P R O P R I E T A R Y

	COPYRIGHT (c)	2001 BY Semiconductor & Integrated Circuits,Hitachi,Ltd.
						---  ALL RIGHTS RESERVED  ---

	File Name	:StartUp.c
	Working		:Initializing Microcomputer and Clearing buffer
	Created		:Rev 2001_11_28 {Author : T.Ishikawa}
****************************************************************************
*/

/*	Includes	*/
#include	<machine.h>

#ifndef SysMemMap
#include	"SysMemMap.h"
#endif	/*	SysMemMap	*/

#include	"CatProType.h"



	/*	Set:STACK	*/
#pragma entry	SetPowerOnSection(sp=STACK_START_ADDR)



/*	Prototype	*/
void			SetPowerOnSection(void);
void			_INITSCT(void);
void			InitMemory(void);
void			InitSystem(void);
void			error(void);


extern void						BranchOfInt(void);

#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,0,0,										/*	10-19	*/
	0,0,0,0,0,0,0,0,0,0,										/*	20-29	*/
	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,0,0,										/*	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




/***************************************************************************
Function Name	:SetPowerOnSection(void)
Working			:Initializing Microcomputer
Return Value	:void
Created			:{Author : T.Ishikawa[2001.Nov.28]}
***************************************************************************/
void	SetPowerOnSection(void) {

	unsigned char	readLVar;

	/*	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	*/
	readLVar = MCU.MDCR.BYTE;	/*	Mode latch	*/
	MCU.SYSCR.BYTE |= 0x2D;	/*	--10 11-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	*/
															/*	Address bus and bus control signals are retained in software standby mode	*/
	LPW.MSTPCRA.BYTE = 0xFF;		/*	1111 1111	*/		/*	DMAC  , DTC   , TPU   , TMR_0/1 , --- , --- , A/D , --- 	*/
	LPW.MSTPCRB.BYTE = 0xFF;		/*	1111 1111	*/		/*	SCI_0 , SCI_1 , SCI_2 , ---     , --- , --- , --- , USB 	*/
	LPW.MSTPCRC.BYTE = 0xFF;		/*	1111 1111	*/		/*	---   , ---   , D/A   , ---     , --- , --- , --- , --- 	*/
	
	
	/*	Set:BSC	*/
// hitachi LSI original
//	BSC.ABWCR.BYTE = 0xF7;	/*	1111 0111	*/	/*	Area 3 is designated for 16-bit access , others are designated for 8-bit access	*/
// hmsa-hk 2215 application board
	BSC.ABWCR.BYTE = 0xFF;	/*	1111 1111	*/	/*	all area are designated for 8-bit access	*/

	BSC.PFCR.BYTE = 0x0F;	/*	--0- 1111	*/	/*	Enable A8 to A23 output	*/

	BSC.ASTCR.BYTE = 0xFF;	/*	1111 1111	*/	/*	All area are designated for 3-state access / Enable wait-state incertion	*/
	BSC.WCRH.BYTE = 0xCF;	/*	1100 1111	*/	/*	Area 6 is designated for 3-state access	*/
	BSC.WCRL.BYTE = 0x3C;	/*	0011 1100	*/	/*	Area 0 & 3 is designated for 3-state access	*/
	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 = 0x89;	/*	1--- 1--1	*/	/*	Enalbe external bus release , Enable wait input	*/
	
	
	/*	Set:PFC	*/
	/*	Set:I/O port	*/
	/*	P*DDR Register is write only register. Be careful with rewriting	*/
	
	/*	PORT 1	*/
	PORT.P1DDR.BYTE = 0x0F;	/*	0000 1111	*/	/*	A23-20 is used	*/
	
	/*	PORT 3	*/
	PORT.P3DR.BYTE |= 0x40;	/*	-1-- ----	*/	/*	Pullup function is used to P36 pin(Active High)	*/
	PORT.P3DDR.BYTE = 0x40;	/*	0100 0000	*/	/*	Output	*/
	
	/*	PORT 7	*/
	PORT.P7DDR.BYTE = 0x0F;	/*	0000 1111	*/	/*	CS7-4 is used	*/
	
	/*	PORT A	*/
	PORT.PADDR.BYTE = 0x0F;	/*	0000 1111	*/	/*	A19-16 is used	*/

	/*	PORT B	*/
	PORT.PBDDR.BYTE = 0xFF;	/*	1111 1111	*/	/*	A15-8 is used	*/

	/*	PORT C	*/
	PORT.PCDDR.BYTE = 0xFF;	/*	1111 1111	*/	/*	A7-0 is used	*/

	/*	PORT E	*/
	PORT.PEDDR.BYTE = 0xFF;	/*	1111 1111	*/	/*	port E output	*/
	PORT.PEDR.BYTE = 0xFF;	/*	1111 1111	*/	/*	port E output	*/
	
	/*	PORT F	*/
	PORT.PFDDR.BYTE = 0xF8;	/*	1111 1000	*/	/*	Output 冇	*/
	
	/*	PORT G	*/
	PORT.PGDDR.BYTE = 0x1E;	/*	---1 1110	*/	/*	CS0-3 is used	*/
	
	
	/*	Set:INTC	*/
	INTC.IPRA.BYTE = 0x00;	/*	-000 -000	*/
	INTC.IPRB.BYTE = 0x00;	/*	-000 -000	*/

	INTC.IPRC.BYTE = 0x00;	/*	-000 -000	*/	/*	Priority level of IRQ6 is 0	*/

	INTC.IPRD.BYTE = 0x00;	/*	-000 ----	*/
	INTC.IPRF.BYTE = 0x00;	/*	-000 -000	*/
	INTC.IPRG.BYTE = 0x00;	/*	-000 ----	*/
	INTC.IPRJ.BYTE = 0x00;	/*	-000 -000	*/
	INTC.IPRK.BYTE = 0x00;	/*	-000 -000	*/
	INTC.IPRM.BYTE = 0x60;	/*	-110 -000	*/	/*	Priority levels of EXIRQ0 is 6	*/
	
	INTC.ISCRH.BYTE = 0x10;	/*	0001 0000	*/	/*	Interrupt request is generated by falling edge of IRQ6	*/
	INTC.ISCRL.BYTE = 0x00;	/*	0000 0000	*/
	
	INTC.ISR.BYTE &= 0x00;	/*	Clear interrupt flags	*/
	
	INTC.IER.BYTE = 0x00;	/*	0000 0000	*/	/*	Disable IRQ6	*/
	
	
	/*	disable D+ pullup	*/
	DISABLE_DPLUS_PULLUP

	InitMemory();	/*	Clear used RAM area	*/

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

	InitSystem();

	/*	normal routine	*/
	while (1) {}
}



extern	unsigned char	*_B_BGN, *_B_END, *_D_BGN, *_D_END, *_D_ROM;

/***************************************************************************
Function Name	:_INITSCT(void)
Working			:copy initial value to RAM area
Return Value	:void
Modified		:{Author : T.Ishikawa[2001.Jan.10]}
Created			:{Author : T.Takenaga[2000.Jan.11]}
***************************************************************************/
void	_INITSCT(void) {

	unsigned char  *p, *q;
	unsigned char  readCounter = 0;

	for (p = _B_BGN; p < _B_END; p++) {
		*p = 0;
	}
	for (p = _D_BGN, q = _D_ROM; p < _D_END; p++, q++) {
		*p = *q;
	}
	
	/*	set initial MBR partition table1 and EOF in sector 1	*/
	while (readCounter <= 65) {
		botDataGVar.byteVal[(readCounter + 446)] = mbrData->byteVal[readCounter];
		readCounter++;
	}
	
	readCounter = 0;
	
	/*	set initial PBR data in sector 20	*/
	while (readCounter <= 62) {
		botDataGVar.byteVal[(readCounter + 16384)] = pbrData->byteVal[readCounter];
		readCounter++;
	}
}



/***************************************************************************
Function Name	:InitMemory(void)
Working			:clear Bulk transfer RAM area
Return Value	:void
Created			:{Author : T.Takenaga[2000.Jan.11]}
***************************************************************************/
void	InitMemory(void) {

	register unsigned long*	writePtrLVar;

//	LED.BYTE = 0x81;	/*	turn on LED for initializing	*/

	for (writePtrLVar = &bulkBeginLongGVar;writePtrLVar <= &bulkEndLongGVar;writePtrLVar++) {	/*	clear Bulk transfer data area	*/
		*writePtrLVar = 0;
	}
	PORT.PEDR.BYTE = 0xFC;	/*	turn on LED for initializing	*/
	
	
}



/***************************************************************************
Function Name	:InitSystem(void)
Working			:Set USB clock & interrupt mask.
Return Value	:void
Created			:{Author : T.Ishikawa[2001.Nov.28]}
***************************************************************************/
void	InitSystem(void) {

	/*	get interrupt enable flag	*/
	GET_INTERRUPT_ENABLE
	
	USBFM.UCTLR.BYTE |= 0x1C;	/*	0001 1100	*/	/*	Uses the UCB operating clock(48MHz) directly , Stop PLL ,  Stabilization time = 8ms 	*/
//	USBFM.UCTLR.BYTE |= 0x20;	/*	0010 0000	*/	/*	Uses the EXTAL48 pin (48MHz) directly , Stop PLL ,  Stabilization time = 200us 	*/
	
	LPW.MSTPCRB.BYTE &= ~0x01;	/*	---- ---0	*/	/*	Disable USB module stop function	*/
	
	set_imask_exr(1);
	set_imask_ccr(0);
	
//	LED.BYTE = 0xAA;	/*	turn on LED for compleated initialize	*/
//	PORT.PEDR.BYTE = 0xF8;	/*	turn on LED for initializing	*/
	PORT.PEDR.BYTE = 0x00;	/*	turn on LED for initializing	*/
}



/***************************************************************************
Function Name	:error(void)
Working			:Occured ERROR
Return Value	:void
Modified		:{Author : T.Ishikawa[2001.Oct.03]}
Created			:{Author : T.Takenaga[2000.Jan.14]}
***************************************************************************/
void	error(void) {

//	LED.BYTE = 0x30;		/*	turn on LED for ERROR	*/
	PORT.PEDR.BYTE = 0x30;	/*	turn on LED for initializing	*/
	sleep();
}

⌨️ 快捷键说明

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