锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

GY-39温湿度传感器

时间:2022-11-01 10:00:00 79传感器

当温度显示时,数字管数字显示不正确

#include

unsigned char recv_flag;

unsigned char send_flag;

unsigned char c;

unsigned char num;

unsigned chartable1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

unsigned chartable2[]={0xc6,0x89};

unsigned chartable3[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};

unsigned chartable4[];

unsignedchar buf[15];

void dingshi(void)

{

TH0=(65536-50000)/256;

TL0=(65536-50000)%6;

EA=1;

ET0=1;

TR0=1;

count ;

if(count==20)

{

count=0;

}

}

void delay(int n)

{

int i,j;

for(i=n;i>0;i--)

for(j=114;j>0;j--);

}

void uart_init()

{

// 第一步:产生波特率配置

// 1、定时器T1的工作方式2

TMOD = 0x20;

// 2、装初值:

TH1= TL1= 0xFD;///一般使用96000

// 3.启动定时器

TR1 = 1;

// 第二步:确定串口的工作方式

SM0 = 0;

SM1 = 1;

REN = 1;

//或者用以上三句话代替 SCON = 0x50;

// 第三步:打开总中断

EA = 1;

// 第四步:打开串口中断:

ES = 1;

}

void send_char(char c)

{

SBUF = c;

while(!TI);

TI = 0;

}

void main()

{ float w,s;

uart_init();

while(1)

{

if(recv_flag == 1)

{

recv_flag = 0;

w=(buf[4]<<8)|buf[5];

s=(buf[10]<<8)|buf[11];

ES = 1;

}

P1=0xf7;

P0=table2[0];

delay(5);

P1 = 0xfb;

P0=table1[(int)(w*100/1000)];

delay(5);

P1 = 0xfd;

P0=table3[(int)(w*100/100)];

delay(5);

P1 = 0xfe;

P0=table1[(int)(w*100/10)];

delay(5);

dingshi(1)

// P1=0xf7;

// P0=table2[1];

// delay(5);

// P1 = 0xfb;

// P0=table1[(int)(s*100/1000)];

// delay(5);

// P1 = 0xfd;

// P0=table3[(int)(s*100/100)];

// delay(5);

// P1 = 0xfe;

// P0=table1[(int)(s*100/10)];

// delay(5);

}

}

void UART_ISR(void) interrupt 4 using 2

{

buf[num ] = SBUF;

RI = 0;

if(num == 15)

{

recv_flag = 1;

num = 0;

ES = 0;

}

}

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章