本帖最后由 cnjxlxp 于 2012-4-15 22:18 编辑
前段时间玩了M0一直没整理,今天整理一下发上来共享一下。
#include <stdio.h>
#include "NUC1xx.h"
#include "DrvGPIO.h"
#include "DrvUART.h"
#include "DrvSYS.h"
uint8_t writechar1[1] ={0x55};//default write char
uint8_t getchar1;
void UART_INT_HANDLE(void) // UART02 interrupt subroutine
{
DrvUART_Read(UART_PORT0,writechar1,1);//driver read uart
DrvSYS_Delay(5000);
DrvUART_Write(UART_PORT0,writechar1,1); //driver write uart
DrvUART_ClearIntFlag(UART_PORT0, DRVUART_RDAINT);
}
//uart set//n,8,1,9600
void uart_init(void)
{
STR_UART_T param;
DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, 0);//UART clock is ex 12M
//SYSCLK->CLKSEL1.UART_S = 0;
//UART clock 00 =ex 12MHz 01 = PLL 1x =inner 22MHz
DrvGPIO_InitFunction(E_FUNC_UART0); //GPIO use as uart
param.u32BaudRate = 9600;
param.u8cDataBits = DRVUART_DATABITS_8;
param.u8cStopBits = DRVUART_STOPBITS_1;
param.u8cParity = DRVUART_PARITY_NONE;
param.u8cRxTriggerLevel = DRVUART_FIFO_1BYTES;
param.u8TimeOut = 0; // FIFO time out
DrvUART_Open(UART_PORT0, ¶m);
DrvUART_ClearIntFlag(UART_PORT0, DRVUART_RDAINT);
DrvUART_EnableInt(UART_PORT0,DRVUART_RDAINT,UART_INT_HANDLE);
}
void Sys_Init()
{
UNLOCKREG();
SYSCLK->WRCON.XTL12M_EN = 1;//12M
//DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);
DrvSYS_Delay(5000);
//while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1);
//SYSCLK->CLKSTATUS.XTL12M_STB
LOCKREG();
uart_init();
DrvGPIO_Open(E_GPB, 10, E_IO_OUTPUT);//GPB10 output
DrvGPIO_ClrBit(E_GPB, 10);//if not clear GPB10, the buzzer will on. the default output is 0xffff;
DrvGPIO_Open(E_GPA,2, E_IO_OUTPUT); //GPA2 output, LED1
DrvGPIO_Open(E_GPA,3, E_IO_OUTPUT); //GPA3 output, LED2
}
void delay_ms(void)//delay form xiaobing's source code
{
uint32_t i,j;
for(i=1000;i>0;i--)
for(j=2395;j>0;j--);
}
int main (void)
{
Sys_Init();
while(1)
{
;
}
}
|