本帖最后由 ltbytyn 于 2012-1-7 10:26 编辑
#include "Smpl_Drv_DS1820.h"
volatile uint16_t value = 0 ;
volatile uint8_t mark; //温度正负标志
volatile uint8_t IsStart = FALSE;
volatile uint8_t Receive_Data = 0;
void UART_INT_HANDLE(uint32_t u32IntStatus)
{
uint8_t bInChar[1]={0xFF};
if(u32IntStatus & DRVUART_RDAINT)
{
/* Get all the input characters */
while(UART0->ISR.RDA_IF==1)
{
/* Get the character from UART Buffer */
DrvUART_Read(UART_PORT0,bInChar,1);
if (IsStart!=TRUE)
{
IsStart = TRUE;
Receive_Data = bInChar[0];
}
}
}
}
void Init_Uart(void)
{
STR_UART_T param;
/*
声明 UART设置的结构体 位于DRVUART.H
结构体如下
typedef struct DRVUART_STRUCT
{
uint32_t u32BaudRate;
E_DATABITS_SETTINS u8cDataBits;
E_STOPBITS_SETTINS u8cStopBits;
E_PARITY_SETTINS u8cParity;
E_FIFO_SETTINGS u8cRxTriggerLevel;
uint8_t u8TimeOut ;
}STR_UART_T;
*/
DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC,0); //使能UART时钟
//SYSCLK->CLKSEL1.UART_S = 0; //UART时钟源选择. 00 =外部12MHz 晶振 01 = PLL 1x =内部 22MHz 振荡器
DrvGPIO_InitFunction(E_FUNC_UART0); //GPB_MFP0-1-2-3置位 GPIO使能UART功能
//outpw(&SYS->GPBMFP, inpw(&SYS->GPBMFP) | (0xF<<0));
param.u32BaudRate = 115200; // 波特率
param.u8cDataBits = DRVUART_DATABITS_8; // 数据位
param.u8cStopBits = DRVUART_STOPBITS_1; // 停止位
param.u8cParity = DRVUART_PARITY_NONE; // 校验位
param.u8cRxTriggerLevel = DRVUART_FIFO_1BYTES; // FIFO存储深度 1 字节
param.u8TimeOut = 0; // FIFO超时设定
/* Set UART Configuration */
if(DrvUART_Open(UART_PORT0,¶m) != E_SUCCESS) // 串口开启、结构体整体赋值
printf("UART0 open failed\n");
/* u32Port -[in] UART Channel: UART_PORT0 / UART_PORT1 /UART_PORT2 */
/* sParam -[in] the struct parameter to configure UART */
/* Enable Interrupt and install the call back function */
DrvUART_EnableInt(UART_PORT0, DRVUART_RDAINT,UART_INT_HANDLE);
/*u32Port -[in] UART Channel: UART_PORT0 / UART_PORT1 / UART_PORT2 */
/*u32InterruptFlag -[in] DRVUART_LININT/DRVUART_WAKEUPINT/DRVUART_BUFERRINT/DRVUART_RLSINT */
/* DRVUART_MOSINT/DRVUART_THREINT/DRVUART_RDAINT/DRVUART_TOUTINT */
/*pfncallback -[in] A function pointer for callback function */
}
int main (void)
{
Set_System();
Init_Uart();
printf("======温度实验=====\n");
while(1)
{
value = read_temp();
printf("当前温度: %d.%d℃",value/10,value%10);
delay_ms(2000);
}
}
有详细注释。
Smpl_Drv_DS18B20.rar
(1.32 MB)
|