📄 pwm_test1.c
字号:
#include <stdio.h>
#include <reg51.h>
#include <math.h>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
/*--------------------------parameter setting-----------------------*/
#define XtalFreq (11.059200)//Crystal Frequence
#define FALSE 0
#define TRUE 1
/*--------------------------sfr setting-----------------------*/
sfr CCAPM0=0xDA;//PCA module 0 mode
sfr PCACL=0xE9;//PCA timer Low BYTE
sfr CCAP0H=0xFA;//module 0 get High BYTE
sfr CCAP0L=0xEA;//module 0 get Low BYTE
sfr CMOD=0xD9;//PCA module timer mode
sfr CCON=0xD8;//PCA module timer control
sbit CR=0xDE;//The PCA Start Count
sbit CEX0=0x93;//PWM output CEX0 output P1.3
/*-------------------------------main-------------------------------*/
void main()
{
int i;
TMOD=0x22;
/*-----------------------serrial show----------------------*/
SCON=0x50;
TI=1;//the same to SCON=0x52;
//TMOD=0x20;//T1:8bit; T0:16bit
PCON|=0x80;
TL1=0;
TH1=0xe8;//using the 1200bps//(unsigned int)(256-((XtalFreq/BaudRate)/192));
//TR0=1;//start T0
TR1=1;//start T1
printf("/nThe Test of the PWM Show:/n");
printf("The PWM OUTPUT is :/n");
/*-----------------------PWM----------------------*/
TL0=0xf4;
TH0=0xf4;
CCAP0L=0x7f;
CCAP0H=0x7f;//using for the control of the PWM pulse
//PCACL=0x7F;
CMOD=0x84;//using the T0 overflow for the Count Pulse,none Interupt,none WDOG/remain count
CCAPM0=0x42;//model 0 work state
TR0=1;
CR=1;//start the PCA Counter
//do
//{
// if(CEX0==1)
// printf("1 ");
// else
// printf("0 ");
//}
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -