#include "NUC1XX.h"
#include "DrvSYS.h"
#include "DrvGPIO.h"
#include "DrvTIMER.h"
#include "DrvUART.h"
#include "stdio.h"
uint8_t time=0;
void TMR_Callback(uint32_t age)
{
time++;
printf("In time0 call back\n");
if(time>2)
{
DrvGPIO_ClrBit(E_GPA,2);
}
else
DrvGPIO_SetBit(E_GPA,2);
if(time>4)
time=0;
}
void InitTIMERCountTime()
{
DrvTIMER_Init();
DrvSYS_SelectIPClockSource(E_SYS_TMR0_CLKSRC, 0); /* Set all the default TIMER clock sources are from 12MHz */
DrvTIMER_Open(E_TMR0, 10, E_PERIODIC_MODE); /* Using TIMER0 in PERIODIC_MODE, 2 ticks /sec */
DrvTIMER_SetTimerEvent(E_TMR0, 1, (TIMER_CALLBACK)TMR_Callback, 1);
DrvTIMER_EnableInt(E_TMR0); /* Enable TIMER0 Intettupt */
DrvTIMER_Start(E_TMR0); /* Start counting */
}
void InitUARTDebugPort(void)
{
STR_UART_T param;
/* Select UART Clock Source From 12MHz */
DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, 0);
param.u32BaudRate = 115200;
param.u8cDataBits = DRVUART_DATABITS_8;
param.u8cStopBits = DRVUART_STOPBITS_1;
param.u8cParity = DRVUART_PARITY_NONE;
param.u8cRxTriggerLevel = DRVUART_FIFO_1BYTES;
param.u8TimeOut = 0;
if (DEBUG_PORT == 1)
{
/* Set UART1 pins */
DrvGPIO_InitFunction(E_FUNC_UART1);
/* Set UART1 configuration */
DrvUART_Open(UART_PORT1, ¶m);
}else
{
/* Set UART0 pins */
DrvGPIO_InitFunction(E_FUNC_UART0);
/* Set UART0 configuration */
DrvUART_Open(UART_PORT0, ¶m);
}
}
int main (void)
{
UNLOCKREG();
DrvSYS_SetOscCtrl(E_SYS_XTL12M, ENABLE); /* Enable External 12M Xtal */
DrvSYS_Delay(5000); /* Waiting for 12M Xtal stable */
DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, 0); /* Select UART Clock Source From 12MHz */
InitUARTDebugPort(); /* Initial UART debug message function */
DrvSYS_Open(50000000);
InitTIMERCountTime();
DrvGPIO_Open(E_GPA,2,E_IO_OUTPUT);
DrvGPIO_ClrBit(E_GPA,2);
while(1);
}
2L贴一个简单的代码 |