⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwm.c

📁 适合初学者学习的UPSD的点阵LCD汉字显示
💻 C
字号:
/*uPSD3200.c    

-7/8/02
  >> New release for uPSD3200 family.
*/
/*
These files have been compiled using a the Keil Software Inc uVision2 IDE,
PK51 Compiler/Linker/Debugger, version 7.00. 

NOTES:
1. 
Some of the routines provided may not have been thoroughly tested.  
Please check them in your system. If you find a bug, or a place 
where the code could be improved, PLEASE forward your comments by 
emailing to apps.psd@st.com. Any comments and feedback are 
appreciated. Please tell us what you like and or what you think 
can be improved.

2. 
The Software is provided "AS IS."

LIMITATION OF LIABILITY:    NEITHER WSI NOR ITS VENDORS OR AGENTS
SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

You are free to use/modify any of the provided code at your own risk
in your applications with the expressed limitation of liability above.
*/

/* 
Be sure to uncomment the associated #define statements inside the 
header file, uPSD3200.h, to use individual desired functions 
contained in this C file. Your compiler will ignore the functions
in this file unless you do so.
*/

/*#include "uPSD3200.h"*/   /* uncomment this include statement 
                                             to use the header files generated by 
                                             PSDsoft */
/* Function prototypes
*/

void uPSD_ADC_Init(unsigned char channel);
unsigned char uPSD_ADC_Read( unsigned char channel );
unsigned char uPSD_ADC_Prescaler( void );
void timer0_initialize (void);
unsigned timer0_count (void);
void timer0_delay (unsigned count);
void delay_10ms(void);
void delay_1sec(void);
void delay_2sec(void);
void delay_10sec(void);
void delay_0_5sec(void);
void delay_0_1sec(void);
void uPSD_PWM_Channel_8bit(unsigned char PWMCON_value, unsigned char PWM_channel_no, unsigned char Duty_Cyl);
void uPSD_PWM_Init_8bit(unsigned char PWM_channel_no, unsigned char Duty_Cyl);
void uPSD_PWM_Disable(void);

/*
Functions
*/

/*
Group: uPSD PWM Channels
Coverage: Initialize, Output, Disable
*/

/* 
Module:  uPSD_PWM_Init_8bit
Setup Prescaler value and I/O ports for the select channel of the 8-bit PWM.
*/

#ifdef _U_P_I_8

void uPSD_PWM_Init_8bit(unsigned char PWM_channel_no, unsigned char Duty_Cyl)
{
unsigned int PWM_prescaler;

switch (PWM_channel_no) 
	{
	case 0:
	        	{
		P4SFS |= 0x08;	/* output port P4[3] = PWM0 */
		PWM0 = Duty_Cyl;
		break;
		}
	case 1:
		{
		P4SFS |= 0x10;	/* output port P4[4] = PWM1 */ 
		PWM1 = Duty_Cyl;
		break;
		}
	case 2:
        		{
		P4SFS |= 0x20;	 /* output port P4[5] = PWM2 */
		PWM2 = Duty_Cyl;
		break;
		}
	case 3:
        		{
		P4SFS |= 0x40;	/* output port P4[6] = PWM3 */
		PWM3 = Duty_Cyl;
		break;
		}
	default:
		break;
	}
PWM_prescaler = (unsigned int ) (FREQ_OSC / (2 * PWM_freq8) - 1);
PSCL0L = PWM_prescaler;
PSCL0H = (PWM_prescaler >> 8);
}

#endif

/* 
Module:  uPSD_PWM_Channel_8bit
Output pulse train as specified in passed arguments
*/

#ifdef _U_P_C_8

void uPSD_PWM_Channel_8bit(unsigned char PWMCON_value, unsigned char PWM_channel_no, unsigned char Duty_Cyl)
{
unsigned char output_polarity_mode;

	uPSD_PWM_Init_8bit(PWM_channel_no, Duty_Cyl);	// Initialize
 	
	output_polarity_mode = PWMCON_value & 0x8F;	// bit[7],bit[3:0]} are used to define PWM output mode

	PWMCON |= output_polarity_mode;		// 0--open drain; 1-- push pull 

	PWMCON |= 0x20;				/ /PWME = 1, Enable PWM IP
	
}

#endif


/* 
Module:  uPSD_PWM_Disable
Disable PWM IP
*/

#ifdef _U_P_D

void uPSD_PWM_Disable(void)
{
	PWMCON &= 0xDF;		//PWME = 0, Disable PWM output
}

#endif
/*
End of Group uPSD PWM Channels
*/

⌨️ 快捷键说明

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