欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: 數(shù)碼管中斷顯示+高位滅零處理 [打印本頁]

作者: liuqq    時(shí)間: 2015-5-21 23:26
標(biāo)題: 數(shù)碼管中斷顯示+高位滅零處理
  1. //清理硬盤時(shí)發(fā)現(xiàn)自己以前寫的,貼上來吧,雖然沒什么水平,
  2. //5毫秒一個(gè)顯示周期,理論上顯示20位數(shù)碼管不會(huì)有閃爍感,
  3. 占用了一個(gè)定時(shí)器,簡約的算法實(shí)現(xiàn)高位滅零處理
  4. #include <avr/io.h>
  5. #include <avr/interrupt.h>
  6. unsigned int flag=0;
  7. unsigned char count=0;
  8. unsigned int num=0;
  9. //==================================================
  10. const unsigned char seg[]={        0xC0, // 0
  11. 0xF9, // 1
  12. 0xA4, // 2
  13. 0xB0, // 3
  14. 0x99, // 4
  15. 0x92, // 5
  16. 0x82, // 6
  17. 0xF8, // 7
  18. 0x80, // 8
  19. 0x90 // 9
  20. };


  21. //==================================================

  22. //IO端口初始化
  23. void PortInit(void)
  24. {
  25. DDRA=0XFF;
  26. PORTA=0X00;
  27. DDRB=0XFF;
  28. PORTB=0XFF;
  29. }

  30. //Timer0初始化
  31. void Timer0Init(void)
  32. {
  33. TCCR0 = 0x00; //stop
  34. TCNT0 = 0x06; //set count
  35. OCR0  = 0xFA;  //set compare
  36. TCCR0 = 0x03; //start timer
  37. }

  38. //==================================================

  39. //定時(shí)器0溢出中斷服務(wù)程序
  40. ISR(TIMER0_OVF_vect)
  41. {
  42. TCNT0=0X06;
  43. flag++;
  44. count++;
  45. switch(count)
  46. {
  47. case 1:if(num/1000){PORTA=0X01;PORTB=seg[num/1000];}else PORTB=0XFF;break;
  48. case 2:if(((num/1000)+(num%1000/100))){PORTA=0X02;PORTB=seg[num%1000/100];}else PORTB=0XFF;break;
  49. case 3:if(((num/1000)+(num%1000/100)+(num%100/10))){PORTA=0X04;PORTB=seg[num%100/10];}else PORTB=0XFF;break;
  50. case 4:PORTA=0X08;PORTB=seg[num%10];break;
  51. case 5:count=0;break;
  52. default:break;
  53. }
  54. if (flag==100)
  55. {
  56. flag=0;
  57. num++;
  58. if(num==9999)
  59. {
  60. num=0;
  61. }
  62. }
  63. }

  64. //==================================================

  65. //主函數(shù)
  66. int main(void)
  67. {
  68. cli();
  69.     TIMSK = 0x01; //timer interrupt sources
  70. PortInit();
  71. Timer0Init();
  72. sei();
  73. while(1)
  74.       {
  75.         ;
  76. }
  77. }
復(fù)制代碼







歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1