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

📄 r8c2c2d_s002_main.c

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

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

/************************************************************************************
Name		:main
Parameters	:-
Returns		:-
Description	:main loop
************************************************************************************/
main(){
	/* Initial settings */
	asm("FCLR I");											/* Interrupt disable */

	reset_init();											/* Initialization program after resets */
	sfr_init();												/* Initial setting of function SFR registers */

	prcr = 0x0f;											/* Protect all off */

	asm("FSET I");											/* Interrupt enable */
/* &&main initial&& */

	while(1){												/* Main processing */
		asm("FSET I");										/* Interrupt enable */
/* &&main_loop&& */

		if(f_1ms == 1){										/* 1msec main loop */
			f_1ms = 0;										/* Flag clear */
/* &&main_loop_1msec&& */
		}
		else if(f_10ms == 1){								/* 10msec main loop */
			f_10ms = 0;										/* Flag clear */
/* &&main_loop_10msec&& */
		}
		else if(f_100ms == 1){								/* 100msec main loop */
			f_100ms = 0;									/* Flag clear */
/* &&main_loop_100msec&& */


		}
		else if(f_1s == 1){									/* 1sec main loop */
			f_1s = 0;										/* Flag clear */

/* &&main_loop_1sec&& */
		}
	}
}
/************************************************************************************
Name		:Timer RB interrupt(vector 24)
Parameters	:-
Returns		:-
Description	:Main timer make(250usec)
************************************************************************************/
void timer_rb_int(void){

	asm("FSET I");											/* Interrupt enable */

/* &&timer RB 250uS&& */
	 sio_trx5();											/* ##R8C2C/2D-2009## Trans/Receive of Clock synchronous serial I/O 0 */


	/* A_D channel counter */
	if(++c_ad_cha > 19){									/* A/D channel counter:AN2 to AN19 , Caution:read only from other modules */
		c_ad_cha = 2;
	}

	switch(++c_timesharing & timesharing_mask){
		case 0:
			f_1ms = 1;
			delayed_sorce_make();							/* Delayed LED pulese duty sorce make */
/* &&timer RB 1mS&& */



			break;
		case 1:
			if(++c_10ms >= 10){
				f_10ms = 1;
				c_10ms = 0x00;
/* &&timer RB 10mS&& */

			}
			break;
		case 2:
			if(++c_100ms >= 100){
				f_100ms = 1;
				c_100ms = 0x00;
/* &&timer RB 100mS&& */
			}
			break;
		case 3:
			if(++c_1s >= 1000){
				f_1s = 1;
				c_1s = 0x0000;
/* &&timer RB 1sec&& */
			}
			break;
		default:
			break;
	}
}
/************************************************************************************
Name		:ad_execute
Parameters	:A/D conversion channel(analog input pin)
Returns		:-
Description	:Executes A/D conversion / Matched two times
************************************************************************************/
void ad_exe(unsigned char an){

	unsigned short now_ad;

	/* Executes A/D conversion */							/* Dynamic Scanning */
	if(adst == 0){											/* A/D conversion stop? */
		if(ir_adic == 1){									/* A/D interrupt request? */
			if (an <= 7){
				adcon2 = 0x00;						/* Set Port P0 group */
			}
			else if ((an >= 8) && (an <= 11)){
				adcon2 = 0x08;						/* Set Port P1 group */
			}
			else {
				adcon2 = 0x10;						/* Set Port P7 group */
			}

			if ((an <= 12) || (an == 16)){
				now_ad = ad0 & 0x3ff;				/* Read the A/D conversion data(19bits) */
			}
			else if ((an == 13) || (an == 17)){
				now_ad = ad1 & 0x3ff;				/* Read the A/D conversion data(19bits) */
			}
			else if ((an == 14) || (an == 18)){
				now_ad = ad2 & 0x3ff;				/* Read the A/D conversion data(19bits) */
			}
			else if ((an == 15) || (an == 19)){
				now_ad = ad3 & 0x3ff;
			}

			if(ad_buf[exe_ad_cha] == now_ad){				/* Last A/D data and this time A/D data are compared. Are they match twice? */
				ad_data[exe_ad_cha] = now_ad;				/* A/D convasion data determined (matced two times) */
			}
			ad_buf[exe_ad_cha] = now_ad;					/* Save to the last A/D data */
		}

		adcon0 = tb_ad_port[an];							/* Setting A/D conversion channel(analog input pin) */
		exe_ad_cha = an;									/* Save to Execut channel(analog input pin) */
		ir_adic = 0;										/* A/D interrput request flag clear */

		adst = 1;											/* A/D convarsion start */
	}
}
/************************************************************************************
Name		:delayed_sorce_make
Parameters	:-
Returns		:-
Description	:Delayed LED pulse duty sorce make
************************************************************************************/
void delayed_sorce_make(void){

	/* Pulse duty make */
	switch(++c_delay_sorce & 0x0f){							/* Free run count increment, and Bit3 from bit0 effective. */
		case 0x00:	delay_duty = 0x01;						/* Count  0 : bit0 "H" set */
					break;
		case 0x0f:	delay_duty = 0x00;						/* Count 15 : all clear = all "L" set */
					break;
		default:	delay_duty |= (delay_duty << 1);		/* Other count : Left bit shift */
					break;
	}
}
/************************************************************************************
Name		:Interrupt registers
Parameters	:-
Returns		:-
Description	:-
************************************************************************************/

/****************** fixed vector section ********************/

void wa2_int(void){
/* &&wa2 int&& */
}

/***************** variable vector section ******************/

/* Timer RC interrupt(vector7) */
void timer_rc_int(void){
/* &&timer RC int&& */
}

/* Timer RD(Channel 0) interrupt(vector8) */
void timer_rd0_int(void){
/* &&timer RD0 int&& */
}

/* Timer RD(Channel 1) interrupt(vector9) */
void timer_rd1_int(void){
/* &&timer RD1 int&& */
}

/* Timer RE interrupt(vector10) */
void timer_re_int(void){
/* &&timer RE int&& */

}

/* UART2 transmit interrupt(vector 11) */
void uart2_tra_int(void){
/* &&uart2 transmit int&& */
}

/* UART2 receive interrupt(vector 12) */
void uart2_rec_int(void){
/* &&uart2 receive int&& */
}

/* Key in interrupt(vector 13) */
void key_in_int(void){
/* &&key in int&& */
}

/* SSU/IIC interrupt(vector 15) */
void ssu_int(void){
/* &&ssu int&& */
}

/* Timer RF Compare1 interrupt(vector 16) */
void timer_rf_cmp1_int(void){
/* &&timer RF Compare1 int&& */
}

/* UART0 transmit interrupt(vector 17) */
void uart0_tra_int(void){
/* &&uart0 transmit int&& */
	 uart0_tra_int_func10();								/* ##R8C2C/2D-2009## UART0 transmit interrupt function of Clock synchronous serial transmission/reception 0 */
}

/* UART0 receive interrupt(vector 18) */
void uart0_rec_int(void){
/* &&uart0 receive int&& */
	 uart0_rec_int_func14();								/* ##R8C2C/2D-2009## UART0 receive interrupt function of Clock synchronous serial transmission/reception 0 */
}

/* UART1 transmit interrupt(vector 19) */
void uart1_tra_int(void){
/* &&uart1 transmit int&& */
}

/* UART1 receive interrupt(vector 20) */
void uart1_rec_int(void){
/* &&uart1 receive int&& */
}

/* INT2 interrupt(vector 21) */
void int2_int(void){
/* &&int2 int&& */
}

/* Timer RA interrupt(vector 22) */
void timer_ra_int(void){
/* &&timer ra int&& */
}

/**** timer_rb_int used system main ****/

/* INT1 interrupt(vector 25) */
void int1_int(void){
/* &&int1 int&& */

}

/* INT3 interrupt(vector 26) */
void int3_int(void){
/* &&int3 int&& */
}

/* Timer RF interrupt(vector 27) */
void timer_rf_int(void){
/* &&timer RF int&& */
}

/* Timer RF Compare0 interrupt(vector 28) */
void timer_rf_cmp0_int(void){
/* &&timer RF Compare0 int&& */
}

/* INT0 interrupt(vector 29) */
void int0_int(void){
/* &&int0 int&& */

}

/* A/D interrupt(vector 30) */
void ad_int(void){
/* &&ad int&& */
}

/* Timer RF Capture interrupt(vector 31) */
void timer_rf_cap_int(void){
/* &&timer RF Capture int&& */
}
/************************************************************************************
Name		:-
Parameters	:-
Returns		:-
Description	:-
************************************************************************************/



⌨️ 快捷键说明

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