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

📄 r8c2c2d_s002_sfr_init.c

📁 基于日立单片机的同步收发程序。支持R8C2C/2D(5.0V/20MHz)单片机
💻 C
字号:
/************************************************************************************
*                                                                                   *
*   System file name	: r8c2c2d_s002_sfr_init.c                                 	*
*	System name			: R8C2C/2D(5.0V/20MHz) 										*
*																					*
*   Version     		: 1.00                                                      *
*	ROM size			: -															*
*	RAM size			: -															*
*	Contents			: Initial setting of SFR registers 							*
*                                                                                   *
************************************************************************************/
/************************************************************
*	Include file											*
/***********************************************************/

#include "sfr_r8c2c2d.h"									/* Definition of the R8C/2C,2D SFR for Sango */

/************************************************************
*	Declaration of function prototype    	         		*
************************************************************/
void sfr_init(void);										/* Initial setting of SFR registers */

/*** Extern ***/

/*** Static ***/
static void wait_vref(void);								/* Waiting for stable of Vref */

/************************************************************
*	Declaration of interrupt   			 	         		*
************************************************************/

/************************************************************
*	Definition of RAM area   			 	         		*
************************************************************/
/*** Input parameters ***/

/*** Output parameters ***/

/*** Static ***/

/************************************************************
*	Definition of base section   			         		*
************************************************************/

/************************************************************
*	Definition of port			   			         		*
************************************************************/

/************************************************************
*	Data table			   			         		 		*
************************************************************/

/************************************************************************************
Name		:sfr_init
Parameters	:-
Returns		:-
Description	:Initial setting of SFR registers
************************************************************************************/
void sfr_init(void){

	/* Port */
	p0 = 0x00;												/* Port P0 initial setting = "L" */
	p1 = 0x00;                                              /* Port P1 initial setting = "L" */
	p2 = 0x00;                                              /* Port P2 initial setting = "L" */
	p3 = 0x00;                                              /* Port P3 initial setting = "L" */
	p4 = 0x00;                                              /* Port P4 initial setting = "L" */
	p6 = 0x00;                                              /* Port P6 initial setting = "L" */
	p7 = 0x00;                                              /* Port P7 initial setting = "L" */
	p8 = 0x00;                                              /* Port P8 initial setting = "L" */
	p9 = 0x00;                                              /* Port P9 initial setting = "L" */

	/* Port direction */
	pd0 = 0x00;												/* Port P0 direction = input */
	pd1 = 0x00;												/* Port P1 direction = input */
	pd2 = 0x00;												/* Port P2 direction = input */
	pd3 = 0x00;                                             /* Port P3 direction = input */
	pd4 = 0x00;                                             /* Port P4 direction = input */
	pd6 = 0x00;                                             /* Port P6 direction = input */
	pd7 = 0x00;                                             /* Port P7 direction = input */
	pd8 = 0x00;                                             /* Port P8 direction = input */
	pd9 = 0x00;                                             /* Port P9 direction = input */

	/* Pull-up control register */
	pur0 = 0x00;											/* Pull up resister not used */
	pur1 = 0x00;											/* Pull up resister not used  */
	pur2 = 0x00;											/* Pull up resister not used  */

	/* Port mode resister */
	pmr = 0x10;												/* UART1 are selected / SSU function is selected */

	/* Port P2 drive capacity control */
	p2drr = 0x00;											/* Capacity low is selected */

	/* Timer RB */
	trbcr = 0x00;											/* Timer mode , count stop */
	trbocr = 0x00;											/* Timer RB one-shot is not used */
	trbioc = 0x00;											/* Timer mode */
	trbmr = 0x00;											/* Timer mode is selected , f1 , provides count source */
	trbpre = 125-1;											/* Timer RB prescaler register : set to 125-1 (20MHz x f1 x 125 = 6.25usec) */
	trbpr = 40-1;											/* Timer RB Primary Register : set to 40-1 (6.25usec x 40 = 250usec) */

	/* A/D */
	adcon0 = 0x80;											/* AN0 is selected , Single mdoe , Port P0 group is selected , Soft trigger , A/D conversion stop , fAD/2 */
	adcon1 = 0x28;											/* 10bit mode , cks1=0 setting / Vref connected */
	adcon2 = 0x00;											/* No sample and hold function is selected (20MHz x f2 x 59cycle = 5.9usec) */
	wait_vref();											/* Waiting for stable of Vref */

	/* Interrupt registers */
	trbic = 0x02;											/* Timer RB interrupt : Priority level-2 is selected , Interrupt request bit = clear */
	adic = 0x00;											/* A/D interrupt : Priority level-0(interrupt disable) , Interrupt request = clear */

	/* Timer count start bit */
	tstart_trbcr = 1;										/* Timer RB conut start bit = start */
}
/************************************************************************************
Name		:wait_vref
Parameters	:-
Returns		:-
Description	:Waiting(over 1usec) for stable of Vref. 20MHz x f1 x 32cycle =1.6usec
************************************************************************************/
static void wait_vref(void){

	asm("NOP");												/* Waiting for stability */
	asm("NOP");												/* Waiting for stability */
	asm("NOP");												/* Waiting for stability */
	asm("NOP");												/* Waiting for stability */
	asm("NOP");												/* Waiting for stability */
	asm("NOP");												/* Waiting for stability */
	asm("NOP");												/* Waiting for stability */
	asm("NOP");												/* Waiting for stability */
	asm("NOP");												/* Waiting for stability */
	asm("NOP");												/* Waiting for stability */
}
/************************************************************************************
Name		:-
Parameters	:-
Returns		:-
Description	:-
************************************************************************************/

⌨️ 快捷键说明

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