m11_pwm.txt

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

TXT
59
字号
// File : m11_pwm.c 

#include <gc80c510_so20i.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 m11_pwm_clock(unsigned char divide)
{
	PWMCON &= 0x8F;			
	PWMCON += (divide << 4);
}

void init_pwm() 
{
	//
	// PWM PORT to P0.0
	//
	
	PWM0CON &= 0x7F;
	ALTSEL |= 0x10;
	
	//
	//	Set Pwm Clock
	//
	
	m11_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 + -
显示快捷键?