標題: 詳解單片機數(shù)碼管怎么使用仿真 帶程序 [打印本頁]

作者: heicc    時間: 2016-5-29 15:56
標題: 詳解單片機數(shù)碼管怎么使用仿真 帶程序


單片機數(shù)碼管仿真的原理圖



仿真文件下載:http://www.torrancerestoration.com/bbs/dpj-50777-1.html
  1. #include <reg51.h>

  2. #define uchar unsigned char
  3. uchar count = 0;
  4. uchar switc[9] = {0X7F, 0XBF, 0XDF, 0XEF, 0XF7, 0XFB, 0XFD, 0XFE};                //控制哪一個數(shù)碼管亮
  5. unsigned char disNumber[10] = {0xFF,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};        //數(shù)碼管顯示的數(shù)
  6. unsigned char disNumber_index;       

  7. void delay2ms(void)   //誤差 0us
  8. {
  9.   unsigned char a,b;
  10.   for(b=4;b>0;b--)
  11.     for(a=248;a>0;a--)
  12.         ;
  13. }

  14. void time1() interrupt 1                                                //定時器中斷
  15. {
  16.   uchar tempValue = 0;
  17.   count++;
  18.   if(count == 20)
  19.   {
  20.     count = 0;
  21.         disNumber_index++;
  22.         if(disNumber_index == 9)
  23.            disNumber_index =0;
  24.    }
  25.   
  26.    
  27.   TH0=(65536-50000)/256;                                                //16位定時器0x60B0  高八位TH0 60低八位 B0 定時50000微秒觸發(fā)定時器
  28.   TL0=(65536-50000)%256;
  29. }


  30. void main(void)       
  31. {
  32.   TMOD=0x01;//設(shè)置定時器0為工作方式1
  33.   TH0=(65536-50000)/256;
  34.   TL0=(65536-50000)%256;
  35.   EA=1;//打開中斷總開關(guān)
  36.   ET0=1;//開定時器0中斷
  37.   TR0=1;//啟動定時器0       
  38.   P2 = 0x00;
  39.   

  40.   while(1)
  41.   {          
  42.     P0 = disNumber[disNumber_index];
  43.        
  44.   }
  45. }//小月子2016年5月21日編輯   如果您有什么不理解的地方請加小月子QQ:616142166
  46. //小月子是個電子發(fā)燒友,小月子電子網(wǎng)店賣的是電子電路類、編程類學習資料教學視頻
  47. //請關(guān)注我的網(wǎng)
復(fù)制代碼









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