標(biāo)題: 用單片機(jī)制作自動(dòng)配藥系統(tǒng) 源程序Proteus仿真圖 [打印本頁]

作者: 133456789    時(shí)間: 2022-4-14 13:38
標(biāo)題: 用單片機(jī)制作自動(dòng)配藥系統(tǒng) 源程序Proteus仿真圖
自動(dòng)配藥系統(tǒng)設(shè)計(jì),設(shè)置配置比例和總藥量,自動(dòng)配藥
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #define uint unsigned int
  2. #define uchar unsigned char
  3. #include "Lcd1602.h"
  4. #include <intrins.h>
  5. #include "math.h"
  6. #define delay4us() {_nop_();_nop_();_nop_();_nop_();}//格式

  7. int P_Air,P_Water,H_Water;
  8. int Err,Err_L;
  9. sbit CS  = P1^5;
  10. sbit CLK = P1^6;
  11. sbit DIO = P1^7;//        DI和DO并聯(lián)接入P1^2;

  12. void display() ;

  13. uchar Get_AD_Result_ch2(unsigned char num) //得到 雙通道U5 ad采集的電壓
  14. {
  15.          uchar i,dat1=0,dat2=0;
  16.         CS  = 0; CLK = 0;DIO = 1; _nop_(); _nop_();
  17.         CLK = 1; _nop_(); _nop_(); CLK = 0;                         //準(zhǔn)備

  18.         CLK = 1; _nop_(); _nop_();CLK = 0;                 //開始          核實(shí)準(zhǔn)備工作
  19.         DIO = num; _nop_(); _nop_();CLK = 1;              //上升沿傳地地址的低位
  20.         DIO = num; _nop_(); _nop_();CLK = 0;                    //下降沿傳地地址的高位
  21.         DIO = 1; _nop_(); _nop_();                                   //準(zhǔn)備傳輸數(shù)據(jù)
  22.         for(i=0;i<8;i++)
  23.         {   
  24.             dat1 = dat1 | DIO;
  25.                  CLK = 1; _nop_(); _nop_();
  26.                 CLK = 0; _nop_(); _nop_();
  27.                
  28.                 dat1 = dat1 << 1 ;
  29.               
  30.         }
  31.         CS = 1;
  32.         return dat1;
  33. }
  34. void Get_Info()
  35. {
  36.         uchar temp;
  37.         temp = Get_AD_Result_ch2(0);//采集氣壓
  38.         P_Air = (uchar)(temp/5);
  39. }
  40. /*******************************************************************************
  41. * 函 數(shù) 名         : main
  42. * 函數(shù)功能                   : 主函數(shù)
  43. * 輸    入         : 無
  44. * 輸    出         : 無
  45. *******************************************************************************/
  46. void main(void)
  47. {  
  48.         InitLcd1602();
  49.         while(P_Water<=1)
  50.         {
  51.                 Get_Info();//得到采集數(shù)據(jù)
  52.                 display();//數(shù)據(jù)顯示                        
  53.         }

  54.         while(1)
  55.         {
  56.                 Get_Info();//得到采集數(shù)據(jù)
  57.                 display();//數(shù)據(jù)顯示
  58.         }                                
  59. }

  60. void display()      //lcd顯示提示信息以及測(cè)到的數(shù)據(jù)
  61. {
  62. unsigned char shu[8],shu1[8],shu2[8];
  63. shu[0]='R';               
  64.         shu[1]=':';        
  65. shu[2]=P_Air/1000+0x30;     //取百位 加0x30是為了轉(zhuǎn)化成字符型
  66. shu[3]='.';     //取百位 加0x30是為了轉(zhuǎn)化成字符型
  67. shu[4]=(P_Air-(shu[2]-0x30)*1000)/100+0x30;   //取十位
  68. shu[5]=((P_Air-(shu[2]-0x30)*1000)-100*(shu[4]-0x30))/10+0x30;      //取個(gè)位(下同)
  69. shu[6] =P_Air%10+0x30 ;
  70. shu[7]=' '        ;
  71. shu[8]='\0';

  72. LcdShowStr(0,0,shu);
  73. }
復(fù)制代碼
Keil代碼與Proteus仿真下載:
本人初學(xué),僅供參考,存在錯(cuò)誤和不足之處,請(qǐng)大家回帖多多指教,切勿照搬,文件下載:
仿真代碼.7z (102.98 KB, 下載次數(shù): 35)







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