社区导航

 
查看: 2482|回复: 0

[求助] 51单片机,流星灯程序修改

[复制链接]

48

TA的帖子

0

TA的资源

一粒金砂(初级)

Rank: 1

发表于 2011-2-12 14:15:28 | 显示全部楼层 |阅读模式

这是网上找的51单片机流星灯程序,软件模拟PWM,拖尾效果,是P0的IO口8路输出的,如果,我要改为16路输出,怎样改呢,求高手指点,谢谢~,原程序如下:

 


#include<reg52.h>     //head file
#define uchar unsigned char//for convenient
#define led P0      // led data port
bit flag=0;       //direction flag

uchar code lshift[3]={0x07,0x03,0x01};
uchar code shift[7]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
//imitate PWM data
uchar code sta0[100]={  0x0f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,
                        0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
      0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
      0xcf,0xcf,0xcf,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
      0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
      0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
      0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
      0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
      0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
      0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef       
        };
 //functions statement
void delay(uchar ms); 
uchar exchg(uchar dat);
//main function
void main()    
{
  uchar i,j,k,x,sdata; 
  while(1) 
  {

  for(k=1;k<8;k++)
    for(i=0;i<22;i++)
   for(j=0;j<100;j++)
     {
      sdata=(sta0[j]>>k)|shift[k-1];
      if(flag==1)  led=exchg(sdata); 
   else led=sdata;    
  }

  for(x=1;x<4;x++)
    for(i=0;i<22;i++)
   for(j=0;j<100;j++)
     {
      sdata=( sta0[j]<<(4-x) )|lshift[x-1];
      if(flag==1)  led=exchg(sdata); 
   else led=sdata;
  }
  
 
 } 

}
void delay(uchar ms)
{
   uchar n;
  while(ms--)
  {
    for(n=125;n>0;n--);
  }
}
uchar exchg(uchar dat) //对字节的高位和低位进行互换!
{
   uchar temp;
   temp=
   ((dat&0x01)<<7)|
   ((dat&0x02)<<5)|
   ((dat&0x04)<<3)|
   ((dat&0x08)<<1)|
   ((dat&0x10)>>1)|
   ((dat&0x20)>>3)|
   ((dat&0x40)>>5)|
   ((dat&0x80)>>7);
return temp;
}

此帖出自51单片机论坛

您需要登录后才可以回帖 登录 | 注册

本版积分规则

  • 论坛活动 E手掌握

    扫码关注
    EEWORLD 官方微信

  • EE福利  唾手可得

    扫码关注
    EE福利 唾手可得

小黑屋|手机版|Archiver|电子工程世界 ( 京ICP证 060456

GMT+8, 2017-8-24 10:56 , Processed in 0.193212 second(s), 15 queries , Redis On.

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