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

📄 systimer.h

📁 str73系列 三洋LC75010 控制代码
💻 H
字号:
					      
#include "73x_lib.h"
#include "def.h"	


void  SysTimerInit(void)
{
    CMU_InitTypeDef   CMU_InitStruct; 
	TB_InitTypeDef    TB_InitStructure;
	PRCCU_InitTypeDef    PRCCU_InitStructure;
	/* TB0 Clock Enable */
	

	CFG_PeripheralClockConfig(CFG_CLK_TB0,DISABLE);
	CFG_PeripheralClockConfig(CFG_CLK_EIC,DISABLE);
	CFG_PeripheralClockConfig(CFG_CLK_TB0,ENABLE);
	CFG_PeripheralClockConfig(CFG_CLK_EIC,ENABLE);

	/* EIC Configuration */
	EIC_IRQChannelConfig(TB0_IRQChannel,ENABLE);
	EIC_IRQChannelPriorityConfig(TB0_IRQChannel,1);
	EIC->ICR &=3;	 //允许中断

    CMU_InitStruct.CMU_CKSEL0 = CMU_CKSEL0_CKOSC;
    CMU_Init (&CMU_InitStruct);

	 PRCCU_InitStructure.PRCCU_DIV2 = ENABLE;
     PRCCU_InitStructure.PRCCU_MCLKSRC_SRC = PRCCU_MCLKSRC_PLL ; 
     PRCCU_InitStructure.PRCCU_PLLDIV = PRCCU_PLLDIV_2;
     PRCCU_InitStructure.PRCCU_PLLMUL = PRCCU_PLLMUL_16;
     PRCCU_InitStructure.PRCCU_FREEN = DISABLE; 
     PRCCU_Init(&PRCCU_InitStructure);

	TB_InitStructure.TB_CLK_Source = TB_CLK_INTERNAL  ;
	TB_InitStructure.TB_Prescaler = 31;
	TB_InitStructure.TB_Preload = 0xffff;
	TB_Init (TB0,&TB_InitStructure);
	
	TB_ITConfig (TB0,ENABLE);
	TB_Cmd(TB0,ENABLE);
	
	TsysCnt = 0xffff0000;
}

void SetUserTimer(uint32 *timer)
{
	uint32 temp;
	//uint16 TBx_SR;
	EIC->ICR &=2;	 //禁止中断
	temp = TB0->CNT;
	*timer = TsysCnt + temp; //notice:  必须先计算完成才能开中断。
	//TBx_SR = TB0->SR;
    EIC->ICR &=3;  //允许中断	
}
uint32 ReadUserTimer(uint32 *timer)
{
	uint32 temp;
	uint32 currentT;
	//uint16 TBx_SR;
	EIC->ICR &=2;   // 禁止中断
	temp = TB0->CNT;
	currentT = TsysCnt + temp; //notice:  必须先计算完成才能开中断。
	//TBx_SR = TB0->SR;
	EIC->ICR &=3;	 //允许中断

	return (*timer - currentT);
}




void Uart0Init(void)
{
   
   
    UART_InitTypeDef UART_InitStruct;
	
	CFG_PeripheralClockConfig(CFG_CLK_GPIO6,DISABLE);
	CFG_PeripheralClockConfig(CFG_CLK_GPIO6,ENABLE);

	GPIOx_Pinsx_INOUT_WP_Set(GPIO6,8);	//GPIO_Mode_INOUT_WP
	GPIOx_Pinsx_AF_PP_Set(GPIO6,9);

	/* UART Clock Enable */
	CFG_PeripheralClockConfig(CFG_CLK_UART0, DISABLE);
	CFG_PeripheralClockConfig(CFG_CLK_UART0, ENABLE);

	/* EIC Configuration */
	EIC_IRQChannelConfig(UART0_IRQChannel, ENABLE );
	EIC_IRQChannelPriorityConfig(UART0_IRQChannel,2);
  
	UART_StructInit(&UART_InitStruct);             /*Initialize Structure with default values*/
	UART_InitStruct.UART_BaudRate  = 19200;         /* Baud rate value */ 
	UART_InitStruct.UART_Mode = UART_Mode_8D_P ;   /*Set the UARTx Mode  8 bit Data + Parity */
	UART_InitStruct.UART_Loop_Standard = UART_Standard; /*Disable LoopBack*/
	UART_InitStruct.UART_StopBits = UART_StopBits_1; /* STOP bits number */
	UART_InitStruct.UART_Parity = UART_Parity_Even;
	UART_InitStruct.UART_FIFO = UART_FIFO_Enable;
	UART_InitStruct.UART_Rx = UART_Rx_Enable;
	UART_Cmd(UART0, ENABLE);
	UART_Init(UART0, &UART_InitStruct);
	UART_FifoReset(UART0,UART_TxFIFO);
    UART_FifoReset(UART0,UART_RxFIFO);
	UART_SetTimeOutValue(UART0, 0x3f);
}

⌨️ 快捷键说明

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