微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 想用IAP 15W4K58S4芯片做一个PWM输出,占空比为50.8% 频率为13.57KHZ..怎么弄?

想用IAP 15W4K58S4芯片做一个PWM输出,占空比为50.8% 频率为13.57KHZ..怎么弄?

时间:10-02 整理:3721RD 点击:
想用IAP 15W4K58S4芯片做一个PWM输出,占空比为50.8% 频率为13.57KHZ..怎么弄?
下面程序是官方的,有老多地方看不懂,请高手指点下。这个程序可以做到吗?
#include<reg51.h>
#define CYCLE 0X1000L
#define PWMC (*(unsigned int volatile xdata*)0xfff0)
#define PWMCH (*(unsigned char volatile xdata*)0xfff0)
#define PWMCl (*(unsigned char volatile xdata*)0xfff1)
#define PWMCKS (*(unsigned char volatile xdata*)0xfff2)
#define PWM2T1 (*(unsigned int volatile xdata*)0xff00)
#define PWM2T1H (*(unsigned char volatile xdata*)0xff00)
#define PWM2T1L (*(unsigned char volatile xdata*)0xff01)
#define PWM2T2 (*(unsigned int volatile xdata*)0xff02)
#define PWM2T2H (*(unsigned char volatile xdata*)0xff02)
#define PWM2T2L (*(unsigned char volatile xdata*)0xff03)
#define PWM2CR (*(unsigned char volatile xdata*)0xff04)
#define PWM3T1 (*(unsigned int volatile xdata*)0xff10)
#define PWM3T1H (*(unsigned char volatile xdata*)0xff10)
#define PWM3T1L (*(unsigned char volatile xdata*)0xff11)
#define PWM3T2 (*(unsigned int volatile xdata*)0xff12)
#define PWM3T2H (*(unsigned char volatile xdata*)0xff12)
#define PWM3T2L (*(unsigned char volatile xdata*)0xff13)
#define PWM3CR (*(unsigned char volatile xdata*)0xff14)
#define PWM4T1 (*(unsigned int volatile xdata*)0xff20)
#define PWM4T1H (*(unsigned char volatile xdata*)0xff20)
#define PWM4T1L (*(unsigned char volatile xdata*)0xff21)
#define PWM4T2 (*(unsigned int volatile xdata*)0xff22)
#define PWM4T2H (*(unsigned char volatile xdata*)0xff22)
#define PWM4T2L (*(unsigned char volatile xdata*)0xff23)
#define PWM4CR (*(unsigned char volatile xdata*)0xff24)
#define PWM5T1 (*(unsigned int volatile xdata*)0xff30)
#define PWM5T1H (*(unsigned char volatile xdata*)0xff30)
#define PWM5T1L (*(unsigned char volatile xdata*)0xff31)
#define PWM5T2 (*(unsigned int volatile xdata*)0xff32)
#define PWM5T2H (*(unsigned char volatile xdata*)0xff32)
#define PWM5T2L (*(unsigned char volatile xdata*)0xff33)
#define PWM5CR (*(unsigned char volatile xdata*)0xff34)
#define PWM6T1 (*(unsigned int volatile xdata*)0xff40)
#define PWM6T1H (*(unsigned char volatile xdata*)0xff40)
#define PWM6T1L (*(unsigned char volatile xdata*)0xff41)
#define PWM6T2 (*(unsigned int volatile xdata*)0xff42)
#define PWM6T2H (*(unsigned char volatile xdata*)0xff42)
#define PWM6T2L (*(unsigned char volatile xdata*)0xff43)
#define PWM6CR (*(unsigned char volatile xdata*)0xff44)
#define PWM7T1 (*(unsigned int volatile xdata*)0xff50)
#define PWM7T1H (*(unsigned char volatile xdata*)0xff50)
#define PWM7T1L (*(unsigned char volatile xdata*)0xff51)
#define PWM7T2 (*(unsigned int volatile xdata*)0xff52)
#define PWM7T2H (*(unsigned char volatile xdata*)0xff52)
#define PWM7T2L (*(unsigned char volatile xdata*)0xff53)
#define PWM7CR (*(unsigned char volatile xdata*)0xff54)
sfr P_SW2=0XBA;
sfr P0M1=0X93;
sfr P0M0=0X94;
sfr P1M1=0X91;
sfr P1M0=0X92;
sfr P2M1=0X95;
sfr P2M0=0X96;
sfr P3M1=0XB1;
sfr P3M0=0XB2;
sfr P4M1=0XB3;
sfr P4M0=0XB4;
sfr P5M1=0XC9;
sfr P5M0=0XCA;
sfr P6M1=0XCB;
sfr P6M0=0XCC;
sfr P7M1=0XE1;
sfr P7M0=0XE2;
sfr PWMCFG=0XF1;
sfr PWMCR=0XF5;
sfr PWMIF=0XF6;
sfr PWMFDCR=0XF7;
sbit PWM2=P3^7;
sbit PWM3=P2^1;
sbit PWM4=P2^2;
sbit PWM5=P2^3;
sbit PWM6=P0^7;
sbit PWM7=P0^6;
void PWM_config(void);
void PWM2_SetPwmWide(unsigned short Wide);
void PWM3_SetPwmWide(unsigned short Wide);
void PWM4_SetPwmWide(unsigned short Wide);
void PWM5_SetPwmWide(unsigned short Wide);
void PWM6_SetPwmWide(unsigned short Wide);
void PWM7_SetPwmWide(unsigned short Wide);
void main()
{
PWM_config();
PWM2_SetPwmWide(0);
PWM3_SetPwmWide(1);
PWM4_SetPwmWide(CYCLE);
PWM5_SetPwmWide(CYCLE-1);
PWM6_SetPwmWide(CYCLE/2);
PWM7_SetPwmWide(CYCLE/3);
while(1);
}
void PWM_config(void)
{
P0M0&=~0XC0;
P0M1&=~0XC0;
P0&=~0XC0;
P2M0&=~0X0E;
P2M1&=~0X0E;
P2&=~0X0E;
P3M0&=~0X80;
P3M1&=~0X80;
P3&=~0X80;
P_SW2|=0X80;
PWMCKS=0X00;
PWMC=CYCLE;

PWM2T1=1;
PWM2T2=0;
PWM2CR=0X00;
PWM3T1=1;
PWM3T2=0;
PWM3CR=0X00;
PWM4T1=1;
PWM4T2=0;
PWM4CR=0X00;
PWM5T1=1;
PWM5T2=0;
PWM5CR=0X00;
PWM6T1=1;
PWM6T2=0;
PWM6CR=0X08;
PWM7T1=1;
PWM7T2=0;
PWM7CR=0X08;
PWMCFG=0X00;
PWMCR=0X3F;
PWMCR|=0X80;
P_SW2&=~0X80;
}
void PWM2_SetPwmWide(unsigned short Wide)
{
if(Wide==0)
{
  PWMCR&=~0X01;
  PWM2=0;
}
else if(Wide==CYCLE)
{
  PWMCR&=~0X01;
  PWM2=1;
}
else
{
  P_SW2|=0X80;
  PWM2T1=Wide;
  P_SW2&=~0X80;
  PWMCR|=0X01;
}
}

高手帮帮忙!

我等着用,顶起

完全看不懂!正在学这款单片机

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top