|
詳情見(jiàn)附件!
單片機(jī)源程序如下:
- #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轉(zhuǎn)換等待
- for (i=0;i<24;i++)
- {
- SCK_HIGH; //put down SCK 置高(發(fā)送脈沖)
- Count = Count << 1; //下降沿來(lái)時(shí)變量count左移一位
- SCK_LOW ; //PD SSCK 置低
- if(DT) Count++;
- }
- SCK_HIGH;
- Count = Count ^ 0x800000; //第25個(gè)脈沖下降沿來(lái)時(shí),轉(zhuǎn)換數(shù)據(jù)
- SCK_LOW ;
-
- return(Count);
- }
復(fù)制代碼- #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);
- }
-
- }
復(fù)制代碼
以上程序51hei提供下載:
壓力傳感器檢測(cè)是否有杯子放入.zip
(46.92 KB, 下載次數(shù): 9)
2021-6-11 15:57 上傳
點(diǎn)擊文件名下載附件
需要 stc15頭文件才能編譯http://m.zg4o1577.cn/bbs/dpj-117121-1.html
|
|