PHP安卓获取gpgga,这个单片机程序中 感觉GPS的 GPGGA这条信息没有被保存

#include

#include "pcf8574lcd.h"

unsigned char RX_Buffer[68];                //此数组用于直接储存来自GPS的原始数据,

unsigned char RX_Count = 0;     //

bit Flag_GPS_OK = 0;

extern bit Flag_GPS_OK;

unsigned char xdata Display_GPGGA_Buffer[68]={0};                //用于储存GPGGA的数据

unsigned char xdata Display_GPRMC_Buffer[68]={0};                //用于储存GPRMC的数据

unsigned int k=0,qian_a=0,hou_a=0,qian_b=0,hou_b=0,qian_c=0,hou_c=0;        //存储前后逗号的位置序号的变量

bit qian_OK=0;                   //已找出前面的逗号的标志变量

bit First_Share_OK=0;  //已开始LCD显示的标志变量

bit jiajian=1;                    //进行加或减的标志变量

bit Flag_Calc_GPGGA_OK = 0;           //GPGGA完整有效的数据已收到的标志变量

bit Flag_Calc_GPRMC_OK = 0;           //GPRMC完整有效的数据已收到的标志变量

//*****************************************************************************

void GPSUart_Init()                        //  GPS串口初始化

{

//    针对的是 STC89C52的,但是发现STC12C5A60S2单片机也可以用 ,同样都是11.0592的晶振。

SCON = 0X50;  //UART方式1;8位UART

REN  = 1;     //允许串行口接收数据

PCON = 0x00;  //SMOD=0;波特率不加倍   9600

TMOD = 0x20;  //T1方式2,用于产生波特率

TH1  = 0xFD;  //装初值

TL1  = 0xFD;

TR1  = 1;     //启动定时器1

EA   = 1;     //打开全局中断控制

ES   = 1;     //打开串行口中断

}

//-----------------------------------------------------------------

void RECEIVE_DATA(void) interrupt 4 using 3                  //串口中断函数,收到GPS的数据时进入此中断

{

unsigned char temp = 0;

ES=0;                                                                                    //先关闭串行口中断

temp = SBUF;                                                                //接收SBUF中的数据

RI = 0;                                                                                  //接收完成的标志位清零

if(temp == '

)                                                                //若是统一的数据头,则作为数组第一个元素

{

RX_Count = 0;

Flag_GPS_OK = 0;

}

RX_Buffer[RX_Count++] = temp;                                //收到的数据放到数组中

if(RX_Count >= 66)                                                        //序号大于66的数据无用,统一放到第66位覆盖掉

{

RX_Count = 66;

}

if(temp == '*')                                                                //收到*,则完成一帧数据的接收,不管是否完整有效

{

Flag_GPS_OK = 1;                         //标志变量置为1

}

ES=1;                                                                                 //重新打开串行口中断

}

//----------------------------------------------------------------------------------

/********************************************************/

void Delay1s(uchar A)                //  1秒,主要用来做欢迎词延时,STC12系列专用

{

while(A--)

{

unsigned char i, j, k;

i = 43;

j = 6;

k = 203;

do

{

do

{

while (--k);

} while (--j);

} while (--i);

}

}

/*******************************************************************************

* 函 数 名         : datapros()

* 函数功能                   : 温度读取处理转换函数

* 输    入         : temp

* 输    出         : 无

*******************************************************************************/

void datapros(int temp)    // 车外温度考虑零下温度

{

float tp;

//tp=temp;

//temp=tp*0.0625*100+0.5;

//temp=tp/16*100;//+0.5;        //尽量避免浮点型运算//留两个小数点就*100,+0.5是四舍五入,因为C语言浮点数转换为整型的时候把小数点

//后面的数自动去掉,不管是否大于0.5,而+0.5之后大于0.5的就是进1了,小于0.5的就

//算加上0.5,还是在小数点后面。

if(temp< 0)                                           //当温度值为负数

{

DisplayOneChar(2,1,'-');  //因为读取的温度是实际温度的补码,所以减1,再取反求出原码

temp=temp-1;

temp=~temp;

tp=temp;

temp=tp*0.0625*100+0.5;

//留两个小数点就*100,+0.5是四舍五入,因为C语言浮点数转换为整型的时候把小数点

//后面的数自动去掉,不管是否大于0.5,而+0.5之后大于0.5的就是进1了,小于0.5的就

//算加上0.5,还是在小数点后面。

}

else

{

DisplayOneChar(2,1,' ');

tp=temp;                   //因为数据处理有小数点所以将温度赋给一个浮点型变量

//如果温度是正的那么,那么正数的原码就是补码它本身

temp=tp*0.0625*100+0.5;

//留两个小数点就*100,+0.5是四舍五入,因为C语言浮点数转换为整型的时候把小数点

//后面的数自动去掉,不管是否大于0.5,而+0.5之后大于0.5的就是进1了,小于0.5的就

//算加上0.5,还是在小数点后面。

}

if(temp/10000 ==0)  DisplayOneChar(2,1,(temp/10000)+' ');      //假如温度百位等于0就不在显示

else DisplayOneChar(2,1,(temp/10000)+'0');                     // 百位

DisplayOneChar(3,1,(temp%10000)/1000+'0');   // 十位

DisplayOneChar(4,1,(temp%1000/100)+'0');     // 个位

DisplayOneChar(6,1,(temp%100/10)+'0');       // 小数点后 1 位

//DisplayOneChar(7,1,(temp%10)+'0');           // 小数点后 2 位

}

/

void dataprosN(int temp)          // 车内温度不考虑零下

{

float tp;

tp=temp;//temp=tp*0.0625*100+0.5;

temp=tp/16*100;//+0.5;        //尽量避免浮点型运算//留两个小数点就*100,+0.5是四舍五入,因为C语言浮点数转换为整型的时候把小数点

//后面的数自动去掉,不管是否大于0.5,而+0.5之后大于0.5的就是进1了,小于0.5的就

//算加上0.5,还是在小数点后面。

if(temp/10000 ==0)  DisplayOneChar(2,0,(temp/10000)+' ');      //假如温度百位等于0就不在显示

else DisplayOneChar(2,0,(temp/10000)+'0');                     // 百位

DisplayOneChar(3,0,(temp%10000)/1000+'0');                     // 十位

DisplayOneChar(4,0,(temp%1000/100)+'0');                       // 个位

DisplayOneChar(6,0,(temp%100/10)+'0');                         // 小数点后 1 位

//DisplayOneChar(7,0,(temp%10)+'0');                             // 小数点后 2 位

}

//

void dataprosS(int temp)          // 水温度不考虑零下

{

float tp;

tp=temp;//temp=tp*0.0625*100+0.5;

temp=tp/16*100;//+0.5;        //尽量避免浮点型运算//留两个小数点就*100,+0.5是四舍五入,因为C语言浮点数转换为整型的时候把小数点

//后面的数自动去掉,不管是否大于0.5,而+0.5之后大于0.5的就是进1了,小于0.5的就

//算加上0.5,还是在小数点后面。

if(temp/10000 ==0)  DisplayOneChar(11,1,(temp/10000)+' ');      //假如温度百位等于0就不在显示

else DisplayOneChar(11,1,(temp/10000)+'0');                     // 百位

DisplayOneChar(12,1,(temp%10000)/1000+'0');   // 十位

DisplayOneChar(13,1,(temp%1000/100)+'0');     // 个位

DisplayOneChar(15,1,(temp%100/10)+'0');       // 小数点后 1 位

//DisplayOneChar(7,1,(temp%10)+'0');           // 小数点后 2 位

}

//*********************************   主函数   ******************************************************

void main()

{

unsigned int i = 0;

Init_Lcd();        //  初始化1602液晶显示器

GPSUart_Init();

Write_LCD(0,0,"   Good  Luck   ");

Write_LCD(0,1,"Happy  ever  day");

Delay1s(1);    //延时3S

LCD_write_command(0x01);  //  清屏

while(1)

{

unsigned int a;

//------------------------------第一屏:显示温度----------------------

for(a=15;a;a--)      //保持温度采样显示 7秒 左右(大概2.2倍秒的关系)

{ Write_LCD(0,0,"n:");

Write_LCD(5,0,".");

Write_LCD(8,0,"H:");

Write_LCD(0,1,"w:");

Write_LCD(5,1,".");

Write_LCD(8,1,"S:");

Write_LCD(14,1,".");

datapros(Ds18b20ReadTemp());         //数据处理函数

dataprosN(Ds18b20ReadTempN());         //数据处理函数

dataprosS(Ds18b20ReadTempS());         //数据处理函数

}

LCD_write_command(0x01);  //  清屏

//---------------------------- 第二屏:测试用 ------------------------------------------

for(a=15;a;a--)      //保持屏幕 5秒 左右(大概10倍秒的关系)

{

Write_LCD(0,0,"Let's go.....");        // 用做测试第二屏显示

}

LCD_write_command(0x01);  //  清屏

//-----------------------------------------------------------------------------------------------------

//---------------------------- 第三屏:处理GPS 显示海拔、速度 ------------------------------------------

//-----------------------------------------------------------------------------------------------------

Write_LCD(0,0,"BBBBBB.....");        // 测试用

Delay1s(1);    //延时3S

LCD_write_command(0x01);  //  清屏

qian_OK=0;                                                                        //标志变量归零

k=0;                                                                                    //累计量归零

if (   Flag_GPS_OK  == 1

&& RX_Buffer[1] == 'G'

&& RX_Buffer[3] == 'G'

&& RX_Buffer[4] == 'G'

&& RX_Buffer[5] == 'A'

&& (RX_Buffer[28] == 'N'|| RX_Buffer[28] == 'S')

&& (RX_Buffer[41] == 'E'|| RX_Buffer[41] == 'W') )                //确认是否收到"GPGGA"这一帧完整有效的数据

{

for( i = 0; i < 67 ; i++)                                                                //必须为i<67,因为要确保Display_GPGGA_Buffer[67]为'\0',便于串口发送

{

Display_GPGGA_Buffer[i] = RX_Buffer[i];                      //储存到数组中

}

Flag_Calc_GPGGA_OK = 1;                                                                        //收到完整有效数据后,置为1

}

LCD_write_command(0x85);

LCD_write_data(RX_Buffer[45]);        // 测试用,有每一帧的  第45 位的数据,

LCD_write_command(0x88);

LCD_write_data(Display_GPGGA_Buffer[2]);           //   没数据

Delay1s(1);    //延时3S

LCD_write_command(0x01);  //  清屏

Write_LCD(0,0,"VVVVVV.....");

Delay1s(1);    //延时3S

}

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/****************************************************************************************************************

*****************************************************************************************************************/

#include "pcf8574lcd.h"

char ADDR = 0x4E;    // PCF8574T  模块的地址码

//***************************** 延时 XX  ms ***********************************************

void delay(int y)

{

;

while(y--)

{

unsigned char a,b,c;

for(c=1;c>0;c--)

for(b=142;b>0;b--)

for(a=2;a>0;a--);

}

}

/***************************** 这是从其他地方移植过来的 *********************

void delay(int ms)

{

unsigned char y ;

while(ms--)

{

for(y = 0 ; y<250 ; y++)     //  这是从其他地方移植过来的

{

_nop_() ;

_nop_() ;

_nop_() ;

_nop_() ;

}

}

}

*************************************************************************************/

//******************************** IIC 串口开始 ********************************************

void IIC_start(void)

{

SDA=1;

_nop_();

SCL=1;

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

SDA=0;

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

SCL=0;

}

//********************************* IIC 串口结束 *******************************************

void IIC_stop(void)

{

SDA=0;

_nop_();

SCL=1;

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

SDA=1;

_nop_();

_nop_();

_nop_();

_nop_();

}

//********************************** IIC 串口写1个字节 ******************************************

void IIC_writeByte(char temp)

{

char i;

for(i=0;i<8;i++)

{

SDA=(bit)(temp & 0x80) ;   // 根据规定1602的数据最高位必须为  1

temp <<=1;

_nop_();

_nop_();

SCL=1;

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

SCL=0;

}

_nop_();

_nop_();

_nop_();

_nop_();

SDA=1;

_nop_();

_nop_();

_nop_();

_nop_();

SCL=1;

_nop_();

_nop_();

_nop_();

while(SDA);

_nop_();

SCL=0;

}

//**************************************************************************************************************

//********************************************* 以下是对1602 的操作  ******************************************

//**************************************************************************************************************

//******************************** 1602写命令 ********************************************

void LCD_write_command(char comm)

{

char tmp;

IIC_start();          // 串口开始

IIC_writeByte(ADDR);  // 先选PCF 8574T 的地址  (应该是相当于选中的意思吧)

tmp = comm & 0xF0;    // 与0xf0 应该是取第四位的意思吧

tmp |= 0x0C;         //保留高4位为指令的高四位,低四位为   RS = 0, RW = 0, EN = 1

IIC_writeByte(tmp);  //从串口送出

delay(20);

tmp &= 0xFB;        //Make EN = 0

IIC_writeByte(tmp);

tmp = (comm & 0x0F) << 4 ;  //将指令的低四位 送到高位置保存

tmp |= 0x0C;        //RS = 0, RW = 0, EN = 1

IIC_writeByte(tmp);

delay(20);

tmp &= 0xFB; // Make EN = 0

IIC_writeByte(tmp);

//stop_8574();

}

//******************************** 1602写数据 ********************************************

void LCD_write_data(char data1)

{

char tmp;

IIC_start();

IIC_writeByte(ADDR);   // 先选PCF 8574T 的地址  (应该是相当于选中的意思吧)

tmp = data1 & 0xF0;

tmp |= 0x0D; //RS = 0, RW = 0, EN = 1

IIC_writeByte(tmp);

delay(20);

tmp &= 0xFB; //Make EN = 0

IIC_writeByte(tmp);

tmp = (data1 & 0x0F) << 4 ;

tmp |= 0x0D; //RS = 0, RW = 0, EN = 1

IIC_writeByte(tmp);

delay(20);

tmp &= 0xFB ; // Make EN = 0

IIC_writeByte(tmp);

}

//******************************** 1602初始化 ********************************************

void Init_Lcd(void)

{

LCD_write_command(0x33); //

delay(50) ;

LCD_write_command(0x32); //

delay(50) ;

LCD_write_command(0x28); // 4位数据线,显示2行,5*7点阵字符  !如果是0x38  则为8位数据线,显示2行,5*7点阵字符

delay(50) ;

LCD_write_command(0x0C); // 开显示,关闭光标,不闪烁

delay(50) ;

LCD_write_command(0x06); // 设定输入方式,增量不位移

delay(50) ;

LCD_write_command(0x01); // 清屏

delay(50) ;

}

//********************************** 1602清屏 ******************************************

void Clear_Lcd(void)

{

LCD_write_command(0x01);

}

//****************************************************************************

void Write_LCD(int x, int y, char *str)   //显示字符串的函数

{

char addr;

if( x < 0)

{

x = 0;

}

if(x > 15)

{

x = 15;

}

if(y<0)

{

y = 0;

}

if(y > 1)

{

y = 1;

}

addr = 0x80 + 0x40 * y + x;   // Move cursor  移动光标

LCD_write_command(addr);

while (*str)

{

LCD_write_data(*str++);

}

}

//****************************************************************************

//按指定位置显示一个字符

void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)

{

Y &= 0x1;

X &= 0xF; //限制X不能大于15,Y不能大于1

if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;

X |= 0x80; // 算出指令码

LCD_write_command(X); //这里不检测忙信号,发送地址码

LCD_write_data(DData);

}

//*****************************************************************************************************************************************************************************************************

//********************************************* 以下是对18b20 的操作  **********************************************************************************************************************************

//*****************************************************************************************************************************************************************************************************

/*******************************************************************************

* 函 数 名         : Delay1ms

* 函数功能                       : 延时函数

* 输    入         : 无

* 输    出         : 无

*******************************************************************************/

void Delay1ms(uint y) //误差 0us  STC12系列专用

{

while(y--)

{

unsigned char a,b,c;

for(c=1;c>0;c--)

for(b=142;b>0;b--)

for(a=2;a>0;a--);

}

}

void delay_us(uchar x)      //延时 X  us    STC12系列专用

{uchar i;

for(i=0;i

}

void delay_1us()            //延时 1 us

{

uchar i;

for(i=0;i<1;i++);

}

/*******************************************************************************

* 函 数 名         : Ds18b20Init

* 函数功能                                   : 初始化

* 输    入         : 无

* 输    出         : 初始化成功返回1,失败返回0

*******************************************************************************/

uchar Ds18b20Init()

{

bit flag;

DSPORT = 1;

delay_1us();

DSPORT = 0;

delay_us(255);    //将总线拉低480us~960us

DSPORT = 1;                        //然后拉高总线,如果DS18B20做出反应会将在15us~60us后总线拉低

delay_us(30);   //等待15-60微秒,18b20作出回应

flag=DSPORT;    //检测是否为低电平

delay_us(255);

delay_us(255);  //延时足够长,最少480us,完成复位周期

return (flag);

}

uchar Ds18b20InitN()

{

bit flag;

DSPORTN = 1;

delay_1us();

DSPORTN = 0;

delay_us(255);    //将总线拉低480us~960us

DSPORTN = 1;                        //然后拉高总线,如果DS18B20做出反应会将在15us~60us后总线拉低

delay_us(30);   //等待15-60微秒,18b20作出回应

flag=DSPORTN;    //检测是否为低电平

delay_us(255);

delay_us(255);  //延时足够长,最少480us,完成复位周期

return (flag);

}

uchar Ds18b20InitS()

{

bit flag;

DSPORTS = 1;

delay_1us();

DSPORTS = 0;

delay_us(255);    //将总线拉低480us~960us

DSPORTS = 1;                        //然后拉高总线,如果DS18B20做出反应会将在15us~60us后总线拉低

delay_us(30);   //等待15-60微秒,18b20作出回应

flag=DSPORTS;    //检测是否为低电平

delay_us(255);

delay_us(255);  //延时足够长,最少480us,完成复位周期

return (flag);

}

/*******************************************************************************

* 函 数 名         : Ds18b20WriteByte

* 函数功能                      : 向18B20写入一个字节

* 输    入         : 无

* 输    出         : 无

*******************************************************************************/

void Ds18b20WriteByte(uchar dat)

{

uchar i;

for(i=0;i<8;i++)

{

DSPORT=1;

delay_1us();//稍作延时

DSPORT=0;//启动写时序

DSPORT=dat&0x01;//向数据线传送最低位

delay_us(40);//延时约50us,供18b20采样数据

DSPORT=1;//释放总线

delay_1us();

dat>>=1;//右移一位

}

delay_us(2);//写完一个指令稍作延时

}

void Ds18b20WriteByteN(uchar dat)

{

uchar i;

for(i=0;i<8;i++)

{

DSPORTN=1;

delay_1us();//稍作延时

DSPORTN=0;//启动写时序

DSPORTN=dat&0x01;//向数据线传送最低位

delay_us(40);//延时约50us,供18b20采样数据

DSPORTN=1;//释放总线

delay_1us();

dat>>=1;//右移一位

}

delay_us(2);//写完一个指令稍作延时

}

void Ds18b20WriteByteS(uchar dat)

{

uchar i;

for(i=0;i<8;i++)

{

DSPORTS=1;

delay_1us();//稍作延时

DSPORTS=0;//启动写时序

DSPORTS=dat&0x01;//向数据线传送最低位

delay_us(40);//延时约50us,供18b20采样数据

DSPORTS=1;//释放总线

delay_1us();

dat>>=1;//右移一位

}

delay_us(2);//写完一个指令稍作延时

}

/*******************************************************************************

* 函 数 名         : Ds18b20ReadByte

* 函数功能                                    : 读取一个字节

* 输    入         : 无

* 输    出         : 无

*******************************************************************************/

uchar Ds18b20ReadByte()

{

uchar i=0,dat;

for(i=0;i<8;i++)

{

DSPORT=1;//先拉高

delay_1us();//稍作延时

DSPORT=0;//启动读时序

delay_1us();//稍作延时

DSPORT=1;//释放总线

delay_us(6);//延时7us,主机采样

dat>>=1;//先右移一位,使最高位为0

if(DSPORT==1)

dat|=0x80;//与10000000或,dat=10000000

else

dat|=0x00;//取值为0

delay_us(50);

}

return(dat);

}

uchar Ds18b20ReadByteN()

{

uchar i=0,dat;

for(i=0;i<8;i++)

{

DSPORTN=1;//先拉高

delay_1us();//稍作延时

DSPORTN=0;//启动读时序

delay_1us();//稍作延时

DSPORTN=1;//释放总线

delay_us(6);//延时7us,主机采样

dat>>=1;//先右移一位,使最高位为0

if(DSPORTN==1)

dat|=0x80;//与10000000或,dat=10000000

else

dat|=0x00;//取值为0

delay_us(50);

}

return(dat);

}

uchar Ds18b20ReadByteS()

{

uchar i=0,dat;

for(i=0;i<8;i++)

{

DSPORTS=1;//先拉高

delay_1us();//稍作延时

DSPORTS=0;//启动读时序

delay_1us();//稍作延时

DSPORTS=1;//释放总线

delay_us(6);//延时7us,主机采样

dat>>=1;//先右移一位,使最高位为0

if(DSPORTS==1)

dat|=0x80;//与10000000或,dat=10000000

else

dat|=0x00;//取值为0

delay_us(50);

}

return(dat);

}

/*******************************************************************************

* 函 数 名         : Ds18b20ChangTemp

* 函数功能                       : 让18b20开始转换温度

* 输    入         : 无

* 输    出         : 无

*******************************************************************************/

void  Ds18b20ChangTemp()

{

Ds18b20Init();

Delay1ms(1);

Ds18b20WriteByte(0xcc);                //跳过ROM操作命令

Ds18b20WriteByte(0x44);            //温度转换命令

//Delay1ms(100);        //等待转换成功,而如果你是一直刷着的话,就不用这个延时了

}

void  Ds18b20ChangTempN()

{

Ds18b20InitN();

Delay1ms(1);

Ds18b20WriteByteN(0xcc);                //跳过ROM操作命令

Ds18b20WriteByteN(0x44);            //温度转换命令

//Delay1ms(100);        //等待转换成功,而如果你是一直刷着的话,就不用这个延时了

}

void  Ds18b20ChangTempS()

{

Ds18b20InitS();

Delay1ms(1);

Ds18b20WriteByteS(0xcc);                //跳过ROM操作命令

Ds18b20WriteByteS(0x44);            //温度转换命令

//Delay1ms(100);        //等待转换成功,而如果你是一直刷着的话,就不用这个延时了

}

/*******************************************************************************

* 函 数 名         : Ds18b20ReadTempCom

* 函数功能                       : 发送读取温度命令

* 输    入         : 无

* 输    出         : 无

*******************************************************************************/

void  Ds18b20ReadTempCom()

{

Ds18b20Init();

Delay1ms(1);

Ds18b20WriteByte(0xcc);         //跳过ROM操作命令

Ds18b20WriteByte(0xbe);         //发送读取温度命令

}

void  Ds18b20ReadTempComN()

{

Ds18b20InitN();

Delay1ms(1);

Ds18b20WriteByteN(0xcc);         //跳过ROM操作命令

Ds18b20WriteByteN(0xbe);         //发送读取温度命令

}

void  Ds18b20ReadTempComS()

{

Ds18b20InitS();

Delay1ms(1);

Ds18b20WriteByteS(0xcc);         //跳过ROM操作命令

Ds18b20WriteByteS(0xbe);         //发送读取温度命令

}

/*******************************************************************************

* 函 数 名         : Ds18b20ReadTemp

* 函数功能                       : 读取温度

* 输    入         : 无

* 输    出         : 无

*******************************************************************************/

int Ds18b20ReadTemp()

{

int temp = 0;

uchar tmh, tml;

Ds18b20ChangTemp();                                 //先写入转换命令

Ds18b20ReadTempCom();                        //然后等待转换完后发送读取温度命令

tml = Ds18b20ReadByte();                //读取温度值共16位,先读低字节

tmh = Ds18b20ReadByte();                //再读高字节

temp = tmh;

temp <<= 8;

temp |= tml;

return temp;

}

int Ds18b20ReadTempN()

{

int temp = 0;

uchar tmh, tml;

Ds18b20ChangTempN();                                 //先写入转换命令

Ds18b20ReadTempComN();                        //然后等待转换完后发送读取温度命令

tml = Ds18b20ReadByteN();                //读取温度值共16位,先读低字节

tmh = Ds18b20ReadByteN();                //再读高字节

temp = tmh;

temp <<= 8;

temp |= tml;

return temp;

}

int Ds18b20ReadTempS()

{

int temp = 0;

uchar tmh, tml;

Ds18b20ChangTempS();                                 //先写入转换命令

Ds18b20ReadTempComS();                        //然后等待转换完后发送读取温度命令

tml = Ds18b20ReadByteS();                //读取温度值共16位,先读低字节

tmh = Ds18b20ReadByteS();                //再读高字节

temp = tmh;

temp <<= 8;

temp |= tml;

return temp;

}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------

#ifndef __PCF8574LCD_H__

#define __PCF8574LCD_H__

#include

#include "intrins.h"

#define uchar unsigned char

#define uint unsigned int

sbit SCL = P1^0;

sbit SDA = P1^1;

void delay(int ms);    //   延时 XX  ms

void IIC_start(void);  //   IIC 串口开始

void IIC_stop(void);   //   IIC 串口结束

void IIC_writeByte(char temp);      //    IIC 串口写1个字节

void LCD_write_command(char comm);  //   1602写命令

void LCD_write_data(char data1);    //   1602写数据

void Init_Lcd(void);                //   1602初始化

void Clear_Lcd(void);               //   1602清屏

void Write_LCD(int x, int y, char *str);   //  显示字符串(小张写的)

void Write_Customer(int x, int y, char str[]);

void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);  //按指定位置显示一个字符

//**************** 18B20*************************************************

//--定义使用的IO口--//

sbit DSPORT=P2^1;   // 车外温度接口

//--声明全局函数--//

void Delay1ms(uint );

uchar Ds18b20Init();

void Ds18b20WriteByte(uchar com);

uchar Ds18b20ReadByte();

void  Ds18b20ChangTemp();

void  Ds18b20ReadTempCom();

int Ds18b20ReadTemp();

sbit DSPORTN=P2^2;   // 车内温度接口

//--声明全局函数--//

uchar Ds18b20InitN();

void  Ds18b20WriteByteN(uchar com);

uchar Ds18b20ReadByteN();

void  Ds18b20ChangTempN();

void  Ds18b20ReadTempComN();

int Ds18b20ReadTempN();

sbit DSPORTS=P2^3;   // 水温度接口

//--声明全局函数--//

uchar Ds18b20InitS();

void Ds18b20WriteByteS(uchar com);

uchar Ds18b20ReadByteS();

void  Ds18b20ChangTempS();

void  Ds18b20ReadTempComS();

int Ds18b20ReadTempS();

//****************************************

#endif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值