找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3966|回復: 0
收起左側

單片機LED流星雨源程序分享

[復制鏈接]
ID:102668 發(fā)表于 2016-1-16 05:28 | 顯示全部樓層 |閱讀模式
電路很簡單,從程序中可以看出來,我就不畫了.
  1. #include<reg52.h>   
  2. #define uchar unsigned char
  3. #define led P1     
  4. bit flag=0;      
  5. uchar code lshift[3]={0x07,0x03,0x01};
  6. uchar code shift[7]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
  7. //imitate PWM data
  8. uchar code sta0[100]={  0x0f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,
  9.                         0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
  10.       0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
  11.       0xcf,0xcf,0xcf,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
  12.       0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
  13.       0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
  14.       0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
  15.       0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
  16.       0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
  17.       0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef      
  18.         };
  19. //functions statement
  20. void delay(uchar ms);
  21. uchar exchg(uchar dat);
  22. //main function
  23. void main()   
  24. {
  25.   uchar i,j,k,x,sdata;
  26.   while(1)
  27.   {
  28.   for(k=1;k<8;k++)
  29.     for(i=0;i<22;i++)
  30.    for(j=0;j<100;j++)
  31.      {
  32.       sdata=(sta0[j]>>k)|shift[k-1];
  33.       if(flag==1)  led=exchg(sdata);
  34.    else led=sdata;   
  35.   }
  36.   for(x=1;x<4;x++)
  37.     for(i=0;i<22;i++)
  38.    for(j=0;j<100;j++)
  39.      {
  40.       sdata=( sta0[j]<<(4-x) )|lshift[x-1];
  41.       if(flag==1)  led=exchg(sdata);
  42.    else led=sdata;
  43.   }
  44.   

  45. }
  46. }
  47. void delay(uchar ms)
  48. {
  49.    uchar n;
  50.   while(ms--)
  51.   {
  52.     for(n=125;n>0;n--);
  53.   }
  54. }
  55. uchar exchg(uchar dat) //對字節(jié)的高位和低位進行互換!
  56. {
  57.    uchar temp;
  58.    temp=
  59.    ((dat&0x01)<<7)|
  60.    ((dat&0x02)<<5)|
  61.    ((dat&0x04)<<3)|
  62.    ((dat&0x08)<<1)|
  63.    ((dat&0x10)>>1)|
  64.    ((dat&0x20)>>3)|
  65.    ((dat&0x40)>>5)|
  66.    ((dat&0x80)>>7);
  67. return temp;
  68. }
復制代碼


回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表