/*-------------------------------------------------------*/
/* 变量区 */
/*-------------------------------------------------------*/
/*-------------------------------------------------------*/
/* 函数区 */
/*-------------------------------------------------------*/
/****************************************
*函数名称:main
*输 入:无
*输 出:无
*功 能:函数主体
******************************************/
INT32 main(VOID)
{
const uint8_t acCRCSrcPattern[] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39};
uint32_t i, u32TargetChecksum = 0x58, u32CalChecksum = 0;
PROTECT_REG
(
/*1.系统时钟初始化 */
SYS_Init(PLL_CLOCK);
/*2.串口0初始化 */
UART0_Init(115200);
)
printf("\n\nCPU @ %d Hz\n", SystemCoreClock);
printf("+-----------------------------------------+\n");
printf("| CRC-8 Polynomial Mode Sample Code |\n");
printf("+-----------------------------------------+\n\n");
printf("# Calculate [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39] CRC-8 checksum value.\n");
printf(" - Seed value is 0x5A \n");
printf(" - CPU write data length is 8-bit \n");
printf(" - Checksum complement disable \n");
printf(" - Checksum reverse disable \n");
printf(" - Write data complement disable \n");
printf(" - Write data reverse disable \n");
printf(" - Checksum should be 0x%X \n\n", u32TargetChecksum);
/* Configure CRC controller for CRC-8 CPU mode */
CRC_Open(CRC_8, 0, 0x5A, CRC_CPU_WDATA_8);
/* Start to execute CRC-8 CPU operation */
for(i = 0; i < sizeof(acCRCSrcPattern); i++)
{
CRC_WRITE_DATA((acCRCSrcPattern & 0xFF));
}
/* Get CRC-8 checksum value */
u32CalChecksum = CRC_GetChecksum();
printf("CRC checksum is 0x%X ... %s.\n", u32CalChecksum, (u32CalChecksum == u32TargetChecksum) ? "PASS" : "FAIL");
/* Disable CRC function */
CRC->CTL &= ~CRC_CTL_CRCEN_Msk;
while(1);
}
/*-------------------------------------------------------*/
/* 中断服务函数 */
/*-------------------------------------------------------*/
|