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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3507|回復(fù): 0
收起左側(cè)

液晶顯示的單片機(jī)ADC0832數(shù)字電壓表

[復(fù)制鏈接]
ID:859742 發(fā)表于 2020-12-13 23:26 | 顯示全部樓層 |閱讀模式
一、實(shí)驗(yàn)要求
利用51單片機(jī)設(shè)計(jì)一個數(shù)字電壓表,實(shí)現(xiàn)從模擬信號輸入到數(shù)字信號輸出的基本功能,具體要求如下:
1)通過滑動變阻器改變輸入電壓;
2)利用AD轉(zhuǎn)換器ADC0832將輸入電壓轉(zhuǎn)換為數(shù)字信號送到單片機(jī);
3)在LCD上顯示輸入電壓值,保留三位小數(shù);
4)在電壓測量值后面顯示單位“V”

Using C51 MCU to design a digital voltmeter achieve from the analog signal input to the basic functions of digital signal output.
(1) Change the input voltage by sliding the rheostat;
(2) Using the AD converter ADC0832 to convert the input voltage to a digital signal to the MCU;
(3) The input voltage value is displayed on the LCD, leaving three decimal places;
(4) After the voltage measurement value shows the unit "V".



二、實(shí)驗(yàn)任務(wù)
本系統(tǒng)以51單片機(jī)作為控制核心,實(shí)現(xiàn)LCD顯示的控制、AD轉(zhuǎn)換器的啟動與數(shù)據(jù)讀入,并協(xié)調(diào)和控制各個模塊的工作。


The system uses C51 MCU as the control core, to achieve LCD display control, AD converter start and data read, and coordinate and control the work of each module


四、硬件電路


五、實(shí)驗(yàn)程序
  1. #include<reg51.h>
  2. #include<intrins.h>
  3. #include<string.h>

  4. typedef unsigned char u8;
  5. typedef unsigned int u16;

  6. sbit CS=P1^0; //片選線
  7. sbit CLK=P1^1; //時鐘線
  8. sbit DIO=P1^2; //數(shù)據(jù)線


  9. sbit RS = P2^0; //寄存器選擇
  10. sbit RW = P2^1; //讀寫控制
  11. sbit E = P2^2; //使能控制

  12. #define LCD P0

  13. u8 BUFF[] = " VOLTAGE:
  14. 0.00V";


  15. void delay_4us();
  16. void delay_ms(u16 i);
  17. bit Read_LCD_Busy_Flag();
  18. void Write_LCD_Command(u8
  19. cmd);
  20. void Write_LCD_Data(u8 dat);
  21. void LCD_Show_String(u8 r,u8
  22. c,char *s);
  23. void LCD_Init();
  24. u8 Get_AD_Result1();

  25. void delay_4us()
  26. {
  27.         _nop_();
  28.         _nop_();
  29.         _nop_();
  30.         _nop_();
  31. }


  32. void delay_ms(u16 i)
  33. {
  34.         u16 t;
  35.         while(i--)
  36.         {
  37.                 for(t=0;t<120;t++)
  38.                 {
  39.                         ;
  40.                 }
  41.         }
  42. }
  43. //讀液晶屏是否繁忙
  44. bit Read_LCD_Busy_Flag()
  45. {
  46.         u8 result;
  47.         LCD = 0xFF;
  48.         RS = 0;
  49.         RW = 1;
  50.         E = 1;
  51.         delay_4us();
  52.         result = P0;
  53.         E = 0;
  54.         return(result & 0x80)?1:0;
  55. }
  56. //寫液晶屏命令
  57. void Write_LCD_Command(u8
  58. cmd)
  59. {
  60.         while(Read_LCD_Busy_Flag());
  61.         RS = 0;
  62.         RW = 0;
  63.         E = 0;
  64.         _nop_();
  65.         _nop_();
  66.         LCD = cmd;
  67.         delay_4us();
  68.         E = 1;
  69.         delay_4us();
  70.         E = 0;
  71. }
  72. //寫液晶屏數(shù)據(jù)
  73. void Write_LCD_Data(u8 dat)
  74. {
  75.         while(Read_LCD_Busy_Flag());
  76.         RS = 1;
  77.         RW = 0;
  78.         E = 0;
  79.         LCD = dat;
  80.         delay_4us();
  81.         E = 1;
  82.         delay_4us();
  83.         E = 0;
  84. }
  85. //液晶屏顯示函數(shù)
  86. void LCD_Show_String(u8 r,u8
  87. c,char *s)
  88. {
  89.         u8 i=0;
  90.         u8 code DDRAM[] =
  91. {0x80,0xC0};
  92.         Write_LCD_Command(DDRA
  93. M[r] | c);
  94.         while(s[ i] && i < 16)
  95.         {
  96.                 Write_LCD_Data(s[i++]);
  97.         }
  98. }
  99. //液晶屏初始化
  100. void LCD_Init()
  101. {
  102.         Write_LCD_Command(0x38);
  103.         delay_ms(1);
  104.         Write_LCD_Command(0x0C);
  105.         delay_ms(1);
  106.         Write_LCD_Command(0x06);
  107.         delay_ms(1);
  108.         Write_LCD_Command(0x01);
  109.         delay_ms(1);
  110. }
  111. //獲取AD轉(zhuǎn)換結(jié)果
  112. u8 Get_AD_Result1()
  113. {
  114.         u8 i,dat1=0,dat2=0;
  115.         CS=0;
  116.         CLK=0;
  117.         DIO=1;
  118.         _nop_();
  119.         _nop_();
  120.         CLK=1;
  121.         _nop_();
  122.         _nop_();
  123.         CLK=0;
  124.         DIO=1;
  125.         _nop_();
  126.         _nop_();
  127.         CLK=1;
  128.         _nop_();
  129.         _nop_();
  130.         CLK=0;
  131.         DIO=0;
  132.         _nop_();
  133.         _nop_();
  134.         CLK=1;
  135.         _nop_();
  136.         _nop_();
  137.         CLK=0;
  138.         DIO=1;
  139.         _nop_();
  140.         _nop_();
  141.         for(i=0;i<8;i++)
  142.         {
  143.                 CLK=1;
  144.                 _nop_();
  145.                 _nop_();
  146.                 CLK=0;
  147.                 _nop_();
  148.                 _nop_();
  149.                 dat1=(dat1<<1)|DIO;
  150.         }
  151.         for(i=0;i<8;i++)
  152.         {
  153.                 dat2=dat2|((u8)DIO<<i);
  154.                 CLK=1;
  155.                 _nop_();
  156.                 _nop_();
  157.                 CLK=0;
  158.                 _nop_();
  159.                 _nop_();
  160.         }
  161.         CS=1;
  162.         return(dat1==dat2)?dat1:0x00;
  163. }



  164. void main()
  165. {
  166.         u8 AD;
  167.         u16 d;
  168.         LCD_Init();

  169.         while(1)
  170.         {
  171.                 AD=Get_AD_Result1();//獲取AD轉(zhuǎn)換值
  172.                 d=AD*500.0*2/511;
  173.                 BUFF[11]=(d/100) + '0';
  174.                 BUFF[13]=((d/10)%10) +
  175. '0';
  176.                 BUFF[14]=(d%10) + '0';

  177.                 LCD_Show_String(1,0,BUFF);//在第1行顯示
  178.         }
  179. }
復(fù)制代碼


六、思考題回答
1A/DD/A中的DA是什么意思,A/DD/A分別有什么作用?
What is the meaning of D and A in A/D or D/Awhat are the functions of A/D and D/A

Answer:A is analog , D is digital . A/D can change analog signals into digital signals . D/A can change digital signals into analog signals.


2C51程序中為什么要包含頭文件reg51.h
Why does the C51 program include the header file reg51.h

Answer:Because reg51.h has function declarations , variable declarations , if you want to use these functions or variables you have to include them.


51hei圖片20201213232517.jpg
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表