一款液晶顯示的超聲波測距板
源程序:
#include "stdio.h"
#include "math.h"
#include "regx52.h"
#include "binary.h"
#include "intrins.h"
#define VOUT P3_7 //脈沖產生端口
#define DQ P1_0 //ds18b20端口
/******************系統全局變量***************/
typedef unsigned char uchar;
typedef unsigned int uint;
bit Success; //測量成功標志位
bit Done; //測量完成標志位
bit Mode; //測量模式:0--近距離,1---遠距離
uint nCount;
uint nResult;
/******************18B20相關函數及變量***************/
bit SignedFlag=0; //符號標志位 ,負為1,正為0
uchar TempInt; //整數部分溫度
uint TempDot; //小數部分溫度
void ReadTemperature(void); //在程序中調用此函數
void Init_DS18B20(void);
unsigned char ReadOneChar(void);
void WriteOneChar(unsigned char dat);
void delayx(unsigned int i);
#include "18b20.h"
/******************LCD相關函數******************/
sbit SCLK = P2^0; // 串行時鐘
sbit SDIN = P2^1; // 串行數據輸入
sbit LCD_DC = P2^2; // 數據/命令 選擇端
sbit LCD_CE = P2^3; // 片選
sbit LCD_RST = P2^4; // 外部復位
#include "Nokia5110.c"
/***********超聲波測量相關函數定義***************/
void StartInit();
void Delay_us(uint i); //微秒級延時:T=7+2*(X-1) us
void StartMeasure();
void DisplayResult();
void ConvertCount();
void Delay_ms(uint x);
評論