#include

sbit PWMOUT = P0^0;

sbit ADDR0 = P1^0;

sbit ADDR1 = P1^1;

sbit ADDR2 = P1^2;

sbit ADDR3 = P1^3;

sbit ENLED = P1^4;

unsigned char HighRH = 0; //高电平重载值的高字节

unsigned char HighRL = 0; //高电平重载值的低字节

unsigned char LowRH = 0; //低电平重载值的高字节

unsigned char LowRL = 0; //低电平重载值的低字节

void ConfigPWM(unsigned int fr, unsigned char dc);

void ClosePWM;

void main{

unsigned int i;

EA = 1; //开总中断

ENLED = 0; //使能独立 LED

ADDR3 = 1;

ADDR2 = 1;

ADDR1 = 1;

ADDR0 = 0;

while (1){

ConfigPWM(100, 10); //频率 100Hz,占空比 10%

for (i=0; i40000; i++);

ClosePWM;

ConfigPWM(100, 40); //频率 100Hz,占空比 40%

for (i=0; i40000; i++);

ClosePWM;

ConfigPWM(100, 90); //频率 100Hz,占空比 90%

for (i=0; i40000; i++);

ClosePWM; //关闭 PWM,相当于占空比 100%

for (i=0; i40000; i++);

}

}

/* 配置并启动 PWM,fr-频率,dc-占空比 */

void ConfigPWM(unsigned int fr, unsigned char dc){

unsigned int high, low;

unsigned long tmp;

tmp = (11059200/12) / fr; //计算一个周期所需的计数值

high = (tmp*dc) / 100; //计算高电平所需的计数值

low = tmp - high; //计算低电平所需的计数值

high = 65536 - high + 12; //计算高电平的重载值并补偿中断延时

low = 65536 - low + 12;//计算低电平的重载值并补偿中断延时

HighRH = (unsigned char)(high》》8); //高电平重载值拆分为高低字节

HighRL = (unsigned char)high;

LowRH = (unsigned char)(low》》8); //低电平重载值拆分为高低字节

LowRL = (unsigned char)low;

TMOD &= 0xF0; //清零 T0 的控制位

TMOD |= 0x01; //配置 T0 为模式 1

  • UC3846控制芯片工作原理控制图 逆变焊机原理与用途
  • 数字万用表电阻档测试二极管正反向没有阻值(使用万用表测量二极管的正向电阻,为什么各档)
  • 学单片机需要学数电模电吗(学单片机要先学数电模电吗)
  • 电工怎么选择适合自己用的万用表(电工初学者买什么样的万用表好)
  • 单片机需要同时运行多个任务怎么办(单片机怎么同时执行多个任务)
  • 电机保护的方案取决于负载的机械特性
  • 绝缘电阻表正负搭接不复零位是怎么回事
  • 短路怎么用万用表查