02比较闪

[复制链接]
437|0
 楼主| 34af9uc 发表于 2024-7-22 21:51 | 显示全部楼层 |阅读模式
TE, STM8, STM, ST, pc
  1. /****************NY8TE64A触摸实验*******************/
  2. /****************ID:共同学习stm8********************/
  3. /****************20240707**************************/
  4. /**************************************************/
  5. //            gnd-|1‾vss‾‾\_/‾‾vdd‾20|-5v
  6. //               -|2 pa6   N   pa4 19|-x1
  7. //               -|3 pa7   Y   pa3 18|-x2
  8. //               -|4 pa5   8   pa2 17|-x3
  9. //               -|5 pb3   T   pa1 16|-x4
  10. //               -|6 pb2   E   pa0 15|-x5
  11. //               -|7 pb1   6   pb5 14|-x6
  12. //               -|8 pb0   4   pb4 13|-x7
  13. //               -|9 pc0   A   pb6 12|-x8
  14. //               -|10_pc1______pb7_11|-x9
  15. /**************************************************/
  16. // ___a___           _______          _______          _______
  17. //|        |        |       |        |       |        |       |
  18. //f        b        |       |    ◇   |       |        |       |
  19. // ---g---           -------          -------          -------
  20. //|        |        |       |    ◇   |       |        |       |
  21. //e        c        |       |        |       |        |       |
  22. // ‾‾‾d‾‾‾           ‾‾‾‾‾‾‾          ‾‾‾‾‾‾‾          ‾‾‾‾‾‾‾
  23. //              @x1 @x2 @x3 @x4 @x5 @x6 @x7 @x8 @x9
  24. //               |   |   |   |   |   |   |   |   |
  25. //              PA4 PA3 PA2 PA1 PA0 PB5 PB4 PB6 PB7
  26. //x1--a--x2        x2--►--x3        x3--►--x4        x4--►--x5
  27. //x1--►--x3        x2--►--x4        x3--►--x5        x4--►--x6
  28. //x1--►--x4        x2--►--x5        x3--►--x6        x4--►--x7    x9--►--|
  29. //x1--d--x5        x2--►--x6        x3--►--x7        x4--►--x8    x9--►--|
  30. //x1--►--x6        x2--►--x7        x3--►--x8        x4--►--x1           ↓
  31. //x1--►--x7        x2--►--x8        x3--►--x1        x4--►--x2
  32. //x1--g--x8        x2--►--x1        x3--►--x2        x4--►--x3
  33. /**************************************************/
  34. #include <ny8.h>
  35. /**************************************************/
  36. __sbit x1                =PORTA:4;
  37. __sbit x2                =PORTA:3;
  38. __sbit x3                =PORTA:2;
  39. __sbit x4                =PORTA:1;
  40. __sbit x5                =PORTA:0;
  41. __sbit x6                =PORTB:5;
  42. __sbit x7                =PORTB:4;
  43. __sbit x8                =PORTB:6;
  44. __sbit x9                =PORTB:7;
  45. /**************************************************/
  46. #define                x1_gao                IOSTA&=~(1<<4);x1=1
  47. #define                x1_di                IOSTA&=~(1<<4);x1=0
  48. #define                x1_zu                IOSTA|=1<<4;

  49. #define                x2_gao                IOSTA&=~(1<<3);x2=1
  50. #define                x2_di                IOSTA&=~(1<<3);x2=0
  51. #define                x2_zu                IOSTA|=1<<3;

  52. #define                x3_gao                IOSTA&=~(1<<2);x3=1
  53. #define                x3_di                IOSTA&=~(1<<2);x3=0
  54. #define                x3_zu                IOSTA|=1<<2;

  55. #define                x4_gao                IOSTA&=~(1<<1);x4=1
  56. #define                x4_di                IOSTA&=~(1<<1);x4=0
  57. #define                x4_zu                IOSTA|=1<<1;

  58. #define                x5_gao                IOSTA&=~(1<<0);x5=1
  59. #define                x5_di                IOSTA&=~(1<<0);x5=0
  60. #define                x5_zu                IOSTA|=1<<0;

  61. #define                x6_gao                IOSTB&=~(1<<5);x6=1
  62. #define                x6_di                IOSTB&=~(1<<5);x6=0
  63. #define                x6_zu                IOSTB|=1<<5;

  64. #define                x7_gao                IOSTB&=~(1<<4);x7=1
  65. #define                x7_di                IOSTB&=~(1<<4);x7=0
  66. #define                x7_zu                IOSTB|=1<<4;

  67. #define                x8_gao                IOSTB&=~(1<<6);x8=1
  68. #define                x8_di                IOSTB&=~(1<<6);x8=0
  69. #define                x8_zu                IOSTB|=1<<6;

  70. #define                x9_gao                IOSTB&=~(1<<7);x9=1
  71. #define                x9_di                IOSTB&=~(1<<7);x9=0
  72. #define                x9_zu                IOSTB|=1<<7;
  73. /**************************************************/
  74. unsigned char const zi1[]={
  75. 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,                //0-9
  76. 0x77,0x7c,0x39,0x5e,0x79,0x71,0x7e,                                                //a-f,20
  77. 0x00,0x00,0x00};                                                                        //不显               
  78. unsigned char const zi12[]={
  79. 0x77,0x7c,0x39,0x5e,0x79,                //a-e
  80. 0x71,0x6f,0x76,0x04,0x1e,                //f-J
  81. 0x78,0x38,0x55,0x54,0x5c,                //k-o
  82. 0X73,0X67,0X50,0X49,0X31,                //p-t
  83. 0X3e,0X1c,0X1f,0X52,0X6e,0X5b};//u-z
  84. /**************************************************/
  85. static unsigned char xian_b1;                //第一个数码管要显示的数据
  86. static unsigned char xian_b2;                //第二个数码管要显示的数据
  87. static unsigned char xian_b3;                //第三个数码管要显示的数据
  88. static unsigned char xian_b4;                //第四个数码管要显示的数据
  89. static unsigned char xian_c1;                //第一个数码管要显示的字模
  90. static unsigned char xian_c2;                //第二个数码管要显示的字模
  91. static unsigned char xian_c3;                //第三个数码管要显示的字模
  92. static unsigned char xian_c4;                //第四个数码管要显示的字模
  93. static unsigned char xian_c5;                //点点
  94. /**************************************************/
  95. void        xianshi();                //显示
  96. void        xianshi_jisuan();                //显示计算
  97. void        yanshi();                //延时
  98. /**************************************************/
  99. void main(void)
  100. {
  101. /**************************************************/
  102. static unsigned int xian_a1;                //计次
  103. static unsigned int xian_a2;
  104. unsigned int                a1 =0;
  105. unsigned char                a2 =0;
  106. /**************************************************/
  107.         WDTEN                =0;                //关闭WDT,关狗
  108. /**************************************************/
  109. xian_c1=zi1[a1+0];
  110. xian_c2=zi1[a1+1];
  111. xian_c3=zi1[a1+2];
  112. xian_c4=zi1[a1+3];
  113. /**************************************************/
  114. while(1)
  115. {
  116. xian_a1                ++;
  117. if(xian_a1 ==435)                //显示50HZ
  118.         {
  119.         xian_a1                =0;
  120.         xian_a2                ++;
  121.         if(xian_a2 ==100){/*xian_c5 =1;*/}                //点点
  122.         if(xian_a2 >200)
  123.         {
  124.         xian_a2 =0;
  125.         xian_c5 =0;
  126.         xian_b1                =a1+0;
  127.         xian_b2                =a1+1;
  128.         xian_b3                =a1+2;
  129.         xian_b4                =a1+3;
  130.         a1                                ++;
  131.         if(a1 >16){a1 =0;}
  132.         xianshi_jisuan();
  133.         }
  134.         xianshi();
  135.         }


  136. }
  137. /**************************************************/
  138. }
  139. /**************************************************/
  140. void        yanshi()                //延时
  141. {
  142. unsigned int z1,z2;
  143. for(z1=200;z1>0;z1--)
  144.         for(z2=500;z2>0;z2--);
  145. }
  146. /**************************************************/
  147. void        xianshi_jisuan()                //显示计算
  148. {
  149. xian_c1                =zi1[xian_b1];
  150. xian_c2                =zi1[xian_b2];
  151. xian_c3                =zi1[xian_b3];
  152. xian_c4                =zi1[xian_b4];
  153. }
  154. /**************************************************/
  155. void xianshi()                //显示
  156. {
  157. //static unsigned char xian_a1;                //计次
  158. static unsigned char xian_a2;                //状态数码管1234
  159. xian_a2                ++;
  160. if(xian_a2 ==4){xian_a2 =0;}
  161. if(xian_a2 ==0)                //第一个数码管算法
  162.         {
  163.         x1_di;
  164.         if(xian_c1&0b00000001){x2_di;}        else{x2_zu;}                //a
  165.         if(xian_c1&0b00000010){x3_di;}        else{x3_zu;}                //b
  166.         if(xian_c1&0b00000100){x4_di;}        else{x4_zu;}                //c
  167.         if(xian_c1&0b00001000){x5_di;}        else{x5_zu;}                //d
  168.         if(xian_c1&0b00010000){x6_di;}        else{x6_zu;}                //e
  169.         if(xian_c1&0b00100000){x7_di;}        else{x7_zu;}                //f
  170.         if(xian_c1&0b01000000){x8_di;}        else{x8_zu;}                //g
  171.         x1_gao;
  172.         }
  173. if(xian_a2 ==1)                //第二个数码管算法
  174.         {
  175.         x2_di;
  176.         if(xian_c2&0b00000001){x3_di;}        else{x3_zu;}
  177.         if(xian_c2&0b00000010){x4_di;}        else{x4_zu;}
  178.         if(xian_c2&0b00000100){x5_di;}        else{x5_zu;}
  179.         if(xian_c2&0b00001000){x6_di;}        else{x6_zu;}
  180.         if(xian_c2&0b00010000){x7_di;}        else{x7_zu;}
  181.         if(xian_c2&0b00100000){x8_di;}        else{x8_zu;}
  182.         if(xian_c2&0b01000000){x1_di;}        else{x1_zu;}
  183.         x2_gao;
  184.         }
  185. if(xian_a2 ==2)                //第三个数码管算法
  186.         {
  187.         x3_di;
  188.         if(xian_c3&0b00000001){x4_di;}        else{x4_zu;}
  189.         if(xian_c3&0b00000010){x5_di;}        else{x5_zu;}
  190.         if(xian_c3&0b00000100){x6_di;}        else{x6_zu;}
  191.         if(xian_c3&0b00001000){x7_di;}        else{x7_zu;}
  192.         if(xian_c3&0b00010000){x8_di;}        else{x8_zu;}
  193.         if(xian_c3&0b00100000){x1_di;}        else{x1_zu;}
  194.         if(xian_c3&0b01000000){x2_di;}        else{x2_zu;}
  195.         x3_gao;
  196.         }
  197. if(xian_a2 ==3)                //第四个数码管算法
  198.         {
  199.         x4_di;
  200.         if(xian_c4&0b00000001){x5_di;}        else{x5_zu;}
  201.         if(xian_c4&0b00000010){x6_di;}        else{x6_zu;}
  202.         if(xian_c4&0b00000100){x7_di;}        else{x7_zu;}
  203.         if(xian_c4&0b00001000){x8_di;}        else{x8_zu;}
  204.         if(xian_c4&0b00010000){x1_di;}        else{x1_zu;}
  205.         if(xian_c4&0b00100000){x2_di;}        else{x2_zu;}
  206.         if(xian_c4&0b01000000){x3_di;}        else{x3_zu;}
  207.         x4_gao;
  208.         }
  209. if(xian_c5==1){x9_gao;}        else{x9_di;}

  210. }
  211. /**************************************************/
  212. /**************************************************/
  213. /**************************************************/


02.zip

1.91 KB, 下载次数: 0

319

主题

487

帖子

64

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