m21_pwm.txt

来自「CoreRiver MCU C语言程序集! 包括:ADC/POWER/PWM/」· 文本 代码 · 共 67 行

TXT
67
字号
// File : m21_pwm.c 

#include <GC89C520_TQ32I.H>

#define PWM_DIVIDE_OSC     0
#define PWM_DIVIDE_OSC_2   1
#define PWM_DIVIDE_OSC_4   2
#define PWM_DIVIDE_OSC_8   3
#define PWM_DIVIDE_OSC_16  4
#define PWM_DIVIDE_OSC_32  5
#define PWM_DIVIDE_OSC_64  6
#define PWM_DIVIDE_OSC_128 7

void m21_pwm_clock(unsigned char divide)
{
	PWMCON &= 0x8F;			
	PWMCON += (divide << 4);
}

void init_pwm() 
{
	//
	// PWM PORT to P0.6
	//
	
	PWMCON |= 0x80;
	ALTSEL &= 0xEF;

	//
	// PWM PORT to P0.0
	//
	
	//PWMCON &= 0x7F;
	//ALTSEL |= 0x10;
	
	//
	//	Set Pwm Clock
	//
	
	m21_pwm_clock(PWM_DIVIDE_OSC);
	
	//
	// Clear Counter
	//
	
	PWMCON |= 0x02;

	//	
	// PWM Duty Setting 
	//
	PWMD = 0x80;
				

	//
	// PWM Start
	//
	PWMCON |= 0x01;
}

void main()
{
	init_pwm();
	
	while(1);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?