找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

关于pwm实现led渐变求助!!!!

[复制链接]
admin 发表于 2012-9-2 11:05:32 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
一下是我写的程序,调试通过,但是实现不了!!!
main.c:
#include<reg52.h>
#include"diy.h"
#include"timer.h"
void main()
{
timeinit();
while(1)
{


}

}


timer.c:

#include<reg52.h>
#include"diy.h"
#define LED_PWM_MAX 166
#define LED_PWM_MIN 0
#define LED P1
#define LED_ON LED=0X00
#define LED_OFF LED=0XFF
static uint8 Time_Counter=0;
static uint8 LED_Direction=0;
static uint8 LED_PWM_Counter=0;
void timeinit()
{
TMOD=0X01;
TH0=(65535-200)/256;
TL0=(65535-200)%256;
EA=1;
ET0=1;
TR0=1;
}
void time0() interrupt 1
{
static uint8 PWM_Counter=0;
TH0=(65535-200)/255;
TL0=(65535-200)%255;
if((LED_Direction==0)&&(++Time_Counter>=50))
{
Time_Counter=0;

if(LED_PWM_Counter>LED_PWM_MAX)
{
LED_PWM_Counter=LED_PWM_MAX;
LED_Direction=1;

}
if(LED_PWM_Counter<=LED_PWM_MAX)
{
LED_PWM_Counter++;

}

}
if((LED_Direction==1)&&(++Time_Counter>=50))
{
Time_Counter=0;
if(LED_PWM_Counter>=LED_PWM_MIN)
{
LED_PWM_Counter--;

}
if(LED_PWM_Counter<LED_PWM_MIN)
{
LED_PWM_Counter=LED_PWM_MIN;
LED_Direction=0;


}

}
PWM_Counter=LED_PWM_Counter;
if(PWM_Counter>0)
{
LED_ON;
PWM_Counter--;

}
else
{
LED_OFF;
}
}

diy.h:

#ifndef _DIY_H_
#define _DIY_H_
typedef unsigned char uint8;
typedef unsigned int uint16;
#endif

timer.h

#ifndef _TIMER_H_
#define _TIMER_H_
extern void timeinit();
#endif

还请各位指教,不胜感激!!!
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 20:23 , Processed in 0.052704 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表