标题: 基于单片机的智能饮水机的压力模块程序 [打印本页]

作者: wiselee    时间: 2021-6-11 15:57
标题: 基于单片机的智能饮水机的压力模块程序
详情见附件!

单片机源程序如下:
  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转换等待
  15.         for (i=0;i<24;i++)
  16.         {
  17.                 SCK_HIGH;                                              //put down SCK 置高(发送脉冲)
  18.                 Count = Count << 1;     //下降沿来时变量count左移一位
  19.                 SCK_LOW   ;           //PD SSCK  置低
  20.     if(DT)  Count++;                       
  21.         }
  22.    SCK_HIGH;
  23.          Count = Count ^ 0x800000;  //第25个脉冲下降沿来时,转换数据
  24.    SCK_LOW ;
  25.        
  26.          return(Count);
  27. }
复制代码
  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. }


复制代码

以上程序51hei提供下载:
压力传感器检测是否有杯子放入.zip (46.92 KB, 下载次数: 9)

需要 stc15头文件才能编译http://www.51hei.com/bbs/dpj-117121-1.html


作者: 51hei团团    时间: 2021-6-11 16:34
么有原理图啊 原理图能分享一下吗?




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1