- void UART0_Init()
- {
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init UART */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Reset IP */
- SYS_ResetModule(UART0_RST);
- /* Configure UART0 and set UART0 Baudrate */
- UART_Open(UART0, 115200);
- //UART_Open(UART0, 9600);
- /* Enable Interrupt and install the call back function */
- UART_ENABLE_INT(UART0, (UART_IER_RDA_IEN_Msk));// | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
- NVIC_EnableIRQ(UART0_IRQn);
- // while(g_bWait);
- }
- void Uart0Send(int32_t Bytes)
- {
- UART0->THR = Bytes;
- while ((UART0->FSR&TX_EMPTY) != 0x00); //检查发送FIFO是否为空
- }
- /*---------------------------------------------------------------------------------------------------------*/
- /* MAIN function */
- /*---------------------------------------------------------------------------------------------------------*/
- int main(void)
- {
- //int8_t i,j;
- SYS_UnlockReg();/* Unlock protected registers */
- SYS_Init();/* Init System, IP clock and multi-function I/O */
- SYS_LockReg();/* Lock protected registers */
- UART0_Init();/* Init UART0 for printf and testing */
- buff_init();
- /*---------------------------------------------------------------------------------------------------------*/
- /* SAMPLE CODE */
- /*---------------------------------------------------------------------------------------------------------*/
- printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz\n", SystemCoreClock);
- printf("\r\n 世界,你好!\r\n");
- printf("\r\n USART0测试正常! \r\n");
- while(1)
- {
- com_command_receive();
- }
- }
- COMINT.C
- /****************************************************************************/
- /* */
- /* Copyright (c) 2016, 老马工作室 */
- /* All rights reserved. */
- /* */
- /* Email:pcwebmaster@163.com */
- /****************************************************************************/
- /****************************************************************************/
- /* 文 件 名:comint.c */
- /* 版 本:Version 1.0 */
- /* 描 述:串行口中断带通讯协议测试 */
- /* 主控芯片:NuMicro M0516*/
- /* 晶振频率:11.0592MHz */
- /* 作 者:pcwebmaster(北极狼) */
- /* 函 数: */
- /* system_init */
- /* com_send_command */
- /* com_command_receive*/
- /*CalCRC16_1021*/
- /*command_decoder*/
- /*send_command*/
- /* 测 试: 发送:16 16 02 01 02 01 00 35 03 94 BD接收:49 AA 15 */
- /* 测试现象: */
- /* 历史记录:20016.02.18测试通过 */
- /* 北极狼 20016-02-18 Creat Inital version. (Version 1.0) */
- /****************************************************************************/
- #include "comint.h"
- uint8_t pint_buf[MAX_RINTL]; /* 串口接收缓冲区 */
- uint8_t pint_read; /* 串口缓冲区读指针 */
- uint8_t pint_write; /* 串口缓冲区写指针 */
- uint8_t psend_int; /* 串口发送允许标志 */
- uint8_t serial_flag = 0; /* 串口接收数据标志位 */
- uint8_t prec_buf[MAX_COMMAND_LEN];/* 命令接收缓冲区 */
- uint8_t prec_num; /* 命令接收缓冲区字节数 */
- uint8_t serial_lengthl = 0; /* 消息命令长度低8位 */
- uint16_t serial_length = 0; /* 消息命令长度16位 */
- uint8_t ADDRESS[2]={ZU,ZHAN}; /* byte0:通讯组地址, byte1:开发板地址 */
|