188拼灯数码管

[复制链接]
802|0
 楼主| 34af9uc 发表于 2024-10-8 22:09 | 显示全部楼层 |阅读模式
  1. /****************188拼灯数码管**********************/
  2. /****************ID:共同学习stm8********************/
  3. /****************20241007**************************/
  4. /**************************************************/
  5. //         ____   ____
  6. //    PB4-|1   \_/  16|-PB3
  7. //    PB5-|2   NY   15|-PB2
  8. //    PA0-|3    8   14|-PB1
  9. //    PA1-|4    A   13|-PB0
  10. //    VDD-|5    0   12|-VSS
  11. //    PA7-|6    5   11|-PA2
  12. //    PA6-|7    4   10|-PA3
  13. //    PA5-|8____E____9|-PA4

  14. //         WY1208BWE16-10.28
  15. //          _A2_      _A3_
  16. //    |    F2   B2   F3   B3    /L1
  17. //   B1    |_G2_|    |_G3_|
  18. //    |    E2  C2    E3   C3    %L2
  19. //   C1    |_D2_|    |_D3_|
  20. //     [url=home.php?mod=space&uid=2514798]@1[/url]   @2    @3   [url=home.php?mod=space&uid=26072]@4[/url]   @5
  21. //     |    |     |    |    |
  22. //    pb4  pb3   pb2  pb1  pb0
  23. //       _____________________________
  24. //第一次|_1高_|_A3__|_C3__|_____|_E3__|
  25. //第二次|_B3__|_2高_|_A2__|_C1__|_L2__|
  26. //第三次|_D3__|_B2__|_3高_|_B1__|_L1__|
  27. //第四次|_F3__|_D2__|_C2__|_4高_|_____|
  28. //第五次|_G3__|_E2__|_F2__|_G2__|_5高_|

  29. /**************************************************/
  30. #include <ny8.h>
  31. //#include "NY8_constant.h"
  32. //#define UPDATE_REG(x)        __asm__("MOVR _" #x ",F")
  33. __sbit x1                =PORTA:4;
  34. __sbit x2                =PORTA:3;
  35. __sbit x3                =PORTA:2;
  36. __sbit x4                =PORTA:1;
  37. __sbit x5                =PORTA:0;
  38. #define                x1_gao                IOSTB&=~(1<<4);x1=1
  39. #define                x1_di                IOSTB&=~(1<<4);x1=0
  40. #define                x1_zu                IOSTB|=1<<4;

  41. #define                x2_gao                IOSTB&=~(1<<3);x2=1
  42. #define                x2_di                IOSTB&=~(1<<3);x2=0
  43. #define                x2_zu                IOSTB|=1<<3;

  44. #define                x3_gao                IOSTB&=~(1<<2);x3=1
  45. #define                x3_di                IOSTB&=~(1<<2);x3=0
  46. #define                x3_zu                IOSTB|=1<<2;

  47. #define                x4_gao                IOSTB&=~(1<<1);x4=1
  48. #define                x4_di                IOSTB&=~(1<<1);x4=0
  49. #define                x4_zu                IOSTB|=1<<1;

  50. #define                x5_gao                IOSTB&=~(1<<0);x5=1
  51. #define                x5_di                IOSTB&=~(1<<0);x5=0
  52. #define                x5_zu                IOSTB|=1<<0;


  53. unsigned char xianshi_a1;                //显示RAM变量
  54. unsigned char xianshi_b1;                //显示RAM数字
  55. unsigned char xianshi_b2;
  56. unsigned char xianshi_b3;
  57. unsigned char xianshi_c1;                //显示RAM字模
  58. unsigned char xianshi_c2;
  59. unsigned char xianshi_c3;

  60. unsigned char const zi1[]={
  61. 0x3f, //0,0
  62. 0x06, //1,1
  63. 0x5b, //2,2
  64. 0x4f, //3,3
  65. 0x66, //4,4
  66. 0x6d, //5,5
  67. 0x7d, //6,6
  68. 0x07, //7,7
  69. 0x7f, //8,8
  70. 0x6f, //9,9
  71. 0x77, //10,a
  72. 0x7c, //11,b
  73. 0x39, //12,c
  74. 0x5e, //13,d
  75. 0x79, //14,e
  76. 0x71}; //15,f
  77. /**************************************************/
  78. void                yanshi(unsigned char z1);                //延时
  79. void                chushihua();                        //初始化
  80. void                xianshi_jisuan();                //显示计算
  81. void                xianshi();                                //显示

  82. /**************************************************/
  83. void main(void)
  84. {
  85. unsigned char a1;
  86. chushihua();                //初始化
  87. xianshi_a1                =0;
  88. yanshi(100);                //延时
  89. while(1)
  90. {
  91. //CLRWDT();                //喂狗
  92. xianshi_a1                ++;                if(xianshi_a1 >199){xianshi_a1 =0;}
  93. xianshi_jisuan();                //显示计算

  94. for(a1 =50;a1 >0;a1 --)                //显示50次
  95.         {
  96.         xianshi();                                //显示
  97.         }

  98. }
  99. }
  100. /**************************************************/
  101. void                xianshi()                                //显示
  102. {
  103. x1_zu;                //第一种
  104. x2_zu;
  105. x3_zu;
  106. x4_zu;
  107. x5_zu;

  108. //if(xianshi_c3 &0b00000000){}                        //1高
  109. if(xianshi_c3 &0b00000001){x2_di;}                //3A
  110. if(xianshi_c3 &0b00000100){x3_di;}                //3C
  111. //if(xianshi_c1 &0b00000000){x4_di;}        //无
  112. if(xianshi_c3 &0b00010000){x5_di;}                //3E
  113. x1_gao;
  114. yanshi(100);                //延时


  115. x1_zu;                //第二种
  116. x2_zu;
  117. x3_zu;
  118. x4_zu;
  119. x5_zu;

  120. if(xianshi_c3 &0b00000010){x1_di;}                //3B
  121. //if(xianshi_c1 &0b00000000){}                        //2高
  122. if(xianshi_c2 &0b00000001){x3_di;}                //2A
  123. //if(xianshi_c1 &0b00000100){x4_di;}        //1C
  124. if(xianshi_c1 ==1){x4_di;}                                //1C
  125. //if(xianshi_c1 &0b00000000){x5_di;}        //%
  126. x2_gao;
  127. yanshi(100);                //延时


  128. x1_zu;                //第三种
  129. x2_zu;
  130. x3_zu;
  131. x4_zu;
  132. x5_zu;

  133. if(xianshi_c3 &0b00001000){x1_di;}                //3D
  134. if(xianshi_c2 &0b00000010){x2_di;}                //2B
  135. //if(xianshi_c1 &0b00000000){}                        //3高
  136. //if(xianshi_c1 &0b00000010){x4_di;}        //1B
  137. if(xianshi_c1 ==1){x4_di;}                                //1B
  138. //if(xianshi_c3 &0b00000000){x5_di;}        // /
  139. x3_gao;
  140. yanshi(100);                //延时


  141. x1_zu;                //第四种
  142. x2_zu;
  143. x3_zu;
  144. x4_zu;
  145. x5_zu;

  146. if(xianshi_c3 &0b00100000){x1_di;}                //3F
  147. if(xianshi_c2 &0b00001000){x2_di;}                //2D
  148. if(xianshi_c2 &0b00000100){x3_di;}                //2C
  149. //if(xianshi_c1 &0b00000000){}                        //4高
  150. //if(xianshi_c1 &0b00000000){}                        //无
  151. x4_gao;
  152. yanshi(100);                //延时




  153. x1_zu;                //第五种
  154. x2_zu;
  155. x3_zu;
  156. x4_zu;
  157. x5_zu;

  158. if(xianshi_c3 &0b01000000){x1_di;}                //3G
  159. if(xianshi_c2 &0b00010000){x2_di;}                //2E
  160. if(xianshi_c2 &0b00100000){x3_di;}                //2F
  161. if(xianshi_c2 &0b01000000){x4_di;}                //2G
  162. //if(xianshi_c1 &0b00000000){}                        //5高
  163. x5_gao;
  164. yanshi(100);                //延时


  165. }
  166. /**************************************************/
  167. void                xianshi_jisuan()                //显示计算
  168. {
  169. xianshi_b1                =xianshi_a1 /100;                        //取百位
  170. xianshi_b2                =(xianshi_a1 %100)/10;                //取十位
  171. xianshi_b3                =xianshi_a1 %10;                        //取个位

  172. xianshi_c1                =zi1[xianshi_b1];                        //取百位字模
  173. xianshi_c2                =zi1[xianshi_b2];                        //取十位字膜
  174. xianshi_c3                =zi1[xianshi_b3];                        //取个位字膜
  175. }
  176. /**************************************************/
  177. void                chushihua()                //初始化
  178. {

  179. }
  180. /**************************************************/
  181. void                yanshi(unsigned char z1)                //延时
  182. {
  183. unsigned char z2,z3;
  184. for(z2=z1;z2>0;z2--)
  185.         for(z3=180;z3>0;z3--);
  186. }
  187. /**************************************************/


main.zip

1.7 KB, 下载次数: 4

319

主题

487

帖子

64

粉丝
快速回复 在线客服 返回列表 返回顶部