当前位置:   article > 正文

应广单片机PFS123按键中断控制数码管显示例程_pfs123驱动数码管

pfs123驱动数码管

目录

应广单片机PFS123按键中断控制数码管显示视频

led数码管图片

应广单片机PFS123按键中断控制数码管显示代码

应广科技网址,开发工具,PMS123规格书:http://www.padauk.com.tw/cn/product/show.aspx?num=145&kw=PFS123


led数码管图片

应广单片机PFS123按键中断控制数码管显示代码

  1. #include "extern.h"
  2. COM1 equ pc.3
  3. COM2 equ pa.7
  4. COM3 equ pa.6
  5. jia equ pb.4
  6. jian equ pb.6
  7. byte m;
  8. byte num_bit;
  9. byte num_ten;
  10. word reload_T16;
  11. bit j;
  12. word counter=0;
  13. void Look_Table(void)
  14. {
  15. A += 1;
  16. _Pcadd
  17. {
  18. ret 0x3f;//0
  19. ret 0x06;//1
  20. ret 0x5b;//2
  21. ret 0x4f;//3
  22. ret 0x66;//4
  23. ret 0x6d;//5
  24. ret 0x7d;//6
  25. ret 0x07;//7
  26. ret 0x7f;//8
  27. ret 0x6f;//9
  28. }
  29. }
  30. void T16_Time(void)
  31. {
  32. $ T16M SYSCLK,/4,bit12; //T16的时钟源选择,内部的时钟分频器,中断源选择(当选择位由低到高或者由高到低时,发生中断事件);
  33. //时钟源选择可以选择STOP, SYSCLK, PA4_F, IHRC, EOSC, ILRC, PA0_F;分频器可选择/1, /4, /16, /64
  34. //中断源可选择BIT8, BIT9, BIT10, BIT11, BIT12, BIT13, BIT14, BIT15
  35. reload_T16 = 4096-500; //每次进中断为1ms;
  36. //计算公式为 [1/(时钟源/分频器)]*(中断源-reload_T16)=[1/(4M/4)]*(2^12-(4096-1000))=1000us=1ms
  37. stt16 reload_T16; //设定计数器初始值reload_T16,当计数器累加超过设定中断源时产生中断;
  38. $ INTEN T16; //中断允许寄存器,启用从T16的溢出中断;1:启用,0:停用。
  39. $ INTRQ T16; //中断请求寄存器,此位是由硬件置位并由软件清零;1:请求,0:不请求。
  40. //注:INTEN,INTRQ没有初始值,所以要使用中断前,一定要根据需要设定数据。即使INTEN为0,INTRQ还是会被中断发生源触发。
  41. $ INTEGS BIT_R; //T16中断边缘选择,上升缘请求中断为BIT_R,下降缘请求中断为BIT_F;默认为上升缘请求。
  42. INTEN.T16 = 1; //开T16中断
  43. INTRQ.T16 = 0; //清零INTRQ寄存器。
  44. ENGINT; //打开全局中断
  45. }
  46. void xianshi(void)
  47. {
  48. A = num_ten;
  49. Look_Table();
  50. m = A;
  51. PA = m & 0x01; //a-> pa0=1,其他的关
  52. PB = m & 0x00;
  53. PC = m & 0x00;
  54. $ COM1 out,low; //c3为共阴极=0,a->f流水灯
  55. $ COM2 out,high;
  56. $ COM3 out,high;
  57. .delay 1000;
  58. PA = (m<<3) & 0x10; //b-> a4=1,其他的关
  59. PB = m & 0x00;
  60. PC = m & 0x00;
  61. $ COM1 out,low; //c3为共阴极=0,a->f流水灯
  62. $ COM2 out,high;
  63. $ COM3 out,high;
  64. .delay 1000;
  65. PA = (m<<1 )& 0x08; //c a3=1,其他的关
  66. PB = m & 0x00;
  67. PC = m & 0x00;
  68. $ COM1 out,low; //c3为共阴极=0,a->f流水灯
  69. $ COM2 out,high;
  70. $ COM3 out,high;
  71. .delay 1000;
  72. PA = m & 0x00; //d c0=1,其他的关
  73. PB = m & 0x00;
  74. PC = (m>>3) & 0x01;
  75. $ COM1 out,low; //c3为共阴极=0,a->f流水灯
  76. $ COM2 out,high;
  77. $ COM3 out,high;
  78. .delay 1000;
  79. PA = m & 0x00; //e c1=1,其他的关
  80. PB = m & 0x00;
  81. PC = (m>>3) & 0x02;
  82. $ COM1 out,low; //c3为共阴极=0,a->f流水灯
  83. $ COM2 out,high;
  84. $ COM3 out,high;
  85. .delay 1000;
  86. PA = m & 0x00; //f b0=1,其他的关
  87. PB = (m>>5) & 0x01;
  88. PC = m & 0x00;
  89. $ COM1 out,low; //c3为共阴极=0,a->f流水灯
  90. $ COM2 out,high;
  91. $ COM3 out,high;
  92. .delay 1000;
  93. PA = (m>>2) & 0x10; //g a6=0,a4=1,其他的关
  94. PB = m & 0x00;
  95. PC = m & 0x00;
  96. $ COM1 out,high;
  97. $ COM2 out,high;
  98. $ COM3 out,low; //a6为共阴极=0,开g数码管
  99. .delay 1000;
  100. /*个位分两部分*/
  101. A = num_bit;
  102. Look_Table();
  103. m = A;
  104. PA = m & 0x01; //a-> pa0=1,其他的关
  105. PB = m & 0x00;
  106. PC = m & 0x00;
  107. $ COM1 out,high; //c3为共阴极=0,a->f流水灯
  108. $ COM2 out,low;
  109. $ COM3 out,high;
  110. .delay 1000;
  111. PA = (m<<3) & 0x10; //b-> a4=1,其他的关
  112. PB = m & 0x00;
  113. PC = m & 0x00;
  114. $ COM1 out,high; //c3为共阴极=0,a->f流水灯
  115. $ COM2 out,low;
  116. $ COM3 out,high;
  117. .delay 1000;
  118. PA = (m<<1 )& 0x08; //c a3=1,其他的关
  119. PB = m & 0x00;
  120. PC = m & 0x00;
  121. $ COM1 out,high; //c3为共阴极=0,a->f流水灯
  122. $ COM2 out,low;
  123. $ COM3 out,high;
  124. .delay 1000;
  125. PA = m & 0x00; //d c0=1,其他的关
  126. PB = m & 0x00;
  127. PC = (m>>3) & 0x01;
  128. $ COM1 out,high; //c3为共阴极=0,a->f流水灯
  129. $ COM2 out,low;
  130. $ COM3 out,high;
  131. .delay 1000;
  132. PA = m & 0x00; //e c1=1,其他的关
  133. PB = m & 0x00;
  134. PC = (m>>3) & 0x02;
  135. $ COM1 out,high; //c3为共阴极=0,a->f流水灯
  136. $ COM2 out,low;
  137. $ COM3 out,high;
  138. .delay 1000;
  139. PA = m & 0x00; //f b0=1,其他的关
  140. PB = (m>>5) & 0x01;
  141. PC = m & 0x00;
  142. $ COM1 out,high; //c3为共阴极=0,a->f流水灯
  143. $ COM2 out,low;
  144. $ COM3 out,high;
  145. .delay 1000;
  146. PA = (m>>3) & 0x08; //g a6=0,a3=1,其他的关
  147. PB = m & 0x00;
  148. PC = m & 0x00;
  149. $ COM1 out,high;
  150. $ COM2 out,high;
  151. $ COM3 out,low; //a6为共阴极=0,开g数码管
  152. .delay 1000;
  153. }
  154. void anjian(void)
  155. {
  156. if(j)//1ms 中断扫描
  157. {
  158. j=0;
  159. if(jia==0)
  160. {
  161. if(jia==0)
  162. {
  163. if(counter<1500) counter++;//jishi
  164. if(counter==20)//长按
  165. {
  166. if(num_bit<10) {num_bit++;}
  167. if(num_bit==10) {num_bit=0;num_ten++;if(num_ten>=10)num_ten=0;}
  168. counter=0;
  169. }
  170. }
  171. else
  172. {
  173. if(counter>4&&counter<20)//xiaodou duanan
  174. {
  175. if(num_bit<10) {num_bit++;}
  176. if(num_bit==10) {num_bit=0;num_ten++;if(num_ten>=10)num_ten=0;}
  177. }
  178. counter=0;
  179. }
  180. }
  181. if(jian==0)
  182. {
  183. if(jian==0)
  184. {
  185. if(counter<1500) counter++;//jishi
  186. if(counter==20)//长按
  187. {
  188. if((num_bit>0||num_bit==0 )&& num_ten==0)
  189. {
  190. if(!num_bit)
  191. {
  192. num_bit=9;num_ten=9;
  193. }
  194. else
  195. {
  196. num_bit--;
  197. }
  198. }
  199. else if(num_ten>0 && (num_bit>0||num_bit==0 ))
  200. {
  201. if(!num_bit)
  202. {
  203. num_ten--;
  204. num_bit=9;
  205. }
  206. else
  207. {
  208. num_bit--;
  209. }
  210. }
  211. counter =0;
  212. }
  213. }
  214. else
  215. {
  216. if(counter>4&&counter<20)//xiaodou duanan
  217. {
  218. if((num_bit>0||num_bit==0 )&& num_ten==0)
  219. {
  220. if(!num_bit)
  221. {
  222. num_bit=9;num_ten=9;
  223. }
  224. else
  225. {
  226. num_bit--;
  227. }
  228. }
  229. else if(num_ten>0 && (num_bit>0||num_bit==0 ))
  230. {
  231. if(!num_bit)
  232. {
  233. num_ten--;
  234. num_bit=9;
  235. }
  236. else
  237. {
  238. num_bit--;
  239. }
  240. }
  241. }
  242. counter=0;
  243. }
  244. }
  245. }
  246. }
  247. void FPPA0 (void)
  248. {
  249. .ADJUST_IC SYSCLK=IHRC/8, IHRC=16MHz, VDD=5V;
  250. num_ten = 2;
  251. num_bit = 5;
  252. PAC = 0b1101_1001;
  253. PBC = 0b0000_0001;
  254. PCC = 0B0000_1011;
  255. PA = 0b0000_0000;
  256. PB = 0b0000_0000;
  257. PC = 0b0000_0000;
  258. $ jia in,pull; //输入上拉
  259. $ jian in,pull; //输入上拉
  260. T16_Time();
  261. .delay 10000;
  262. while (1)
  263. {
  264. xianshi();
  265. anjian();
  266. }
  267. }
  268. void Interrupt (void)
  269. {
  270. pushaf; //进栈
  271. if (Intrq.T16)
  272. {
  273. Intrq.T16=0;
  274. stt16 reload_T16;
  275. j=1;
  276. }
  277. popaf; //出栈
  278. }

应广科技网址,开发工具,PMS123规格书:http://www.padauk.com.tw/cn/product/show.aspx?num=145&kw=PFS123

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号