找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1075|回复: 0
收起左侧

单片机跑马灯实现

[复制链接]
ID:363977 发表于 2018-7-3 14:34 | 显示全部楼层 |阅读模式
  1. //#include <REG52.h>
  2. #include <STC/STC89C5xRC.H>

  3. void Delay(unsigned int i);
  4. #define DP P1 //DataPort

  5. unsigned char code RTL[9]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};
  6. /**
  7. * 1111 1111  1111 1110 -- 0000 0000
  8. */
  9. unsigned char code LTR[9]={0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};
  10. /**
  11. * 1111 1111  0111 1111 -- 0000 0000
  12. */
  13. unsigned char code L[2][5]={{0xff,0x7f,0x3f,0x1f,0x0f},{0x0f,0x8f,0xcf,0xef,0xff}};
  14. /**
  15. * 1111 1111  0111 1111 -- 0000 1111
  16. * 0000 1111  1000 1111 -- 1111 1111
  17. */
  18. unsigned char code R[2][5]={{0xff,0xfe,0xfc,0xf8,0xf0},{0xf0,0xf1,0xf3,0xf7,0xff}};
  19. /**
  20. * 1111 1111  1111 1110 -- 1111 0000
  21. * 1111 0000  1111 0001 -- 1111 1111
  22. */

  23. void main(){
  24.         int i,j;
  25.         while(1){
  26.                 for(i=0;i<=8;i++){
  27.                         DP=LTR[i];
  28.                         Delay(100);
  29.                 }
  30.                 //Delay(1000);
  31.                 for(i=8;i>=0;i--){
  32.                         DP=RTL[i];
  33.                         Delay(100);
  34.                 }
  35.                 //Delay(200);
  36.                
  37.                 for(i=0;i<=8;i++){
  38.                         DP=RTL[i];
  39.                         Delay(100);
  40.                 }
  41.                 //Delay(1000);
  42.                 for(i=8;i>=0;i--){
  43.                         DP=LTR[i];
  44.                         Delay(100);
  45.                 }
  46.                 //Delay(200);
  47.                
  48.                 for(j=0;j<2;j++){
  49.                         for(i=0;i<5;i++){
  50.                                 DP=L[j][i]&R[j][i];
  51.                                 Delay(100);
  52.                         }
  53.                         //Delay(200);
  54.                 }
  55.                 for(j=1;j>=0;j--){
  56.                         for(i=4;i>=0;i--){
  57.                                 DP=L[j][i]&R[j][i];
  58.                                 Delay(100);
  59.                         }
  60.                         //Delay(200);
  61.                 }
  62.                
  63.                 DP=0x00;
  64.                 Delay(200);
  65.                 DP=0xff;
  66.                 Delay(100);
  67.                 DP=0x00;
  68.                 Delay(200);
  69.                 DP=0xff;
  70.                 Delay(100);
  71.                
  72.         }
  73. }

  74. void Delay(unsigned int i){
  75.         unsigned int j;
  76.         for(;i>0;i--)
  77.                 for(j=0;j<125;j++) ;
  78. }
复制代码


回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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