自己规划的51单片机操控LED七彩突变灯
MCU:89C51,89S51,89C2051等
晶振:12MHz
电路驱动(LED衔接):
P1.0衔接蓝色LED
P1.1衔接赤色LED
P1.2衔接绿色LED (有必要运用纯绿色高亮LED,不行运用一般草绿管)
全为低电平驱动(低电平点亮),能够加三极管驱动,红、蓝、绿LED也能够交流方位
操控方法:PWM
频率:约300-700Hz(我没有核算或测量过,仅仅实验显现作用足够好)
调理级数:共600级,适当滑润
编译后的HEX文件:
687241197859316.rar
HEX代码:
:0D009300E4FEEEC39F50060000000E80F555
:0100A000223D
:06005F00A9078D828C83CD
:10006500E4FDE96008C292FF120093D292E5824551
:10007500836009C291AF82120093D291EB4A600965
:0D008500C290AF03120093D2900DBD0AD5BA
:01009200224B
:100003007508C8E4F509F50AE5086008E50A70040F
:1000130015080509E5096008E50870041509050ACE
:10002300E50A6008E5097004150A0508E5082509CD
:10003300FFE433FE7C00EF250AFFEC3EFEEF64C8CD
:100043004E60087508C8E4F509F50AE509FD7C006A
:0C005300E50AFB7A00AF0812005F80ACE9
:030000000200A15A
:0C00A100787FE4F6D8FD75810A020003A8
:00000001FF
C言语源程序:
/*******************************
程序称号:七彩LED突变程序
编写者:ZH YU
MCU:51/2051
晶振:12MHz
*********************************/
#include
#include
sbit gl=P1^2; //绿色
sbit rl=P1^1; //红
sbit bl=P1^0; //兰
timer(unsigned char t)
{unsigned char b;
for(b=0;b {_nop_(); _nop_(); _nop_();} } ledout(unsigned char g,r,b) {unsigned char a; for(a=0;a<10;a++) {if(g!=0) {gl=0;timer(g);gl=1;} if(r!=0) {rl=0;timer(r);rl=1;} if(b!=0) {bl=0;timer(b);bl=1;} } } main() { unsigned char g,r,b; g=200;r=0;b=0; while(1) {if(g!=0&&b==0) {g–;r++;} if(r!=0&&g==0) {r–;b++;} if(b!=0&&r==0) {b–;g++;} if(g+r+b!=200) {g=200;r=0;b=0;} ledout(g,r,b); } } 入无法下载HEX,我们能够用KEIL自己编译,或许运用记事本保存HEX代码(重命名为.HEX文件)都能够 再把.hex文件写入单片机,接好电路即可作业