//这是一段求430波特率的计算程序//U_UxBR1,U_UxBR0,U_UxMCTL可以直接传送给相关寄存器//你只要设置以下两项UART_CLK,UART_BAUD//U_UxMCTL求取的思想://某位为0引起的(整数N分频)的累积误差,小于,为1引起的(整数N + 1分频)的累积误差,则取0,否则取1//由于预编译系统对小数比较大小,处理不便,因此把小数部分*256,换为整数处理//程序中的256到小数系统中就是1//为了与程序中其它的其它变量不重名,本预编译中所以常量都以"U_"开头并大写.//刘玉宏编写#define UART_CLK 1048576#define UART_BAUD 76800#define U_UxBR1 (UART_CLK/UART_BAUD)/256 //波特率分频整数部分的高8位#define U_UxBR0 (UART_CLK/UART_BAUD)%256 //波特率分频整数部分的低8位//波特率分频小数部分*256#define U_DECIMAL_FRACTION (((256*UART_CLK)/UART_BAUD) - 256*(UART_CLK/UART_BAUD))#define U_ERROR_SUM0 0 //累计误差//-------------------------------#if (U_ERROR_SUM0 - U_DECIMAL_FRACTION) > 0 //求某位为0时的累积误差绝对值 #define U_ER_BIT_IS_0 (U_ERROR_SUM0 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_0 -(U_ERROR_SUM0 - U_DECIMAL_FRACTION)#endif#if (U_ERROR_SUM0 + 256 - U_DECIMAL_FRACTION) > 0 //求某位为1时的累积误差绝对值 #define U_ER_BIT_IS_1 (U_ERROR_SUM0 + 256 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_1 -(U_ERROR_SUM0 + 256 - U_DECIMAL_FRACTION)#endif#if U_ER_BIT_IS_0 <= U_ER_BIT_IS_1 //据累积误差小者,取0或1 #define U_C0 0 #define U_ERROR_SUM1 U_ERROR_SUM0 - U_DECIMAL_FRACTION#else #define U_C0 1 #define U_ERROR_SUM1 U_ERROR_SUM0 + 256 - U_DECIMAL_FRACTION#endif#undef U_ER_BIT_IS_0#undef U_ER_BIT_IS_1//-------------------------------//-------------------------------#if (U_ERROR_SUM1 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_0 (U_ERROR_SUM1 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_0 -(U_ERROR_SUM1 - U_DECIMAL_FRACTION)#endif#if (U_ERROR_SUM1 + 256 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_1 (U_ERROR_SUM1 + 256 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_1 -(U_ERROR_SUM1 + 256 - U_DECIMAL_FRACTION)#endif#if U_ER_BIT_IS_0 <= U_ER_BIT_IS_1 #define U_C1 0 #define U_ERROR_SUM2 U_ERROR_SUM1 - U_DECIMAL_FRACTION#else #define U_C1 2 #define U_ERROR_SUM2 U_ERROR_SUM1 + 256 - U_DECIMAL_FRACTION#endif#undef U_ER_BIT_IS_0#undef U_ER_BIT_IS_1//-------------------------------//-------------------------------#if (U_ERROR_SUM2 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_0 (U_ERROR_SUM2 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_0 -(U_ERROR_SUM2 - U_DECIMAL_FRACTION)#endif#if (U_ERROR_SUM2 + 256 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_1 (U_ERROR_SUM2 + 256 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_1 -(U_ERROR_SUM2 + 256 - U_DECIMAL_FRACTION)#endif#if U_ER_BIT_IS_0 <= U_ER_BIT_IS_1 #define U_C2 0 #define U_ERROR_SUM3 U_ERROR_SUM2 - U_DECIMAL_FRACTION#else #define U_C2 4 #define U_ERROR_SUM3 U_ERROR_SUM2 + 256 - U_DECIMAL_FRACTION#endif#undef U_ER_BIT_IS_0#undef U_ER_BIT_IS_1//-------------------------------//-------------------------------#if (U_ERROR_SUM3 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_0 (U_ERROR_SUM3 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_0 -(U_ERROR_SUM3 - U_DECIMAL_FRACTION)#endif#if (U_ERROR_SUM3 + 256 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_1 (U_ERROR_SUM3 + 256 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_1 -(U_ERROR_SUM3 + 256 - U_DECIMAL_FRACTION)#endif#if U_ER_BIT_IS_0 <= U_ER_BIT_IS_1 #define U_C3 0 #define U_ERROR_SUM4 U_ERROR_SUM3 - U_DECIMAL_FRACTION#else #define U_C3 8 #define U_ERROR_SUM4 U_ERROR_SUM3 + 256 - U_DECIMAL_FRACTION#endif#undef U_ER_BIT_IS_0#undef U_ER_BIT_IS_1//-------------------------------//-------------------------------#if (U_ERROR_SUM4 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_0 (U_ERROR_SUM4 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_0 -(U_ERROR_SUM4 - U_DECIMAL_FRACTION)#endif#if (U_ERROR_SUM4 + 256 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_1 (U_ERROR_SUM4 + 256 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_1 -(U_ERROR_SUM4 + 256 - U_DECIMAL_FRACTION)#endif#if U_ER_BIT_IS_0 <= U_ER_BIT_IS_1 #define U_C4 0 #define U_ERROR_SUM5 U_ERROR_SUM4 - U_DECIMAL_FRACTION#else #define U_C4 16 #define U_ERROR_SUM5 U_ERROR_SUM4 + 256 - U_DECIMAL_FRACTION#endif#undef U_ER_BIT_IS_0#undef U_ER_BIT_IS_1//-------------------------------//-------------------------------#if (U_ERROR_SUM5 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_0 (U_ERROR_SUM5 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_0 -(U_ERROR_SUM5 - U_DECIMAL_FRACTION)#endif#if (U_ERROR_SUM5 + 256 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_1 (U_ERROR_SUM5 + 256 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_1 -(U_ERROR_SUM5 + 256 - U_DECIMAL_FRACTION)#endif#if U_ER_BIT_IS_0 <= U_ER_BIT_IS_1 #define U_C5 0 #define U_ERROR_SUM6 U_ERROR_SUM5 - U_DECIMAL_FRACTION#else #define U_C5 32 #define U_ERROR_SUM6 U_ERROR_SUM5 + 256 - U_DECIMAL_FRACTION#endif#undef U_ER_BIT_IS_0#undef U_ER_BIT_IS_1//-------------------------------//-------------------------------#if (U_ERROR_SUM6 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_0 (U_ERROR_SUM6 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_0 -(U_ERROR_SUM6 - U_DECIMAL_FRACTION)#endif#if (U_ERROR_SUM6 + 256 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_1 (U_ERROR_SUM6 + 256 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_1 -(U_ERROR_SUM6 + 256 - U_DECIMAL_FRACTION)#endif#if U_ER_BIT_IS_0 <= U_ER_BIT_IS_1 #define U_C6 0 #define U_ERROR_SUM7 U_ERROR_SUM6 - U_DECIMAL_FRACTION#else #define U_C6 64 #define U_ERROR_SUM7 U_ERROR_SUM6 + 256 - U_DECIMAL_FRACTION#endif#undef U_ER_BIT_IS_0#undef U_ER_BIT_IS_1//-------------------------------//-------------------------------#if (U_ERROR_SUM7 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_0 (U_ERROR_SUM7 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_0 -(U_ERROR_SUM7 - U_DECIMAL_FRACTION)#endif#if (U_ERROR_SUM7 + 256 - U_DECIMAL_FRACTION) > 0 #define U_ER_BIT_IS_1 (U_ERROR_SUM7 + 256 - U_DECIMAL_FRACTION)#else #define U_ER_BIT_IS_1 -(U_ERROR_SUM7 + 256 - U_DECIMAL_FRACTION)#endif#if U_ER_BIT_IS_0 <= U_ER_BIT_IS_1 #define U_C7 0 #define U_ERROR_SUM8 U_ERROR_SUM7 - U_DECIMAL_FRACTION#else #define U_C7 128 #define U_ERROR_SUM8 U_ERROR_SUM7 + 256 - U_DECIMAL_FRACTION#endif#undef U_ER_BIT_IS_0#undef U_ER_BIT_IS_1//-------------------------------#define U_UxMCTL U_C7 + U_C6 + U_C5 + U_C4 + U_C3 + U_C2 + U_C1 + U_C0//-------------------------------//本次预编译到此结束,你可以使用U_UxBR1;U_UxBR0;U_UxMCTL;给相关寄存器赋值.//-------------------------------unsigned int b1=U_UxBR1;unsigned int b0=U_UxBR0;unsigned int m= U_UxMCTL;main(){ while(1);}
导读:目前正在解读《用预编译的方法实现430单片机计算波特率》的相关信息,《用预编译的方法实现430单片机计算波特率》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《用预编译的方法实现430单片机计算波特率》的详细说明。
简介:本文介绍的是用预编译的方法实现430单片机计算波特率的程序设计。
提醒:《用预编译的方法实现430单片机计算波特率》最后刷新时间 2024-03-14 01:10:40,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《用预编译的方法实现430单片机计算波特率》该内容的真实性请自行鉴别。