我想找个郑州做网站的,北京 企业建网站,discuz 做视频网站,网站建设基础与网页设计根据手册说明#xff0c;STC12C5A60S2 系列单片机可以直接使用 reg51.h 的头文件#xff0c;只是在用到相应的特殊功能寄存器时#xff0c;要做相应的定义即可。
笔记来自视频教程链接: https://www.bilibili.com/video/BV1Qq4y1Z7iS/?spm_id_from333.880.my_history.page…根据手册说明STC12C5A60S2 系列单片机可以直接使用 reg51.h 的头文件只是在用到相应的特殊功能寄存器时要做相应的定义即可。
笔记来自视频教程链接: https://www.bilibili.com/video/BV1Qq4y1Z7iS/?spm_id_from333.880.my_history.page.clickvd_sourceb91967c499b23106586d7aa35af46413 开启两个串口进行测试。 使用串口二的接收中断要把串口二中断使能给加进来。 IE2 0x01; //Enable UART2 interruptuart2.c 的代码如下
#include uart2.hextern void sendByte(unsigned char dat);void uart2_init(void) //9600bps11.0592MHz
{AUXR 0xF7; //波特率不倍速S2CON 0x50; //8位数据,可变波特率AUXR 0xFB; //定时器时钟12T模式BRT 0xFD; //设置定时重载值AUXR | 0x10; //启动独立波特率发射器IE2 0x01; //Enable UART2 interrupt
}void uart2_SendByte(unsigned char dat)
{S2BUF dat;while(!(S2CON S2TI)); // S2CON S2TI 0 时会一直等在这S2CON ~S2TI; // 手动清 0
}#if 0
void uart2_SendString(unsigned char *dat)
{while(*dat ! \0) {uart2_SendByte(*dat);}
}
#endifchar putchar(char c)
{uart2_SendByte(c);return c;
}/*----------------------------
UART2 interrupt service routine
----------------------------*/
void Uart2() interrupt 8
{unsigned char dat;if (S2CON S2RI){S2CON ~S2RI; //Clear receive interrupt flagdat S2BUF;sendByte(dat);}
}uart2.h 的代码如下
#ifndef _UART2_H_
#define _UART2_H_#include stc12c5a60s2.h#define S2RI 0x01 //S2CON.0
#define S2TI 0x02 //S2CON.1
#define S2RB8 0x04 //S2CON.2
#define S2TB8 0x08 //S2CON.3// 函数声明
extern void uart2_init(void);
extern void uart2_SendByte(unsigned char dat);
extern void uart2_SendString(unsigned char *dat);#endif工程是在基于串口超时接收用户自定义通讯协议的编程实现——协议内 CRC16 校验及接收应答处理基础上改的代码已上传至CSDN资料库。 12T – 12 分频 – 每12个时钟计数一次 1T – 不分频 – 每1个时钟计数一次
波特率设置为 115200