芯片解密NuMicro M0516-PC通讯协议
芯片解密main.c
/****************************************************************************/
/* */
/* 芯片解密 */
/* 芯片解密 */
/* 芯片解密 */
/* 芯片解密 */
/****************************************************************************/
/****************************************************************************/
/* 文 件 名:comint.c */
/* 版 本:Version 1.0 */
/* 描 述:串行口中断带通讯协议测试 */
/* 主控芯片:NuMicro M0516*/
/* 晶振频率:11.0592MHz */
/* 函 数: */
/* system_init */
/* com_send_command */
/* com_command_receive*/
/*CalCRC16_1021*/
/*command_decoder*/
/*send_command*/
/****************************************************************************/
#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 */
buff_init();
/*---------------------------------------------------------------------------------------------------------*/
/* SAMPLE CODE */
/*---------------------------------------------------------------------------------------------------------*/
printf("\n\nCPU @ %dHz\n", SystemCoreClock);
printf("\r\n 世界,你好!\r\n");
printf("\r\n USART0测试正常! \r\n");
while(1)
{
com_command_receive();
}

芯片解密