单片机教程网

电脑版
提示:原网页已由神马搜索转码, 内容由www.51hei.com提供.
查看:2345|回复:4
打印上一主题下一主题

51单片机贴片心形灯原理图PCB程序 亚克力外壳.dwg资料

[复制链接]
跳转到指定楼层
楼主
ID:912476发表于 2022-5-14 20:53|只看该作者|只看大图回帖奖励
Altium Designer画的51单片机贴片心形灯原理图和PCB图如下:(51hei附件中可下载工程文件)


单色心形灯CAD亚克力外壳设计图


单片机源程序如下:
  1. /*******************************************************************/
  2. /* 作品:单色心形流水灯

  3. /* 主控采用STC89c52RC单片机 晶振12M                                          
  4. /*******************************************************************/
  5.                                         
  6. #include<reg52.h>
  7. #define uchar unsigned char
  8. #define uint unsigned int

  9. uchar code table0[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//LED从低位往高位移
  10. uchar code table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//LED从高位往低位移
  11. uchar code table2[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};//LED从1个亮到8个都点亮(从低位往高位)
  12. uchar code table3[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};//LED从1个亮到8个都点亮(从高位往低位)
  13. uchar code table4[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};//LED从8个全亮到一个都不亮(从低位往高位)
  14. uchar code table5[]={0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};//LED从8个全亮到一个都不亮(从高位往低位)
  15. uchar code table6[]={0xfe,0xfc,0xfa,0xf6,0xee,0xde,0xbe,0x7e};//LED从低位往高位移(最低位始终为0)
  16. uchar code table7[]={0x7f,0x3f,0x5f,0x6f,0x77,0x7b,0x7d,0x7e};//LED从高位往低位移(最高位始终为0)
  17. uchar code Tab1[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,0xFF};//暗中左移  向下
  18. uchar code Tab2[]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF};//暗中右移  向上
  19. uchar code Tab3[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00};//亮中左移       向下
  20. uchar code Tab4[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00};//亮中右移  向上
  21. uchar code Tab11[]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0xff};//暗中左移  向下
  22. uchar code Tab22[]={0x7F,0x3F,0x1F,0x0F,0x07,0x03,0x01,0x00,0xff};
  23. uchar code Tab33[]={0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF};
  24. uchar code Tab44[]={0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};
  25. uchar code Tab55[]={0x08,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff};
  26. uchar code Tab5[]={0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xff};
  27. uchar code Tab6[]={0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xff};
  28. uchar code Tab7[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
  29. uchar code Tab8[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};


  30. uchar i,j,flag=200;       //定义循环变量
  31. uint tt=70,temp,cycle=350,xunhuan;           //定义时间指数
  32. void shansuo();
  33. void xl();

  34. void delay()  
  35. {
  36.          uchar m,n;
  37.        for(m=0;m<flag;m++)
  38.          for(n=0;n<250;n++);        
  39.         
  40. }
  41. void delay1(uint z)       //延时函数
  42. {
  43.        uint x,y;
  44.        for(x=z;x>0;x--)
  45.          for(y=110;y>0;y--);
  46. }
  47. void delay2(uint x)  //延时函数,要足够快,否则灯会闪烁,而不是慢慢变化。
  48. {  
  49.        uint i;
  50.        for(i=x;i>0;i--);
  51.       
  52. }
  53. void liushuideng1()
  54. {
  55.        for(xunhuan=0;xunhuan<2;xunhuan++)
  56.        {
  57.              for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
  58.              {
  59.                    P0=P1=P2=P3=0x00;
  60.                  delay2(temp);       //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
  61.                  P0=P1=P2=P3=0xff;
  62.                  delay2(cycle-temp);       //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
  63.              }
  64.       
  65.              for(temp=cycle;temp>0;temp--)//由亮到暗
  66.              {
  67.                    P0=P1=P2=P3=0x00;
  68.                  delay2(temp);  //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
  69.                    P0=P1=P2=P3=0xff;
  70.                  delay2(cycle-temp);       //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
  71.              }
  72.        }

  73. }      
  74. void liushuideng2()
  75. {      
  76.        P0=P1=P2=P3=0x00;
  77.        delay1(600);
  78.        for(xunhuan=0;xunhuan<2;xunhuan++)
  79.        {
  80.              for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
  81.              {
  82.                    P0=P1=P2=P3=0x55;
  83.                  delay2(temp);       //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
  84.                  P0=P1=P2=P3=0xaa;
  85.                  delay2(cycle-temp);       //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
  86.              }
  87.                    delay1(600);
  88.              for(temp=cycle;temp>0;temp--)//由亮到暗
  89.              {
  90.                P0=P1=P2=P3=0xaa;
  91.                  delay2(temp);  //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
  92.            P0=P1=P2=P3=0x55;
  93.                  delay2(cycle-temp);       //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
  94.              }
  95.             
  96.                    delay1(600);
  97.        }
  98.           
  99. }

  100. void liushuideng3()
  101. {      
  102.        delay1(1000);
  103.        for(xunhuan=0;xunhuan<2;xunhuan++)
  104.        {
  105.              for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
  106.              {
  107.                    P0=P1=P2=P3=0x0f;
  108.                  delay2(temp);       //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
  109.                  P0=P1=P2=P3=0xf0;
  110.                  delay2(cycle-temp);       //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
  111.              }
  112.              delay1(600);  
  113.              for(temp=cycle;temp>0;temp--)//由亮到暗
  114.              {
  115.                P0=P1=P2=P3=0xf0;
  116.                  delay2(temp);  //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
  117.            P0=P1=P2=P3=0x0f;
  118.                  delay2(cycle-temp);       //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
  119.              }
  120.              delay1(600);
  121.         
  122.        }
  123.           
  124. }
  125. void liushuideng4()
  126. {
  127.        for(xunhuan=0;xunhuan<1;xunhuan++)
  128.        {
  129.              for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
  130.              {
  131.                    P0=P2=0x00;
  132.                  delay2(temp);       //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
  133.                P0=P2=0xff;
  134.                  delay2(cycle-temp);       //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
  135.              }
  136.       
  137.              for(temp=cycle;temp>0;temp--)//由亮到暗
  138.              {
  139.                    P0=P2=0x00;
  140.                  delay2(temp);  //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
  141.                    P0=P2=0xff;
  142.                  delay2(cycle-temp);       //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
  143.              }

  144.              for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
  145.              {
  146.                    P1=P3=0x00;
  147.                  delay2(temp);       //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
  148.                    P1=P3=0xff;
  149.                  delay2(cycle-temp);       //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
  150.              }
  151.       
  152.              for(temp=cycle;temp>0;temp--)//由亮到暗
  153.              {
  154.                    P1=P3=0x00;
  155.                  delay2(temp);  //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
  156.                    P1=P3=0xff;
  157.                  delay2(cycle-temp);       //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
  158.              }
  159.        }

  160. }
  161. void liushuideng5()
  162. {


  163.        for(xunhuan=0;xunhuan<1;xunhuan++)
  164.        {
  165.              for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
  166.              {
  167.                    P1=P0=0x00;
  168.                  delay2(temp);       //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
  169.                    P1=P0=0xff;
  170.                  delay2(cycle-temp);       //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
  171.              }
  172.       
  173.              for(temp=cycle;temp>0;temp--)//由亮到暗
  174.              {
  175.                    P1=P0=0x00;
  176.                  delay2(temp);  //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
  177.                    P1=P0=0xff;
  178.                  delay2(cycle-temp);       //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
  179.              }

  180.              for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
  181.              {
  182.                    P3=P2=0x00;
  183.                  delay2(temp);       //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
  184.                P3=P2=0xff;
  185.                  delay2(cycle-temp);       //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
  186.              }
  187.       
  188.              for(temp=cycle;temp>0;temp--)//由亮到暗
  189.              {
  190.                    P3=P2=0x00;
  191.                  delay2(temp);  //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
  192.                    P3=P2=0xff;
  193.                  delay2(cycle-temp);       //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
  194.              }
  195.        }


  196. }

  197. void liushuideng6()
  198. {
  199.        for(xunhuan=0;xunhuan<1;xunhuan++)
  200.        {
  201.              for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
  202.              {
  203.                    P0=P3=0x00;
  204.                  delay2(temp);       //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
  205.                P0=P3=0xff;
  206.                  delay2(cycle-temp);       //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
  207.              }
  208.       
  209.              for(temp=cycle;temp>0;temp--)//由亮到暗
  210.              {
  211.                    P0=P3=0x00;
  212.                  delay2(temp);  //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
  213.                    P0=P3=0xff;
  214.                  delay2(cycle-temp);       //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
  215.              }

  216.              for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
  217.              {
  218.                    P1=P2=0x00;
  219.                  delay2(temp);       //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
  220.                P1=P2=0xff;
  221.                  delay2(cycle-temp);       //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
  222.              }
  223.       
  224.              for(temp=cycle;temp>0;temp--)//由亮到暗
  225.              {
  226.                    P1=P2=0x00;
  227.                  delay2(temp);  //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
  228.                    P1=P2=0xff;
  229.                  delay2(cycle-temp);       //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
  230.              }
  231.        }

  232. }

  233. void disp0()                 //状态0 所有LED闪烁3次
  234. {
  235.        for(i=0;i<3;i++)
  236.        {
  237.            P0=0x00; P2=0x00; P3=0x00; P1=0x00;
  238.            delay1(300);
  239. ……………………

  240. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码


所有资料51hei附件下载:
单色心形流水灯工程项目.zip(949.92 KB, 下载次数: 57)

评分

黑币 +50
收起理由
+ 50
共享资料的黑币奖励!

查看全部评分

沙发
ID:78271发表于 2022-5-15 22:02|只看该作者
设计的挺巧妙,估计做闪动表格的费不少时间。挺佩服的。
板凳
ID:230742发表于 2022-5-16 19:54|只看该作者
做的挺好!继续加油。
下次做个2812的。绝对高大上。
地板
ID:484897发表于 2024-4-12 09:37|只看该作者
很棒,资料很齐全
5#
ID:876947发表于 2024-5-10 12:02|只看该作者
大侠可以将这个程序移植到STC32上吗?也赋值到所有I/Ok?

手机版|小黑屋|51黑电子论坛|51黑电子论坛6群QQ管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网