19
16
369
中级会员
<div> <div>#include "AI8051U.h" #include "intrins.h" #include "stdio.h" #include "math.h" #define MAIN_Fosc 24000000UL volatile unsigned long int near uint1, uint2; volatile unsigned long int near xuint; volatile long int sint1, sint2; volatile long int xsint; unsigned long ultest; long ltest; /*****************************************************************************/ sbit TPIN = P1^0; /*****************************************************************************/ #define Baudrate 115200L #define TM (65536 -(MAIN_Fosc/Baudrate/4)) #define PrintUart 1 //1:printf 使用 UART1; 2:printf 使用 UART2 /******************** 串口打印函数 ********************/ void UartInit(void) { #if(PrintUart == 1) S1_S1 = 0; //UART1 switch to, 0x00: P3.0 P3.1, 0x40: P3.6 P3.7, 0x80: P1.6 P1.7, 0xC0: P4.3 P4.4 S1_S0 = 1; SCON = (SCON & 0x3f) | 0x40; T1x12 = 1; //定时器时钟1T模式 S1BRT = 0; //串口1选择定时器1为波特率发生器 TL1 = TM; TH1 = TM>>8; TR1 = 1; //定时器1开始计时 // SCON = (SCON & 0x3f) | 0x40; // T2L = TM; // T2H = TM>>8; // AUXR |= 0x15; //串口1选择定时器2为波特率发生器 #else S2_S = 1; //UART2 switch to: 0: P1.2 P1.3, 1: P4.2 P4.3 S2CFG |= 0x01; //使用串口2时,W1位必需设置为1,否则可能会产生不可预期的错误 S2CON = (S2CON & 0x3f) | 0x40; T2L = TM; T2H = TM>>8; AUXR |= 0x14; //定时器2时钟1T模式,开始计时 #endif } void UartPutc(unsigned char dat) { #if(PrintUart == 1) SBUF = dat; while(TI==0); TI = 0; #else S2BUF = dat; while(S2TI == 0); S2TI = 0; //Clear Tx flag #endif } char putchar(char c) { UartPutc(c); return c; } void delay(unsigned char ms) { while(--ms); } void PLL_Init() { // CLKSEL &= ~0x80; //选择PLL的96M(*8)作为PLL的输出时钟 CLKSEL |= 0x80; //选择PLL的144M(*12)作为PLL的输出时钟 USBCLK &= ~0x60; // USBCLK |= 0x00; //PLL输入时钟为12M则选择1分频 // USBCLK |= 0x20; //PLL输入时钟为24M则选择2分频 USBCLK |= 0x40; //PLL输入时钟为48M则选择4分频 // USBCLK |= 0x60; //PLL输入时钟为96M则选择8分频 USBCLK |= 0x80; //启动PLL delay(1000); //等待PLL锁频,建议50us以上 HSCLKDIV = 0; //高速外设时钟源不分频 TFPU_CLKDIV = 0; //TFPU时钟源不分频 // CLKSEL &= ~0x40; //选择系统时钟作为高速外设时钟源 CLKSEL |= 0x40; //选择PLL时钟作为高速外设时钟源 } /*****************************************************************************/ void main(void) { float f1=223.57; float f2=764.84; float f3=0; WTST = 0; //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快 EAXFR = 1; //扩展寄存器(XFR)访问使能 CKCON = 0; //提高访问XRAM速度 P0M1 = 0x00; P0M0 = 0x00; //设置为准双向口 P1M1 = 0x00; P1M0 = 0x00; //设置为准双向口 P2M1 = 0x00; P2M0 = 0x00; //设置为准双向口 P3M1 = 0x00; P3M0 = 0x00; //设置为准双向口 P4M1 = 0x00; P4M0 = 0x00; //设置为准双向口 P5M1 = 0x00; P5M0 = 0x00; //设置为准双向口 P6M1 = 0x00; P6M0 = 0x00; //设置为准双向口 P7M1 = 0x00; P7M0 = 0x00; //设置为准双向口 UartInit(); PLL_Init(); // DMAIR = 0x3e; //TFPU使用系统时钟作为时钟源 DMAIR = 0x3f; //TFPU使用高速外设时钟作为时钟源 //*** 必须设置此句,TFPU才能使用高速时钟作为时钟源 *** while(1) { //printf("start...\r\n"); TPIN=1; f3 = f1 + f2; // f3 = f1 - f2; // f3 = f1 * f2; // f3 = f1 / f2; TPIN=0; } } /*****************************************************************************/</div> </div>复制代码
使用道具 举报 送花
本版积分规则 发表回复 回帖后跳转到最后一页
|手机版|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )
GMT+8, 2026-4-2 21:11 , Processed in 0.104090 second(s), 49 queries .
Powered by Discuz! X3.5
© 2001-2026 Discuz! Team.