求助!!Ai8051U的串口打印RTC时钟范例无法使用
本帖最后由 星陨之雨 于 2024-11-13 15:47 编辑//8bit
//测试工作频率为11.0592MHz
#include <AI8051U.H>
#include "intrins.h"
#include "stdio.h"
#define MAIN_Fosc 22118400L
#define Baudrate 115200L
#define TM (65536-(MAIN_Fosc/Baudrate+2)/4)
bit B1S_Flag;
void RTC_config(void);
void UartInit(void)
{
SCON = (SCON & 0x3F)|0x40;
T2L = TM;
T2H = TM >> 8;
S1BRT = 1;
T2x12 = 1;
T2R = 1;
}
void UartPutc(unsigned char dat)
{
SBUF = dat;
while(TI == 0);
TI = 0;
}
char putchar(char c)
{
UartPutc(c);
return c;
}
void RTC_Isr() interrupt 13
{
if(RTCIF & 0x08)
{
RTCIF &= ~0x08;
B1S_Flag = 1;
}
}
void main(void)
{
P_SW2 = 0x80; //使能XFR,没有冲突不用关闭
CKCON = 0x00; //设置外部数据总线速度为最快
WTST = 0x00; //设置程序代码等待参数
//赋值为0可将CPU执行程序的速度设置为最快
P0M1 = 0x00; P0M0 = 0x00;//配置P0口为准双向口
P1M1 = 0x00; P1M0 = 0x00;//配置P1口为准双向口
P2M1 = 0x00; P2M0 = 0x00;//配置P2口为准双向口
P3M1 = 0x00; P3M0 = 0x00;//配置P3口为准双向口
P4M1 = 0x00; P4M0 = 0x00;//配置P4口为准双向口
P5M1 = 0x00; P5M0 = 0x00;//配置P5口为准双向口
UartInit();
RTC_config();
EA = 1;
printf("RTC Test Programme!\r\n");
while(1)
{
if(B1S_Flag)
{
B1S_Flag = 0;
printf("Year=20%bd ",YEAR);
printf("Month=%bd ",MONTH);
printf("Day=%bd ",DAY);
printf("Hour=%bd ",HOUR);
printf("Minute=%bd ",MIN);
printf("Second=%bd ",SEC);
printf("\r\n");
}
}
}
void RTC_config(void)
{
X32KCR = 0xC0;
while(!(X32KCR & 0x01));
RTCCFG &= ~0x02;
INIYEAR = 21;
INIMONTH = 12;
INIDAY = 31;
INIHOUR = 23;
INIMIN = 59;
INISEC = 50;
INISSEC = 0;
RTCIF = 0;
RTCIEN = 0X08;
RTCCR = 0X01;
RTCCFG |= 0X01;
while(RTCCFG & 0x01);
}
编译后会报错
User\main.c(17): error C202: 'T2L': undefined identifier
User\main.c(18): error C202: 'T2H': undefined identifier
在头文件里我没有找到T2L、T2H,但是找到了TL2、TH2
但是会报一个User\main.c(19): error C213: left side of asn-op not an lvalue
无法解决,求大佬帮助
复制粘贴你的没问题
本帖最后由 邮箱 于 2024-11-12 21:06 编辑
8051U 8位的
AUXR |= S1BRT; 使用最新版Ai ISP添加头文件和仿真器驱动
https://www.stcaimcu.com/data/download/Tools/AIapp-ISP-v6.94X.zip
邮箱 发表于 2024-11-12 20:34
复制粘贴你的没问题
是八位的吗{:5_295:} DebugLab 发表于 2024-11-12 22:46
使用最新版Ai ISP添加头文件和仿真器驱动
https://www.stcaimcu.com/data/download/Tools/AIapp-ISP-v6.94X ...
试过了,不可以{:5_270:} 邮箱 发表于 2024-11-12 21:04
8051U 8位的
AUXR |= S1BRT;
不好意思{:5_270:},没有明白,可以说详细一点吗{:5_270:} RTC并无问题,可以使用,但是串口不知道哪里错了,求大佬指点
星陨之雨 发表于 2024-11-13 15:46
RTC并无问题,可以使用,但是串口不知道哪里错了,求大佬指点
本帖最后由 邮箱 于 2024-11-13 17:34 编辑
星陨之雨 发表于 2024-11-13 15:40
不好意思,没有明白,可以说详细一点吗
报错 User\main.c(19): error C213: left side of asn-op not an lvalue
8051u 8位的 S1BRT 不能位操作,只能
AUXR |= S1BRT; //选择定时器 2 作为波特率发射器
AUXR &= ~S1BRT; //选择定时器 1 作为波特率发射器
页:
[1]
2