为了测试STC8F/A的PCA脉冲测量脉宽,需要一个精确的外部时钟源。参考STC-ISP范例程序进行了测试,以下程序实现了选择外部时钟源。
/*
STC8F/A系统时钟源选择外部时钟串口测试程序
外部晶振为11.0592M,串口波特率设置在115200
验证方法:
1 编译后 STC-ISP下载内部IRC频率可选任意值
2 串口设置成“编程完成后自动打开串口”
3 串口波特率设置成115200
4 下载完成后串口接受区自动显示“STC8系统时钟源串口测试!”
5 可在发送缓冲区发送数据,数据可大于接收缓存16字节,接收区能正常显示
证明选择外部晶振时钟源成功!
*/
#include "reg51.h"
#include "intrins.h"
//#include "STC8Axx.h"
#define CKSEL (*(unsigned char volatile xdata *)0xfe00)
#define CKDIV (*(unsigned char volatile xdata *)0xfe01)
#define IRC24MCR (*(unsigned char volatile xdata *)0xfe02)
#define XOSCCR (*(unsigned char volatile xdata *)0xfe03)
#define IRC32KCR (*(unsigned char volatile xdata *)0xfe04)
#define FOSC 11059200UL
#define BRT (65536 - FOSC / 115200 / 4)
sfr AUXR = 0x8e;
sfr P_SW2 = 0xba;
bit busy;
char wptr;
char rptr;
char buffer[16];
void UartIsr() interrupt 4
{
if (TI)
{
TI = 0;
bu

本文档详细介绍了如何在STC8F/A单片机中通过配置外部时钟源实现精确的脉冲测量,并提供了使用STC-ISP范例程序的步骤。通过设置串口波特率为115200,验证了外部晶振的选择和系统时钟源的成功切换。
最低0.47元/天 解锁文章
3233





