標(biāo)題: 基于單片機(jī)的智能飲水機(jī)的壓力模塊程序 [打印本頁]

作者: wiselee    時(shí)間: 2021-6-11 15:57
標(biāo)題: 基于單片機(jī)的智能飲水機(jī)的壓力模塊程序
詳情見附件!

單片機(jī)源程序如下:
  1. #include "config.h"
  2. sbit DT  = P0 ^ 7;
  3. sbit SCK = P0 ^ 6;
  4. #define  DT_HIGH  DT=1
  5. #define  DT_LOW   DT=0
  6. #define  SCK_HIGH SCK=1
  7. #define  SCK_LOW  SCK=0
  8. unsigned long ReadCount(void)
  9. {
  10.         unsigned long Count=0;
  11.         unsigned char i;
  12.         DT_HIGH;
  13.         SCK_LOW;                  //使能AD
  14.         while(DT);               //AD轉(zhuǎn)換等待
  15.         for (i=0;i<24;i++)
  16.         {
  17.                 SCK_HIGH;                                              //put down SCK 置高(發(fā)送脈沖)
  18.                 Count = Count << 1;     //下降沿來時(shí)變量count左移一位
  19.                 SCK_LOW   ;           //PD SSCK  置低
  20.     if(DT)  Count++;                       
  21.         }
  22.    SCK_HIGH;
  23.          Count = Count ^ 0x800000;  //第25個(gè)脈沖下降沿來時(shí),轉(zhuǎn)換數(shù)據(jù)
  24.    SCK_LOW ;
  25.        
  26.          return(Count);
  27. }
復(fù)制代碼
  1. #include "config.h"



  2. void main()
  3. {  
  4.         float Date ;
  5.         UartInit()        ;
  6.         while(1)
  7.         {       
  8.                
  9.           Date = ReadCount() ;       
  10.        
  11.                 Date = (unsigned int)((float)Date/4.35+0.05);       
  12.                 UART_SendStr("The press is    ") ;
  13.           UART_SendStrNum(Date);

  14.         }
  15.        
  16. }


復(fù)制代碼

以上程序51hei提供下載:
壓力傳感器檢測(cè)是否有杯子放入.zip (46.92 KB, 下載次數(shù): 9)

需要 stc15頭文件才能編譯http://www.torrancerestoration.com/bbs/dpj-117121-1.html


作者: 51hei團(tuán)團(tuán)    時(shí)間: 2021-6-11 16:34
么有原理圖啊 原理圖能分享一下嗎?




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