詳情見附件!
單片機源程序如下:
- #include "config.h"
- sbit DT = P0 ^ 7;
- sbit SCK = P0 ^ 6;
- #define DT_HIGH DT=1
- #define DT_LOW DT=0
- #define SCK_HIGH SCK=1
- #define SCK_LOW SCK=0
- unsigned long ReadCount(void)
- {
- unsigned long Count=0;
- unsigned char i;
- DT_HIGH;
- SCK_LOW; //使能AD
- while(DT); //AD轉換等待
- for (i=0;i<24;i++)
- {
- SCK_HIGH; //put down SCK 置高(發送脈沖)
- Count = Count << 1; //下降沿來時變量count左移一位
- SCK_LOW ; //PD SSCK 置低
- if(DT) Count++;
- }
- SCK_HIGH;
- Count = Count ^ 0x800000; //第25個脈沖下降沿來時,轉換數據
- SCK_LOW ;
-
- return(Count);
- }
復制代碼- #include "config.h"
- void main()
- {
- float Date ;
- UartInit() ;
- while(1)
- {
-
- Date = ReadCount() ;
-
- Date = (unsigned int)((float)Date/4.35+0.05);
- UART_SendStr("The press is ") ;
- UART_SendStrNum(Date);
- }
-
- }
復制代碼
以上程序51hei提供下載:
壓力傳感器檢測是否有杯子放入.zip
(46.92 KB, 下載次數: 9)
2021-6-11 15:57 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
需要 stc15頭文件才能編譯http://www.zg4o1577.cn/bbs/dpj-117121-1.html
|