求stc单片机的PCA定时器程序!!!

有程序最好,,我调了好久都没跳出来!!没有的话求高手解答!!!CCAP0H=0x78; //PCA定时器寄存器值,50ms,7.3728MHz这是什么意思!!

/* --- 演示 STC 1T 系列单片机 用PCA功能实现16位定时器 --------*/
#include "reg51.h"
#include "intrins.h"
#define FOSC 18432000L
#define T100Hz (FOSC / 12 / 100)
typedef unsigned char BYTE;
typedef unsigned int WORD;
/*Declare SFR associated with the PCA */
sfr CCON = 0xD8; //PCA control register
sbit CCF0 = CCON^0; //PCA module-0 interrupt flag
sbit CCF1 = CCON^1; //PCA module-1 interrupt flag
sbit CR = CCON^6; //PCA timer run control bit
sbit CF = CCON^7; //PCA timer overflow flag
sfr CMOD = 0xD9; //PCA mode register
sfr CL = 0xE9; //PCA base timer LOW
sfr CH = 0xF9; //PCA base timer HIGH
sfr CCAPM0 = 0xDA; //PCA module-0 mode register
sfr CCAP0L = 0xEA; //PCA module-0 capture register LOW
sfr CCAP0H = 0xFA; //PCA module-0 capture register HIGH
sfr CCAPM1 = 0xDB; //PCA module-1 mode register
sfr CCAP1L = 0xEB; //PCA module-1 capture register LOW
sfr CCAP1H = 0xFB; //PCA module-1 capture register HIGH
sfr PCAPWM0 = 0xf2;
sfr PCAPWM1 = 0xf3;
sbit PCA_LED = P1^0; //PCA test LED
BYTE cnt;
WORD value;
void PCA_isr() interrupt 7 using 1
{
CCF0 = 0; //Clear interrupt flag
CCAP0L = value;
CCAP0H = value >> 8; //Update compare value
value += T100Hz;
if (cnt-- == 0)
{
cnt = 100; //Count 100 times
PCA_LED = !PCA_LED; //Flash once per second
}
}
void main()
{
CCON = 0; //Initial PCA control register
//PCA timer stop running
//Clear CF flag
//Clear all module interrupt flag
CL = 0; //Reset PCA base timer
CH = 0;
CMOD = 0x00; //Set PCA timer clock source as Fosc/12
//Disable PCA timer overflow interrupt
value = T100Hz;
CCAP0L = value;
CCAP0H = value >> 8; //Initial PCA module-0
value += T100Hz;
CCAPM0 = 0x49; //PCA module-0 work in 16-bit timer mode
//and enable PCA interrupt
CR = 1; //PCA timer start run
EA = 1;
cnt = 0;
while (1);
}
温馨提示:内容为网友见解,仅供参考
无其他回答

求stc单片机的PCA定时器程序!!!
sfr CCON = 0xD8; \/\/PCA control register sbit CCF0 = CCON^0; \/\/PCA module-0 interrupt flag sbit CCF1 = CCON^1; \/\/PCA module-1 interrupt flag sbit CR = CCON^6; \/\/PCA timer run control bit sbit CF = CCON^7; \/\/PCA timer overflow flag sfr CMOD = 0xD9; \/\/PCA m...

用STC单片机的PCA做定时器,输出PWM
CCON = 0; \/\/初始化PCA控制寄存器 \/\/PCA定时器停止 \/\/清除CF标志 \/\/清除模块中断标志 CL = CH = 0; \/\/复位PCA计数寄存器 CMOD = 0x08; \/\/设置PCA时钟源为sysclock,禁止PCA计数器溢出中断 CCAPM1 = 0x4d; \/\/0100 1101 \/\/PCA模块1为16位定时器模式,同时反转(P2.6)口 PPC...

stc单片机PCA高速输出脉冲程序
CCON = 0; \/\/初始化PCA控制寄存器,PCA定时器停止,清除CF标志,清除模块中断标志 CL = 0; \/\/复位PCA计数寄存器 CH = 0;CMOD = 0x02; \/\/设置PCA时钟源为sysclock\/2,禁止PCA定时器溢出中断 value = T100KHz; \/\/计算PCA输出100K方波应设定的值 CCAP0L = value; \/\/将值得低...

stc单片机中的pca定时器跟普通定时器有什么不同
PCA——可编程计数器阵列 STC手册中把概念模块化了,他的PCA包含两个 捕获\/比较匹配 模块,可以实现上升沿\/下降沿捕获,及捕获中断,或者比较匹配中断,或者PWM,或者最普通的定时\/计数器。 其实就是个功能稍微强大点的定时器 - -! 比如STC12C2052AD,它的PCA是16位的计数器,计数脉冲可选(时钟分频后做为计数信号,或...

请教STC单片机timer0和PCA模块的问题!
定时器0作为PCA模块时钟源后, 其溢出速度可能会很快(根据你的设置而定),开放timer0中断会频繁的进入中断,极端情况下,比如,24MHZ,定时器0分频为12,则溢出率为2MHZ, MCU基本就在中断里了.所以,定时器0作为PCA模块时钟源后,不要允许中断,被独占.

STC单片机定时器怎么用
STC单片机的PCA定时器是配合其硬件PWM功能使用的可编程定时器,一般情况下当使用硬件PWM功能时需要配置PCA定时器,至于其他用途使用可以参看数据手册。关于“指定定时引脚”,51内核的单片机的定时器的全称呼为“定时\/计数器Tx”,字面上既可以知道,它既可以做定时器用也可以做计数器用,当用着计数器时,...

STC12C5A60S2单片机怎么才能输出占空比可调的PWM
CCAP1H=0x00; \/\/ PWM1初始时为0 CR=1; \/\/启动PCA定时器 } void PWM1_set (uchar a)\/\/PWM1占空比设置函数 { CCAP1L=a; \/\/设置值直接写入CCAP1L CCAP1H=a; \/\/设置值直接写入CCAP1H } 主程序中,按预想规律改变PWM1_set (uchar a)的参数即可调节占空比 ...

stc12c pwm例程 定时器0
void main(){ CMOD |=0x04;CL=0;CH=0;CR=1;AUXR |=0x80;TMOD |=0x02;TH0= 256-10;TL0= 256-10;TR0= 1;ET0= 1;CCAP0L = 0x80; \/\/Set the initial value same as CCAP0H CCAP0H = 0x80; \/\/25% Duty Cycle CCAPM0 = 0x42;\/\/0x42 Setup PCA module 0 in PWM mode whil...

关于STC12C5A60S2单片机的PCA\/PWM应用
工作在pwm模式下cl一定是从0加到255溢出的 不会装载任何值 ccap0l是会自动跟cl比较 大于输出0小于输出1 cl完成一个255计数之后ccap0h的值重新装入ccap0l cl还是从0开始计数 epcnl的作用是 固定pwm输出 当 epc0l=1时 pwm固定输出低 epc0l=0时 pwm固定输出高 ...

sTc8 pwm调光程序怎么写?
下面这个程序是应用在stc上的pwm程序,测试成功#includesfr CCON =0xD8; \/\/PCA control registersfr CMOD =0xD9;sfr CL =0xe9;sfr CH =0xF9;sfr CCAP0L=0xea;sfr CCAP1L=0xeb;sfr CCAP0H=0xfa;sfr CCAP1H=0xfb;sfr CCAPM0=0xda;sfr CCAPM1=0xdb;sbit CR=0xde; \/\/位寻址...

相似回答