当前位置:首页 > 单片机 > 单片机
[导读]#include #include #include #include "UPSD3200.H"#include "upsd_pwm.h"#define uint unsigned int#define uchar unsigned charPSD_REGS PSD8xx_reg _at_ csiop;#define KEYIO (~(PSD8xx_reg.DATAIN_A)) & 0x07sbi

#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();}
}
}

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

在这篇文章中,小编将对pwm的相关内容和情况加以介绍以帮助大家增进对它的了解程度,和小编一起来阅读以下内容吧。

关键字: pwm 脉冲宽度调制

在下述的内容中,小编将会对PWM控制器的相关消息予以报道,如果PWM控制器是您想要了解的焦点之一,不妨和小编共同阅读这篇文章哦。

关键字: pwm 控制器 pwm控制器

在下述的内容中,小编将会对PWM的相关消息予以报道,如果PWM是您想要了解的焦点之一,不妨和小编共同阅读这篇文章哦。

关键字: pwm 变换器

在这篇文章中,小编将为大家带来PWM变换器的相关报道。如果你对本文即将要讲解的内容存在一定兴趣,不妨继续往下阅读哦。

关键字: pwm 变换器 pwm变换器

单片机内部有很多的特殊功能寄存器,每个寄存器在单片机内部都分配有唯一的地址,一般我们会根据寄存器功能的不同给寄存器赋予各自的名称,当我们需要在程序中操作这些特殊功能寄存器时,必须要在程序的最前面将这些名称加以声明,声明的...

关键字: C51 数据类型 扩充定义

数据元(Data Element),也称为数据元素,是用一组属性描述其定义、标识、表示和允许值的数据单元,在一定语境下,通常用于构建一个语义正确、独立且无歧义的特定概念语义的信息单元。数据元可以理解为数据的基本单元,将若...

关键字: C51 数据类型

pwm控制器将是下述内容的主要介绍对象,通过这篇文章,小编希望大家可以对pwm控制器的相关情况以及信息有所认识和了解,详细内容如下。

关键字: pwm 控制器 mppt

今天,小编将在这篇文章中为大家带来pwm控制器的有关报道,通过阅读这篇文章,大家可以对pwm控制器具备清晰的认识,主要内容如下。

关键字: pwm 控制器 mppt

▼点击下方名片,关注公众号▼欢迎关注【玩转单片机与嵌入式】公众号,回复关键字获取更多免费资料。回复【加群】,限时免费进入知识共享群;回复【3D封装库】,常用元器件的3D封装库;回复【电容】,获取电容、元器件选型相关的内容...

关键字: C51 MDK RealView

在Keil C51软件中51单片机的中断服务和外设驱动程序的开发

关键字: keil5 编译 C51
关闭
关闭