標題: 51單片機+8*8點陣做的粗糙“流星雨”程序與Proteus仿真圖 [打印本頁]

作者: 最好看的小胖子    時間: 2021-12-16 19:43
標題: 51單片機+8*8點陣做的粗糙“流星雨”程序與Proteus仿真圖
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)

粗糙的流星雨代碼,每隔0.3下落一條

單片機源程序如下:
  1. #include<reg52.h>
  2. #include<stdlib.h>
  3. #include<intrins.h>
  4. #define uchar unsigned char
  5. #define uint unsigned int
  6. #define DATA P0

  7. uchar Col_w[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
  8. uchar RowLed[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
  9. uchar DelayTab[]={25,21,16,12,8,5,2,1};
  10. sbit SH595 =P1^2;
  11. sbit ST595 =P1^1;
  12. sbit DA595 =P1^0;

  13. void delayms(uint x)
  14. {
  15.   uint j;
  16.   for(;x>0;x--)
  17.     for(j=0;j<113;j++);
  18. }

  19. void SIPO(uchar dat){
  20.         uchar i;
  21.         SH595 = 0;
  22.         for(i=0;i<8;i++){
  23.                 if(dat&0x80)        DA595 = 1;
  24.                 else                DA595 = 0;
  25.                 dat = dat<<1;
  26.                 SH595=0;_nop_();_nop_();SH595=1;
  27.         }
  28.         ST595=0;_nop_();_nop_();ST595=1;
  29. }

  30. void Shower(uchar Col_wVal){
  31.         uchar i;
  32.         for(i=0;i<8;i++){
  33.                 SIPO(RowLed);
  34.                 P0 = Col_wVal;
  35.                 delayms(DelayTab);
  36.         }
  37.         SIPO(0xff);
  38.         delayms(300);
  39. }

  40. void main(){
  41.         uchar uRandNum;
  42.         while(1){
  43.                 uRandNum=rand()%8;
  44.                 Shower(Col_w[uRandNum]);
  45.         }
  46. }
復(fù)制代碼

Keil代碼與Proteus仿真下載:
仿真代碼.7z (37.21 KB, 下載次數(shù): 37)

作者: qzyhlf    時間: 2022-12-17 14:43
oooooooooooooooooooooooo




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1