找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 885|回复: 1
收起左侧

请教单片机PCA做16位定时器使用的问题

[复制链接]
ID:961122 发表于 2022-5-25 22:31 | 显示全部楼层 |阅读模式
我用STC15F2K60S2的单片机,想在按下P32时启动定时器,读取当前[CH CL]值,加定时长度再存入[CCAP0L CCAP0H],每个中断变接P11的状态。实际运行时是按下P32后P1输出的周期是73ms.想要的调定值是1ms.不知是什么原因,有高人帮忙看一下吗?
#define _MAIN_C

#include <reg51.h>
unsigned int value;

sbit test_button        = P3^2;
sbit pulse_out          = P1^1;
sbit covery_motor       = P1^2;

bit test_flag=0;

void active(void);

unsigned int current_value;

#define Basetime    (0x039A) 1ms// (11059200/12/1000)

void main(void){
    P1M1=0x00;
    P1M0=0x0C;

    test_button=1;
    pulse_out=1;
    CCON = 0x00;
    CMOD = 0x00;                                //PCA时钟为系统时钟/12
    CR = 1;                                     //启动PCA计时器
    EA = 1;


    while (1){
        if(test_button==0 && test_flag==0){
            test_flag=1;
            covery_motor= ~covery_motor;
                    active();
        }           
        if(test_button==1 && test_flag==1)
            test_flag=0;

    }   
}
void active(void){

    pulse_out=0;
    CCAPM0 = 0x49;                              //PCA模块0为16位定时器模式
    current_value=(CH<<8+CL)+Basetime;
    CCAP0L=current_value;
    CCAP0H=current_value>>8;
}

void PCA_Isr() interrupt 7
{
    pulse=~pulse;
    CCF0 = 0;
    current_value=(CH<<8+CL)+Basetime;
    CCAP0L=current_value;
    CCAP0H=current_value>>8;


}
回复

使用道具 举报

ID:961122 发表于 2022-5-25 23:05 | 显示全部楼层
已解决,CH<8要加括号,没有得删帖功能,只能在这回复
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表