完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "reg51.h" #include "intrins.h" #define FOSC 11059200L /* define constants */ #define MODE1T #ifdef MODE1T #define T1MS (65536-FOSC/20000) //20ms timer calculation method in 1T mode #else #define T1MS (65536-FOSC/12/20000) //20ms timer calculation method in 12T mode #endif /* define SFR */ sfr AUXR = 0x8e; typedef unsigned char BYTE; typedef unsigned int WORD; /*Declare SFR associated with the PCA */ sfr CCON = 0xD8; //PCA control register ***it CCF0 = CCON^0; //PCA module-0 interrupt flag ***it CCF1 = CCON^1; //PCA module-1 interrupt flag ***it CR = CCON^6; //PCA timer run control bit ***it 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; void pwm_init(void) { 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|=0x04; //设置PWM时钟使用定时器0 AUXR = 0x80; //timer0 work in 1T mode TMOD = 0x01; //set timer0 as mode1 (16-bit) TL0 = T1MS; //initial timer0 low byte TH0 = T1MS >> 8; //initial timer0 high byte TR0 = 1; CCAPM0 = 0x42; CCAP0H = CCAP0L = 0x12;//占空比7% 约等于1.4ms CCAP1L=CCAP1H=0x80;//占空比调整至5%约等于1ms PCAPWM0=0x00; //stc12c5a60s2是8位PWM,控制占空比的第九位为0 CCAPM1 = 0x42; PCAPWM1 = 0x00; //PCA module-1 work in 8-bit PWM mode and no PCA interrupt CR = 1; } void main() { pwm_init(); //PCA timer start run } |
|
相关推荐
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
820 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第十一章 KEY实验
388 浏览 0 评论
783 浏览 0 评论
801 浏览 2 评论
飞凌嵌入式-ELFBOARD-ELF 2硬件知识分享-最小系统原理
466 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11933 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-13 00:36 , Processed in 0.684042 second(s), Total 71, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号