C51 Program for PWM

Publisher:自由思想Latest update time:2016-11-21 Source: eefocusKeywords:PWM  C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include  
#include  
#include  
#include "UPSD3200.H" 
#include "upsd_pwm.h" 
#define uint unsigned int 
#define uchar unsigned char 
PSD_REGS PSD8xx_reg _at_ csiop; 
#define KEYIO (~(PSD8xx_reg.DATAIN_A)) & 0x07 
sbit CP=P4^7; 
sbit U_D=P1^1; 
void init_system(); // 系统初始化 
uchar keyboard(); 
void uPSD_PWM4_Variable(unsigned char PWM_Period, unsigned char PWM_PulseWidth); 
uchar Adjust_station=NO; 
unsigned char data x,flag; 
unsigned char keyboard() //键盘输入 

unsigned char a=0xff,b=0x01,c=0xf8,d;//有按键的位置 
uint i; 
do{ 
a=KEYIO|c; 
}while(a==0xff); 
if (a == 0xfe){d = '1';} 
else if (a == 0xfd){d = '2';} 
else if (a == 0xfb){d = '3';} 
else {d = '0';} 
return(d); 

void uPSD_PWM4_Init(void) 
unsigned int PWM_prescaler; 
P4SFS |= 0x80; 
PWM_prescaler = (unsigned int)((FREQ_OSC/2)/PWM4_INPUT_freq);//PWM4输入脉冲频率 K 

PSCL1L = PWM_prescaler & 0x00ff; 
PSCL1H = (PWM_prescaler >> 8); 

void StepMotor_GO(bit direction,uint speed) { 
unsigned char PWM_Period, PWM_PulseWidth; 
uint temp_uint; 
U_D = direction;//方向 
temp_uint = (PWM4_INPUT_freq*1000)/speed; 
PWM_Period = (unsigned char)temp_uint; 
PWM_PulseWidth = PWM_Period/2; 
uPSD_PWM4_Variable(PWM_Period,PWM_PulseWidth); 

void StepMotor_STOP(void) 

P4SFS &= 0x7f; 

void uPSD_PWM4_Variable(unsigned char PWM_Period, unsigned char PWM_PulseWidth) 

P4SFS |= 0x80; 
PWMVP = PWM_Period; 
PWMVPW = PWM_PulseWidth; 
PWMCON |= 0x20; 

void initkey(void){ 
PSD8xx_reg.DATAOUT_A=0xFF; 
PSD8xx_reg.CONTROL_A=0x00; 
PSD8xx_reg.DIRECTION_A=0x00; 

void init_system() // 系统初始化 

WDKEY=0x55; 
P4SFS = (unsigned char) (0x08 << 3); 
uPSD_PWM_Channel_8bit(3,243);
问题补充:(接着上面的序) 
void uPSD_PWM_Init_8bit(unsigned char PWM_channel_no, unsigned int PWM_freq8, unsigned char PWMCON_value) 

unsigned int PWM_prescaler; 
unsigned char output_polarity_mode; 
output_polarity_mode = PWMCON_value & 0x8F; 
PWMCON = (PWMCON & 0x70) | output_polarity_mode; 
P4SFS = (unsigned char) (0x08 << PWM_channel_no); 
PWM_prescaler = (unsigned int) ( (((unsigned int) FREQ_OSC) / 2) / PWM_freq8); 
PSCL0L = PWM_prescaler & 0x00ff; 
PSCL0H = (PWM_prescaler >> 8); 
PSCL1L = PWM_prescaler & 0x00ff; 
PSCL1H = (PWM_prescaler >> 8); 

void uPSD_PWM_Disable(void) 

PWMCON &= 0xDF; 

void main(void){ 
x=0; 
init_system(); 
flag=1; 
while(flag==1){ 
x=keyboard(); 
if(x=='1') {StepMotor_GO(0,100);} 
else if(x=='2') {StepMotor_GO(1,500);} 
else if(x=='3') { StepMotor_STOP();uPSD_PWM_Disable();} 
else if(x=='0') {uPSD_PWM_Disable();} 

}

Keywords:PWM  C51 Reference address:C51 Program for PWM

Previous article:Problems with using xdata when simulating C51 with proteus
Next article:C51 fixed ROM address initialization data method

Recommended ReadingLatest update time:2024-11-16 14:28

C51 interrupt function format
C51 Keil compiler interrupt function syntax definition: void function name() interrupt n using m The C51 compiler allows 0 to 31 interrupts. The interrupts and interrupt addresses provided by the C51 controller are as follows: Interrupt number Interrupt source Interrupt address 0 EXTERNAL 0 0003H 1 TIMER/COU
[Microcontroller]
Equipped with 2160Hz ultra-high frequency PWM dimming, the super value OPPO A1 Pro will be released on November 16
Equipped with 2160Hz ultra-high frequency PWM dimming, the super value OPPO A1 Pro will be released on November 16 OPPO has just announced more product details of the A1 Pro , which will be the first to adopt the industry-leading 2160Hz ultra-high frequency PWM dimming and have an ex
[Mobile phone portable]
Equipped with 2160Hz ultra-high frequency PWM dimming, the super value OPPO A1 Pro will be released on November 16
C51 interrupt handling process
C51 Interrupt Processing Procedure The C51 compiler supports the development of interrupt procedures directly in the C source program, thus reducing the tedious work of using assembly language and improving development efficiency. The complete syntax of the interrupt service function is as follows: void function
[Microcontroller]
Research on space voltage vector PWM technology based on DSP
  1 Introduction   In recent years, in high-performance fully digitally controlled electrical transmission systems, as the key to power electronic inverter technology, PWM technology has made rapid progress from initially pursuing the sinusoidal voltage waveform, to the sinusoidal current waveform, and then to the si
[Embedded]
C51---11 Buzzer
Buzzer Introduction Drive circuit ULN2003 Notes and frequencies Buzzer plays reminder tone
[Microcontroller]
C51---11 Buzzer
Research on a carrier phase-shifted multi-level PWM
1 Introduction With the rapid development of power electronics technology and power semiconductor technology, medium voltage high power transmission equipment not only improves resource utilization, but also reduces production costs. Although its circuit topology and control technolog
[Power Management]
Research on a carrier phase-shifted multi-level PWM
A multi-task mechanism based on 51 single chip microcomputer and its application
Introduction         Traditional single-chip microcomputer programs generally adopt a single-task mechanism. The single-task system has the advantages of being simple, intuitive and easy to control. However, since the program can only be executed in sequence, it lacks flexibility and can only use interrupt functions t
[Microcontroller]
A multi-task mechanism based on 51 single chip microcomputer and its application
How does the C51 tool perform coverage analysis?
The C51 tools are optimized for the limited memory resources of the 8051 microcontroller. To make the most efficient use of memory, automatic variables and function parameters are overwritten in memory according to a method that is easily explained. First, the connector generates a call tree based on the source pr
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号