#define uchar unsigned char
#define uint unsigned int
#define DQ RC1
#define DQ_HIGH() TRISC1=1
#define DQ_LOW() TRISC1=0;DQ=0
__CONFIG(0x3B31);
const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f};
const uchar table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
0x87,0xff,0xef};
uint temper;
uchar a1,a2,a3,a4;
void delay(uint x);
void delayus(uint,uchar);
void init();
void disp(uchar num1,uchar num2,uchar num3,uchar num4);
void write_byte(uchar date);
uchar read_byte();
void get_tem();
void main()
{
init();
while(1)
{
/* delayus(0,0);//20
delayus(1,1);//30
delayus(2,2);//45
delayus(4,4);//70
delayus(70,30);//750
delayus(50,10);//500*/
// uchar num;
get_tem();
// for(num=20;num>0;num--)
// disp(a1,a2,a3,a4);
}
}
void reset()
{
uchar st=1;
DQ_HIGH();
NOP();NOP();
while(st)
{
DQ_LOW();
delayus(70,30);
DQ_HIGH();
delayus(4,4);
if(DQ==1)
st=1;
else
st=0;
delayus(50,10);
}
}
void write_byte(uchar date)
{
uchar i,temp;
DQ_HIGH();
NOP();NOP();
for(i=8;i>0;i--)
{
temp=date&0x01;//01010101
DQ_LOW();
delayus(0,0);
if(temp==1)
DQ_HIGH();
delayus(2,2);
DQ_HIGH();
date=date>>1;//00101010
}
}
uchar read_byte()
{
uchar i,date;
static bit j;
for(i=8;i>0;i--)
{
date=date>>1;
DQ_HIGH();
NOP();NOP();
DQ_LOW();
NOP();NOP();NOP();NOP();NOP();NOP();
DQ_HIGH();
NOP();NOP();NOP();NOP();
j=DQ;
if(j==1)
date=date|0x80;//1000 0000
delayus(1,1);
}
return (date);
}
void get_tem()
{
uchar tem1,tem2,num;
float aaa;
reset(); //Reset
write_byte(0xCC); //Skip ROM
write_byte(0x44); //Temperature conversion
for(num=100;num>0 ;num--)
disp(a1,a2,a3,a4);
reset();
write_byte(0xCC);
write_byte(0xBE);
tem1=read_byte();
tem2=read_byte();
aaa=(tem2*256+tem1 )*6.25;
temper=(int)aaa;
a1=temper/1000;
a2=temper%1000/100;
a3=temper%100/10;
a4=temper%10;
}
void delayus(uint x,uchar y)
{
uint i;
uchar j;
for(i=x;i>0;i--);
for(j=y;j>0;j--);
}
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b> 0;b--);
}
void init()
{
TRISD=0;
TRISA=0;
PORTD=0;
PORTA=0;
}
void disp(uchar num1,uchar num2,uchar num3,uchar num4)
{
PORTD=table[ num1]; //Display the first digital tube
PORTA=0x20; //0010 0000
delay(2);
PORTD=table1[num2]; //Display the second digital tube
PORTA=0x10; //0001 0000
delay(2 );
PORTD=table[num3]; //Display the third digital tube
PORTA=0x08; //0000 1000
delay(2);
PORTD=table[num4];//Display the fourth digital tube
PORTA=0x04;//0000 0100
delay(2);
/* PORTD=table[num5];//Display the fifth digital tube
PORTA=0x02;/ /0000 0010
delay(2);
PORTD=table[num6];//display the sixth digital tube
PORTA=0x01;//0000 0001
delay(2);*/
}
Previous article:How to use PIC microcontroller timer 1
Next article:Principle and implementation of PIC microcontroller controlling relay
Recommended ReadingLatest update time:2024-11-16 15:37
- 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 3rd Edition (Zhang Yigang)
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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- News: Qorvo, a well-known RF chip company, also makes power solutions
- Why "It's time to abandon the switch matrix for multi-port testing" is all in Keysight's white paper ~ Limited time gifts are waiting for you
- It’s the beginning of autumn. Check out the beginning of autumn postcards from all over the country.
- TI High-Speed Signal Conditioning Product Selection Guide
- STM32L051's ADC conversion is inaccurate after wakeup
- Sharing of experience in single board circuit design 3-selection of pull-up and pull-down resistor parameters
- LVDS Receive
- Create a GD32VF103 project using Visual Studio Code
- Circuit Playground Star Tree
- Principles and Applications of FPGA and Specialized DSP