找回密码
 立即注册

QQ登录

只需一步,快速开始

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

LED点阵屏时钟源程序 stc11f32xe

[复制链接]
ID:127496 发表于 2016-6-21 01:05 | 显示全部楼层 |阅读模式
由于时间问题,暂时还没有上传图片。

  1. /********************************************************************

  2. 作者:TZR

  3. 版本:CLK188

  4. 简介:点阵屏很暗,只能在暗处看清。

  5. *********************************************************************/

  6. #include <at89x52.h>
  7. sbit a1=P0^0;
  8. sbit a2=P0^1;
  9. sbit a3=P0^2;
  10. sbit a4=P0^3;
  11. sbit a5=P0^4;
  12. sbit a6=P0^5;
  13. sbit a7=P0^6;
  14. sbit a8=P0^7;
  15. sbit LED=P2^0;
  16. sbit mode=P2^2;
  17. sbit chan=P2^5;
  18. P1M1=0x00;
  19. P1M0=0xff;
  20. bit rs;
  21. unsigned int tt;
  22. unsigned char syst;
  23. unsigned char sec;
  24. unsigned char min;
  25. unsigned char hour;
  26. unsigned char c;
  27. unsigned char k;
  28. unsigned char j;
  29. unsigned char zt;
  30. unsigned char temp;
  31. unsigned char temp2;
  32. unsigned char temp3;
  33. unsigned char ledplay[7]={0+52,0+52,62,0+52,0+52,63,63};
  34. unsigned char msg[4]={
  35. 64,19,25,17
  36. };
  37. unsigned char code word[][8]={
  38. {0x20,0x50,0x88,0x88,0xF8,0x88,0x88,0x00}, // -A-0
  39. {0xF0,0x88,0x88,0xF0,0x88,0x88,0xF0,0x00}, // -B-1
  40. {0x70,0x88,0x80,0x80,0x80,0x88,0x70,0x00}, // -C-2
  41. {0xF0,0x88,0x88,0x88,0x88,0x88,0xF0,0x00}, // -D-3
  42. {0xF8,0x80,0x80,0xF0,0x80,0x80,0xF8,0x00}, // -E-4
  43. {0xF8,0x80,0x80,0xF0,0x80,0x80,0x80,0x00}, // -F-5
  44. {0x70,0x88,0x80,0x80,0xB8,0x88,0x78,0x00}, // -G-6
  45. {0x88,0x88,0x88,0xF8,0x88,0x88,0x88,0x00}, // -H-7
  46. {0x70,0x20,0x20,0x20,0x20,0x20,0x70,0x00}, // -I-8
  47. {0x38,0x10,0x10,0x10,0x10,0x90,0x60,0x00}, // -J-9
  48. {0x88,0x90,0xA0,0xC0,0xA0,0x90,0x88,0x00}, // -K-10
  49. {0x80,0x80,0x80,0x80,0x80,0x80,0xF8,0x00}, // -L-11
  50. {0x88,0xD8,0xA8,0xA8,0x88,0x88,0x88,0x00}, // -M-12
  51. {0x88,0x88,0xC8,0xA8,0x98,0x88,0x88,0x00}, // -N-13
  52. {0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00}, // -O-14
  53. {0xF0,0x88,0x88,0xF0,0x80,0x80,0x80,0x00}, // -P-15
  54. {0x70,0x88,0x88,0x88,0xA8,0x90,0x68,0x00}, // -Q-16
  55. {0xF0,0x88,0x88,0xF0,0xA0,0x90,0x88,0x00}, // -R-17
  56. {0x70,0x88,0x80,0x70,0x08,0x88,0x70,0x00}, // -S-18
  57. {0xF8,0x20,0x20,0x20,0x20,0x20,0x20,0x00}, // -T-19
  58. {0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00}, // -U-20
  59. {0x88,0x88,0x88,0x88,0x88,0x50,0x20,0x00}, // -V-21
  60. {0x88,0x88,0x88,0xA8,0xA8,0xD8,0x88,0x00}, // -W-22
  61. {0x88,0x88,0x50,0x20,0x50,0x88,0x88,0x00}, // -X-23
  62. {0x88,0x88,0x50,0x20,0x20,0x20,0x20,0x00}, // -Y-24
  63. {0xF8,0x08,0x10,0x20,0x40,0x80,0xF8,0x00}, // -Z-25
  64. {0x00,0x00,0xE0,0x10,0x70,0x90,0x68,0x00}, // -a-26
  65. {0x80,0x80,0xB0,0xC8,0x88,0xC8,0xB0,0x00}, // -b-27
  66. {0x00,0x00,0x70,0x88,0x80,0x80,0x70,0x00}, // -c-28
  67. {0x08,0x08,0x68,0x98,0x88,0x98,0x68,0x00}, // -d-29
  68. {0x00,0x00,0x70,0x88,0xF0,0x80,0x70,0x00}, // -e-30
  69. {0x30,0x48,0x40,0xF0,0x40,0x40,0x40,0x00}, // -f-31
  70. {0x00,0x00,0x70,0x88,0x88,0x78,0x08,0xF0}, // -g-32
  71. {0x80,0x80,0xB0,0xC8,0x88,0x88,0x88,0x00}, // -h-33
  72. {0x20,0x00,0x00,0x20,0x20,0x20,0x20,0x00}, // -i-34
  73. {0x10,0x00,0x00,0x30,0x10,0x10,0x10,0x60}, // -j-35
  74. {0x80,0x80,0x90,0xA0,0xC0,0xA0,0x98,0x00}, // -k-36
  75. {0x60,0x20,0x20,0x20,0x20,0x20,0x70,0x00}, // -l-37
  76. {0x00,0x00,0x50,0xA8,0xA8,0xA8,0xA8,0x00}, // -m-38
  77. {0x00,0x00,0xB0,0x48,0x48,0x48,0x48,0x00}, // -n-39
  78. {0x00,0x00,0x70,0x88,0x88,0x88,0x70,0x00}, // -o-40
  79. {0x00,0x00,0xF0,0x88,0x88,0xF0,0x80,0x80}, // -p-41
  80. {0x00,0x00,0x78,0x88,0x88,0x78,0x08,0x08}, // -q-42
  81. {0x00,0x00,0xB0,0x48,0x40,0x40,0x40,0x00}, // -r-43
  82. {0x00,0x00,0x78,0x80,0x70,0x08,0xF0,0x00}, // -s-44
  83. {0x40,0x40,0xF8,0x40,0x40,0x48,0x30,0x00}, // -t-45
  84. {0x00,0x00,0x90,0x90,0x90,0x90,0x68,0x00}, // -u-46
  85. {0x00,0x00,0x88,0x88,0x88,0x50,0x20,0x00}, // -v-47
  86. {0x00,0x00,0xA8,0xA8,0xA8,0xA8,0x50,0x00}, // -w-48
  87. {0x00,0x00,0x88,0x50,0x20,0x50,0x88,0x00}, // -x-49
  88. {0x00,0x00,0x88,0x88,0x98,0x68,0x08,0xF0}, // -y-50
  89. {0x00,0x00,0xF8,0x10,0x20,0x40,0xF8,0x00}, // -z-51
  90. {0x38,0x44,0x4C,0x54,0x64,0x44,0x38,0x00}, // -0-52
  91. {0x10,0x30,0x10,0x10,0x10,0x10,0x38,0x00}, // -1-53
  92. {0x38,0x44,0x04,0x18,0x20,0x40,0x7C,0x00}, // -2-54
  93. {0x7C,0x04,0x08,0x18,0x04,0x44,0x38,0x00}, // -3-55
  94. {0x08,0x18,0x28,0x48,0x7C,0x08,0x08,0x00}, // -4-56
  95. {0x7C,0x40,0x78,0x04,0x04,0x44,0x38,0x00}, // -5-57
  96. {0x1C,0x20,0x40,0x78,0x44,0x44,0x38,0x00}, // -6-58
  97. {0x7C,0x04,0x08,0x10,0x20,0x20,0x20,0x00}, // -7-59
  98. {0x38,0x44,0x44,0x38,0x44,0x44,0x38,0x00}, // -8-60
  99. {0x38,0x44,0x44,0x3C,0x04,0x08,0x30,0x00}, // -9-61
  100. {0x00,0x30,0x30,0x00,0x30,0x30,0x00,0x00}, // -:-62
  101. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // - -63
  102. {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}, // -FULL-64
  103. };
  104. void delay (unsigned int a){
  105. unsigned int i;
  106. while(--a>0){
  107.   for(i=0;i<600;i++);
  108. }
  109. }
  110. void ca(void){//ca=close all
  111. P1=0x00;
  112. }
  113. void main (void){
  114. mode=0;
  115. chan=0;
  116. zt=0;
  117. LED=1;
  118. syst=0;
  119. EA=1;
  120. ET0=1;
  121. TH0 = 0x3c;
  122.    TL0 = 0xb0;
  123. c=0;
  124. TR0=1;
  125. sec=0;
  126. min=59;
  127. hour=16;
  128. tt=0;
  129. rs=1;
  130. while(1){/*
  131.   p=min/10;
  132.   if(tt>80){
  133.    p=min%10;
  134.   }
  135.   if(tt>160){
  136.    p=10;
  137.   }
  138.   if(tt>240){
  139.    p=sec/10;
  140.   }
  141.   if(tt>320){
  142.    p=sec%10;
  143.   }
  144.   if(tt>400){
  145.    p=11;
  146.   }
  147.   if(tt>480){
  148.    tt=0;
  149.   }*/
  150.   temp=0x80;
  151.   if(tt>60){
  152.    tt=0;
  153.    c++;
  154.   }
  155.   for(k=0;k<9;k++){
  156.    P0=~(temp);
  157.    if(rs==1){
  158.     temp2=word[msg[c]][k];
  159.     if(c==4){
  160.      c=0;
  161.      rs=0;
  162.     }
  163.    }else{
  164.     temp2=word[ledplay[c]][k];
  165.     if(c==7 && zt ==0){
  166.      c=0;
  167.     }
  168.     if(c==1 && zt !=0){
  169.      c=0;
  170.     }
  171.    }
  172.    for(j=0;j<9;j++){
  173.     temp3=temp2;
  174.     delay(1);
  175.     temp3>>=(8-j);
  176.     temp3<<=(8-j);
  177.     temp3>>=(tt/8);
  178.     temp3<<=(tt/8);
  179.     ca();
  180.     P1=temp3;
  181.    }
  182.    for(j=0;j<9;j++){
  183.     temp3=temp2;
  184.     delay(1);
  185.     temp3>>=(8-j);
  186.     temp3<<=(8-j);
  187.     temp3<<=(tt/8);
  188.     temp3>>=(tt/8);
  189.     ca();
  190.     P1=temp3;
  191.    }
  192.    temp>>=1;//换下一行
  193.   }
  194.   if(zt==0){
  195.    ledplay[0]=hour/10+52;
  196.    ledplay[1]=hour%10+52;
  197.    ledplay[2]=62;
  198.    ledplay[3]=min/10+52;
  199.    ledplay[4]=min%10+52;
  200.    ledplay[5]=63;
  201.    ledplay[6]=63;
  202.    ledplay[7]=63;
  203.   }
  204.   if(zt==1){
  205.    ledplay[0]=hour/10+52;
  206.   }
  207.   if(zt==2){
  208.    ledplay[0]=hour%10+52;
  209.   }
  210.   if(zt==3){
  211.    ledplay[0]=min/10+52;
  212.   }
  213.   if(zt==4){
  214.    ledplay[0]=min%10+52;
  215.   }/*
  216.   ledplay[8]=63;
  217.   ledplay[9]=63;
  218.   ledplay[0]=sec/10+52;
  219.   ledplay[1]=sec%10+52;*/
  220.   if(mode==1){
  221.    delay(30);
  222.    if(mode==1){
  223.     if(zt==0){
  224.      rs=1;
  225.      msg[0]=64;//Set
  226.      msg[1]=18;
  227.      msg[2]=30;
  228.      msg[3]=45;
  229.     }
  230.     zt++;
  231.     if(zt==5){
  232.      rs=1;
  233.      msg[0]=64;
  234.      msg[1]=14;
  235.      msg[2]=10;
  236.      msg[3]=63;
  237.      zt=0;
  238.     }
  239.     while(mode==1);
  240.    }
  241.   }
  242.   if(chan==1){
  243.    delay(30);
  244.    if(chan==1){
  245.     if(zt==1){
  246.      hour+=10;
  247.      if(hour>23){
  248.       hour=0;
  249.      }
  250.     }else if(zt==2){
  251.      hour+=1;
  252.      if(hour%10==0){
  253.       hour-=10;
  254.      }
  255.     }
  256.     if(zt==3){
  257.      min+=10;
  258.      if(min>59){
  259.       min=0;
  260.      }
  261.     }
  262.     if(zt==4){
  263.      min+=1;
  264.      if(min%10==0){
  265.       min-=0;
  266.      }
  267.     }
  268.     if(zt!=0){
  269.      sec=0;
  270.     }
  271.     while(chan==1);
  272.    }
  273.   }
  274. }
  275. }
  276. void t0 (void) interrupt 1 using 3{
  277. syst++;
  278. if(syst>79){
  279.   syst=0;
  280.   sec++;
  281.   LED=~LED;
  282.   if(sec>59){
  283.    sec=0;
  284.    min++;
  285.    if(min>59){
  286.     min=0;
  287.     hour++;
  288.     if(hour>23){
  289.      hour=0;
  290.      /*day++;
  291.      if(day>29){
  292.       day=0;
  293.       month++;
  294.       if(month>12){
  295.        month=0;
  296.        year++;
  297.        //happy();
  298.       }
  299.      }*/
  300.     }
  301.    }
  302.   }
  303. }
  304. tt++;
  305. TH0 = 0x31;
  306.    TL0 = 0x6d;
  307. }
复制代码



回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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