標題: ADC0808采集電壓并且用數(shù)碼管顯示(仿真+單片機源碼) [打印本頁]

作者: 1925558918    時間: 2018-10-18 21:58
標題: ADC0808采集電壓并且用數(shù)碼管顯示(仿真+單片機源碼)
ADC0808采集電壓并且用數(shù)碼管顯示仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機源程序如下:
  1. #include<reg51.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int

  4. uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  5. sbit CLK=P1^3;
  6. sbit ST=P1^2;
  7. sbit EOC=P1^1;
  8. sbit OE=P1^0;

  9. void DelayMS(uint ms)
  10. {
  11.         uchar i;
  12.         while(ms--)
  13.                 for(i=0;i<120;i++);
  14. }
  15. /******************顯示采集的電壓**********************************/
  16. void Display_Result(uchar d)
  17. {
  18.         P2=0xf7;
  19.         P0=DSY_CODE[d%10];                //注意:當d變?yōu)?*d時候,顯示正確,但不知why
  20.         DelayMS(5);
  21.         P2=0xfb;
  22.         P0=DSY_CODE[d%100/10];
  23.         DelayMS(5);
  24.         P2=0xfd;
  25.         P0=DSY_CODE[d/100]|0x80;
  26.         DelayMS(5);
  27. }

  28. void main()
  29. {
  30. //        uchar guo;
  31.         TMOD=0x02;
  32.         TH0=0x14;
  33.         TL0=0x00;
  34.         IE=0x82;
  35.         TR0=1;
  36.         
  37.         P1=0x3f; //通道選擇
  38.         
  39.         while(1)
  40.         {
  41.                 ST=0;ST=1;ST=0; //ADC啟動
  42.                 while(EOC==0); //轉(zhuǎn)換結(jié)束信號
  43.                 OE=1;                //輸出使能
  44. //                guo=(P3/256)*5*100;
  45.                 Display_Result(P3);
  46.                 OE=0;
  47.         }
  48. }

  49. void Timer0_INT() interrupt 1
  50. {
  51.         CLK=~CLK;
  52. }
復制代碼

所有資料51hei提供下載:
ADC0808采集電壓并且用數(shù)碼管顯示0.zip (67.46 KB, 下載次數(shù): 146)







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