#include
#define uint unsigned int
#define uchar unsigned char
/************DS18B20**********/
sbit DQ=P3^7;
uchar temph=0,templ=0;
uint t=0;
float tt=0;
void delay_b20(uint z)//ds18b20 delay
{
while(z--);
}
void b20_reset(void)//ds18b20复位
{
uchar ready=0;
DQ=1;
delay_b20(8);
DQ=0;
delay_b20(80);
DQ=1;
delay_b20(14);
ready=DQ;
delay_b20(20);
}
/*uchar b20_r_bit(void)//读ds18b201Bit
{
uchar i;
DQ=0;
DQ=1;
for(i=0;i<3;i++);
return(DQ);
}
void b20_w_bit(uchar bitval)//写ds18b201Bit
{
DQ=0;
if(bitval==1)
DQ=1;
delay_b20(5);
DQ=1;
}
void b20_w_byte(uchar val)//write one byte to ds18b20
{
uchar i,temp;
for(i=0;i<8;i++)
{
temp=val>>1;
temp=temp&0x01;
b20_w_bit(temp);
delay_b20(5);
}
}
uchar b20_r_byte(void)//读出ds18b20一字节
{
uchar i,j,date;
j=1;
date=0;
for(i=0;i<8;i++)
{
if(b20_r_bit())
{
date=date+(j<
}
delay_b20(4);
}
return(date);
}*/
uchar b20_r_byte(void)//read one byte from DS18B20
{
uchar i=0;
uchar dat=0;
for(i=0;i<8;i++)
{
DQ=0;
dat>>=1;
DQ=1;
if(DQ)
dat|=0x80;
delay_b20(4);
}
return(dat);
}
void b20_w_byte(uchar dat)//write DS18B20 one byte
{
uchar i=0;
for(i=0;i<8;i++)
{
DQ=0;
DQ=dat&0x01;
delay_b20(5);
DQ=1;
dat>>=1;
}
}
uint b20_gettemp(void)//获取DS18B20上温度
{
b20_reset();
b20_w_byte(0xcc);
b20_w_byte(0x44);
//delay_b20(125);
b20_reset();
b20_w_byte(0xcc);
b20_w_byte(0xbe);
templ=b20_r_byte();
temph=b20_r_byte();
t=temph;
t<<=8;
t=t|templ;
tt=t*0.0625;
t=tt*10+0.5;
//delay_b20(200);
return(t);
}
/*************LCD12864*************/
sbit beer=P2^0;
#define P0 P0
uchar code
uchar code
uchar code
uchar code
sbit lcd_rs=P1^0;//define LCD pins
sbit lcd_rw=P1^1;
sbit lcd_en=P1^2;
sbit lcd_psb=P2^4;
sbit lcd_rst=P2^3;
void delay(uint z) //延时
{
uint x,y;
for(x=110;x>0;x--);
for(y=z;y>0;y--);
}
void lcd_w_com(uchar com)//写命令
{
lcd_rs=0;
lcd_rw=0;
lcd_en=0;
P0=com;
delay(5);
lcd_en=1;
delay(5);
lcd_en=0;
}
void lcd_w_da
{
lcd_rs=1;
lcd_rw=0;
lcd_en=0;
P0=date;
delay(5);
lcd_en=1;
delay(5);
lcd_en=0;
}
void lcd_init()//LCD initialization
{
lcd_rst=0;
delay(10);
lcd_rst=1;
delay(10);
lcd_psb=1;
P3=0xff;
key5=1;
key6=1;
lcd_w_com(0x30);
lcd_w_com(0x0c);
lcd_w_com(0x14);
lcd_w_com(0x01);
}
void lcd_pos(uchar x,uchar y)//Select write position
{
uchar pos;
if(x==0)
{x=0x80;}
else if(x==1)
{x=0x90;}
else if(x==2)
{x=0x88;}
else if(x==3)
{x=0x98;}
pos=x+y;
lcd_w_com(pos);
}
void clr_screen()//清屏
{
lcd_w_com(0x34);
delay(5);
lcd_w_com(0x30);
delay(5);
lcd_w_com(0x01);
}
void disp_chinese(uchar co
{
while(*s>0)
{
lcd_w_da
s++;
delay(500);
}
}
void disp_temp()
{
uint i=0;
uchar a=0,b=0,c=0;
/*uint shi,ge,xiaoshu;
uchar a=0,b=0,c=0;
lcd_pos(3,3);
i=b20_gettemp();
shi=i/100;
ge=i/10%10;
xiaoshu=i%10;
lcd_pos(3,3);
lcd_w_data
lcd_w_data
lcd_w_data
lcd_w_data
disp_chinese("℃");*/
lcd_pos(3,3);
i=b20_gettemp();
a=i/100;
lcd_w_da
b=i/10-a*10;
lcd_w_da
lcd_w_da
c=i-a*100-b*10;
lcd_w_da
disp_chinese("℃");
}
void main()
{
lcd_init();
while(1)
{
disp_title();
disp_temp();
}
}
Previous article:DS1302 Test Procedure
Next article:AT89S52 keyboard program
Recommended ReadingLatest update time:2024-11-17 02:46
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Single-chip microcomputer technology and application - electronic circuit design, simulation and production (edited by Zhou Runjing)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- [Mil MYD-YA15XC-T Review] + USB UVC Camera Test
- Share: Several questions about the battery monitor bq76pl455a
- 【Repair】Fire emergency light fault inspection and repair
- Why is the maximum angle read by the resolver chip AD2S1210 only 180°?
- liunx configures static IP and changes ens33 network card to eth0
- "Practice Together in 2021" + An Ordinary Year
- Giant Digital Caliper Clock
- FPGA learning and design considerations V.1.pdf
- After the imx6 fuse is modified, it cannot start and the debug serial port has no response. Is there any way to save it?
- TIOBE Index June 2022: C++ is about to surpass Java