芯片复制NuMicro M0516-PC通讯协议
| 芯片复制main.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 <stdio.h> #include "M051Series.h" #include "comint.h" #define PLL_CLOCK 50000000 /*---------------------------------------------------------------------------------------------------------*/ /* Global variables */ /*---------------------------------------------------------------------------------------------------------*/ void SYS_Init(void) { /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ /* Enable Internal RC 22.1184MHz clock */ CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk); /* Waiting for Internal RC clock ready */ CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk); /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */ CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1)); /* Enable external XTAL 12MHz clock */ CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk); /* Waiting for external XTAL clock ready */ CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk); /* Set core clock as PLL_CLOCK from PLL */ CLK_SetCoreClock(PLL_CLOCK); /* Enable UART module clock */ CLK_EnableModuleClock(UART0_MODULE); /* Select UART module clock source */ // CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));CLK_CLKSEL1_UART_S_HIRC CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HIRC, CLK_CLKDIV_UART(1)); /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* Set P3 multi-function pins for UART0 RXD and TXD */ SYS->P3_MFP &= ~(SYS_MFP_P30_Msk | SYS_MFP_P31_Msk); SYS->P3_MFP |= (SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0); } 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 */ |

芯片解密