• 回复
  • 收藏
  • 点赞
  • 分享
  • 发新帖

C51单片机控制输出LED七彩灯原程序

我学用C51单片机编制控制七彩灯(PWM信号)程序很久了,一直没能实现,请求各位求助.
全部回复(10)
正序查看
倒序查看
czhxp
LV.1
2
2006-03-31 09:53
学习用还是商用?
0
回复
2006-03-31 14:36
@czhxp
学习用还是商用?
学习用的.我已经编好久了,一直没编出.老兄有此原程序吗?给我一份吧!!!!拜托了!!!!在附件是我用汇编写的程序,是用红外解码来控制的(七彩灯开始运行与暂停运行),就是在按遥控时LED闪烁.http://bbs.dianyuan.com/topic/692201143787010.asm
0
回复
czhxp
LV.1
4
2006-03-31 16:25
好久不用汇编了,给个C51的例子参考一下吧
#define OUT0   P3_3
#define OUT1   P3_4
#define OUT2   P3_5
#define Lea 255/3

void main()
{
       bit fagR,fagG,fagB;
       uchar i,j;
       uchar x,y,z;
       uchar tR,tG,tB;
       i=0;
       j=0;
tR=rand();tR&=0x07;x=tR;
tG=rand();tG&=0x07;y=tG;
tB=rand();tB&=0x07;z=tB;
iR=i;
iG=iR+Lea;
iB=iG+Lea;
while(1)
{
if(0==iR){tR=rand();tR&=0x07;x=tR;}
if(0==iG){tG=rand();tG&=0x07;y=tG;}
if(0==iB){tB=rand();tB&=0x07;z=tB;}
do
{
if(iR>j) OUT0=1;
else       OUT0=0;

if(iG>j) OUT1=1;
else       OUT1=0;

if(iB>j) OUT2=1;
else       OUT2=0;
}while(++j);
if(x--==0){
if(iR==0)  fagR=0;
else if(iR==0xff)fagR=1;
if(!fagR) iR++;
else      iR--;
x=tR;
if(iR<64)
{
if(iR<16)
{
if(iR<4)x=tR+32;
else x=tR+16;
}
else x=tR+4;
}
}
if(y--==0){
if(iG==0)  fagG=0;
else if(iG==0xff)fagG=1;
if(!fagG) iG++;
else      iG--;
y=tG;
if(iG<64)
{
if(iG<16)
{
if(iG<4)y=tG+32;
else y=tG+16;
}
else y=tG+4;
}
}
if(z--==0){

if(iB==0)  fagB=0;
else if(iB==0xff)fagB=1;
if(!fagB) iB++;
else      iB--;
z=tB;
if(iB<64)
{
if(iB<16)
{
if(iB<4)z=tB+32;
else x=tB+16;
}
else x=tB+4;
}
}
}
}
0
回复
czhxp
LV.1
5
2006-03-31 16:27
@czhxp
好久不用汇编了,给个C51的例子参考一下吧#defineOUT0  P3_3#defineOUT1  P3_4#defineOUT2  P3_5#defineLea255/3voidmain(){      bitfagR,fagG,fagB;      uchari,j;      ucharx,y,z;      uchartR,tG,tB;      i=0;      j=0;tR=rand();tR&=0x07;x=tR;tG=rand();tG&=0x07;y=tG;tB=rand();tB&=0x07;z=tB;iR=i;iG=iR+Lea;iB=iG+Lea;while(1){if(0==iR){tR=rand();tR&=0x07;x=tR;}if(0==iG){tG=rand();tG&=0x07;y=tG;}if(0==iB){tB=rand();tB&=0x07;z=tB;}do{if(iR>j)OUT0=1;else      OUT0=0;if(iG>j)OUT1=1;else      OUT1=0;if(iB>j)OUT2=1;else      OUT2=0;}while(++j);if(x--==0){if(iR==0)  fagR=0;elseif(iR==0xff)fagR=1;if(!fagR)iR++;else      iR--;x=tR;if(iR
这里用的是个很笨的办法!!!
0
回复
2006-04-01 13:40
@czhxp
好久不用汇编了,给个C51的例子参考一下吧#defineOUT0  P3_3#defineOUT1  P3_4#defineOUT2  P3_5#defineLea255/3voidmain(){      bitfagR,fagG,fagB;      uchari,j;      ucharx,y,z;      uchartR,tG,tB;      i=0;      j=0;tR=rand();tR&=0x07;x=tR;tG=rand();tG&=0x07;y=tG;tB=rand();tB&=0x07;z=tB;iR=i;iG=iR+Lea;iB=iG+Lea;while(1){if(0==iR){tR=rand();tR&=0x07;x=tR;}if(0==iG){tG=rand();tG&=0x07;y=tG;}if(0==iB){tB=rand();tB&=0x07;z=tB;}do{if(iR>j)OUT0=1;else      OUT0=0;if(iG>j)OUT1=1;else      OUT1=0;if(iB>j)OUT2=1;else      OUT2=0;}while(++j);if(x--==0){if(iR==0)  fagR=0;elseif(iR==0xff)fagR=1;if(!fagR)iR++;else      iR--;x=tR;if(iR
多谢了!!!C语言也可以.请问此可变PWM程序你可以可以用定时方式实现吗??因为CPU还有其他任务去做.
0
回复
2006-04-03 09:20
@czhxp
这里用的是个很笨的办法!!!
tR=rand();
请问此rand()这函数是什么函数?,请贴上完整的程序好吗???1144029364.c500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/40/1144029623.gif');}" onmousewheel="return imgzoom(this);">
0
回复
2006-04-05 10:21
@czhxp
好久不用汇编了,给个C51的例子参考一下吧#defineOUT0  P3_3#defineOUT1  P3_4#defineOUT2  P3_5#defineLea255/3voidmain(){      bitfagR,fagG,fagB;      uchari,j;      ucharx,y,z;      uchartR,tG,tB;      i=0;      j=0;tR=rand();tR&=0x07;x=tR;tG=rand();tG&=0x07;y=tG;tB=rand();tB&=0x07;z=tB;iR=i;iG=iR+Lea;iB=iG+Lea;while(1){if(0==iR){tR=rand();tR&=0x07;x=tR;}if(0==iG){tG=rand();tG&=0x07;y=tG;}if(0==iB){tB=rand();tB&=0x07;z=tB;}do{if(iR>j)OUT0=1;else      OUT0=0;if(iG>j)OUT1=1;else      OUT1=0;if(iB>j)OUT2=1;else      OUT2=0;}while(++j);if(x--==0){if(iR==0)  fagR=0;elseif(iR==0xff)fagR=1;if(!fagR)iR++;else      iR--;x=tR;if(iR
请贴上完整的程序好吗???
0
回复
2006-04-08 13:22
@czhxp
这里用的是个很笨的办法!!!
老兄,帮帮忙啊!!干吗只帮一半??帮忙帮到底吗???、
0
回复
大小人
LV.1
10
2007-01-18 11:02
@zby13798132707
请贴上完整的程序好吗???
劳驾我急需LEDC51做闹钟的程序要求可显示年月日星期小时分钟秒还要可调三个闹钟
0
回复
大小人
LV.1
11
2007-01-18 11:05
@zby13798132707
老兄,帮帮忙啊!!干吗只帮一半??帮忙帮到底吗???、
CZHXP兄帮帮忙
0
回复