STC12C5616AD有PCA/PWM模块
可以用定时器的1us溢出来作时钟源
那就不用频繁进出中断
- /*------------------------------------------------------------------*/
- /* --- STC MCU Limited ---------------------------------------------*/
- /* --- STC12C56xx Series MCU PCA module output PWM wave Demo -------*/
- /* --- Mobile: (86)13922805190 -------------------------------------*/
- /* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/
- /* --- Tel: 86-0513-55012928,55012929,55012966----------------------*/
- /* --- Web: www.STCMCU.com -----------------------------------------*/
- /* --- Web: www.GXWMCU.com -----------------------------------------*/
- /* If you want to use the program or the program referenced in the */
- /* article, please specify in which data and procedures from STC */
- /*------------------------------------------------------------------*/
- #include <STC12C5630AD.H>
-
- #include "intrins.h"
-
- #define FOSC 11059200L
-
- typedef unsigned char BYTE;
- typedef unsigned int WORD;
-
- void Timer0_Init(void) //1微秒@12.000MHz
- {
- AUXR |= 0x80; //定时器时钟1T模式
- TMOD &= 0xF0; //设置定时器模式
- TMOD |= 0x02; //设置定时器模式
- TL0 = 0xF4; //设置定时初始值
- TH0 = 0xF4; //设置定时重载值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- }
-
- void main()
- {
- Timer0_Init();
- 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; //Set PCA timer clock source as Timer0 overflow
- //Disable PCA timer overflow interrupt
- CCAP0H = CCAP0L = 0x80; //PWM0 port output 50% duty cycle square wave
- CCAPM0 = 0x42; //PCA module-0 work in 8-bit PWM mode and no PCA interrupt
-
- CCAP1H = CCAP1L = 0xff; //PWM1 port output 0% duty cycle square wave
- PCA_PWM1 = 0x03;
- CCAPM1 = 0x42; //PCA module-1 work in 8-bit PWM mode and no PCA interrupt
-
- CR = 1; //PCA timer start run
-
- while (1);
- }
-
复制代码
|