標(biāo)題: 動(dòng)態(tài)數(shù)碼管 [打印本頁(yè)]

作者: yun251314    時(shí)間: 2017-2-16 10:13
標(biāo)題: 動(dòng)態(tài)數(shù)碼管
  1. #include<reg51.h>

  2. //--定義使用的IO口--//
  3. #define GPIO_DIG   P0        //段選
  4. #define GPIO_PLACE P1        //位選

  5. //--定義全局變量--//
  6. unsigned char code DIG_PLACE[8] = {
  7. 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位選控制   查表的方法控制
  8. unsigned char code DIG_CODE[17] = {
  9. 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
  10. 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
  11. //0、1、2、3、4、5、6、7、8、9、A、b、C、d、E、F的顯示碼
  12. unsigned char DisplayData[8];
  13. //用來(lái)存放要顯示的8位數(shù)的值

  14. //--聲明全局函數(shù)--//
  15. void DigDisplay(); //動(dòng)態(tài)顯示函數(shù)

  16. /*******************************************************************************
  17. * 函 數(shù) 名         : main
  18. * 函數(shù)功能                   : 主函數(shù)
  19. * 輸    入         : 無(wú)
  20. * 輸    出         : 無(wú)
  21. *******************************************************************************/

  22. void main(void)
  23. {
  24.         unsigned char i;

  25.         for(i=0; i<8; i++)
  26.         {
  27.                 DisplayData[i] = DIG_CODE[i];       
  28.         }
  29.         while(1)
  30.         {
  31.                 DigDisplay();
  32.         }                               
  33. }

  34. /*******************************************************************************
  35. * 函 數(shù) 名         : DigDisplay
  36. * 函數(shù)功能                   : 使用數(shù)碼管顯示
  37. * 輸    入         : 無(wú)
  38. * 輸    出         : 無(wú)
  39. *******************************************************************************/

  40. void DigDisplay()
  41. {
  42.         unsigned char i;
  43.         unsigned int j;

  44.         for(i=0; i<8; i++)
  45.         {
  46.                 GPIO_PLACE = DIG_PLACE[i];         //發(fā)送位選
  47.                 GPIO_DIG = DisplayData[i];     //發(fā)送段碼
  48.                 j = 10;                                                 //掃描間隔時(shí)間設(shè)定
  49.                 while(j--);       
  50.                 GPIO_DIG = 0x00;//消隱
  51.         }
  52. }
復(fù)制代碼



作者: 新手,請(qǐng)賜教    時(shí)間: 2017-7-8 09:27
請(qǐng)問(wèn)下我時(shí)候?yàn)槭裁磾?shù)碼管顯示一直在閃,并且數(shù)字不規(guī)則變化有部分亂碼?難道他這個(gè)動(dòng)態(tài)數(shù)碼管就是指數(shù)碼管閃動(dòng)?




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