10416 views|11 replies

37

Posts

0

Resources
The OP

Conflict between 18B20 and interrupt display. [Copy link]

I wrote a program to measure the temperature of 18B20 using 51, and used a digital tube to display it. The display was scanned by a timer interrupt. The display program was good, and the temperature driver was perfect. But it didn't display properly when I put a 1.9 yuan. I searched on Baidu and found that there was a conflict between the interrupt and the 18B20 driver. But how to solve it? Has anyone done this before? Please give me some advice...
This post is from MCU

Latest reply

The 750ms is for temperature conversion, and there is no read or write operation, so the interrupt can be turned on to execute the operation in the interrupt routine, such as display. The interrupt cannot be turned on during the read or write operation. If an interrupt occurs during the read or write process and the interrupt operation is executed, the 18B20 operation timing will definitely be destroyed. There are nine operations behind, all of which are in the microsecond level. Turning off the interrupt in less than 1ms will affect the display, but the human eye usually cannot feel it because the time is very short.  Details Published on 2013-10-13 13:12

Comments

18B20 has strict requirements on operation timing. Usually, interruption is not allowed when operating 18B20. However, the read and write operation time of 18B20 is not very long (tens of microseconds), and the conversion time is long (about 1 second). Therefore, interruption needs to be turned off when reading and writing 18B20, and interruption is turned on after reading and writing (conversion command), so that 18B20 can convert by itself, and then the conversion is completed.  Details Published on 2013-10-12 18:33

3w

Posts

0

Resources
2
18B20 has strict requirements on operation timing, and usually, interruption is not allowed when operating 18B20. However, the reading and writing operation time of 18B20 is not very long (tens of microseconds), and the conversion time is long (about 1 second). Therefore, when reading and writing 18B20, interruption needs to be turned off, and interruption is turned on after reading and writing (conversion command), so that 18B20 can convert by itself. After the conversion is completed, the interruption is turned off and the temperature data is read, and the interruption is turned on immediately after reading. In this way, the interruption time is relatively short, and the display is slightly delayed, which is usually not noticeable.
This post is from MCU

Comments

//Write one byte of data to DS18B20 void writeByte(unsigned char dat) { unsigned int i; unsigned char j; bit b; TR0=0; for(j = 0; j < 8; j++) { b = dat & 0x01; dat >>=  Details Published on 2013-10-12 21:39

7

Posts

0

Resources
3
The above is very accurate. It should be a problem of timing and interruption.
This post is from MCU

Comments

I set the temperature module to execute in the interrupt, and then put the display in the main function, and it works. Although it can achieve the purpose, it is not easy to use if other work needs to be done. So,,, I still don't know how to use it.  Details Published on 2013-10-12 21:42

37

Posts

0

Resources
4
//Write a byte of data to DS18B20 void writeByte(unsigned char dat) { unsigned int i; unsigned char j; bit b; TR0=0; for(j = 0; j < 8; j++) { b = dat & 0x01; dat >>= 1; //Write "1", pull DQ down for 15us, then pull DQ high within 15us~60us to complete writing 1 if(b) { ds = 0; i++; i++; //Pull down for about 16us, the sign requires 15~60us ds = 1; i = 8; while(i>0) i--; //Delay about 64us, in line with the write time slot requirement of not less than 60us } else //Write "0", pull DQ down for 60us~120us ds = 0; i = 8; while(i>0) i--; //Pull down for about 64us, Sign requirement ds = 1; i++; i++; //The whole write 0 time slot process has exceeded 60us, so there is no need to delay 64us like writing 1} TR0=1; } //Read one byte of data, implemented by calling readBit() unsigned char readByte() { unsigned int i; unsigned char j, dat; dat = 0; TR0=0; for(i=0; i<8; i++) { j = readBit(); //The first to read is the lowest bit dat = (j << 7) | (dat >> 1); } TR0=1; return dat; } Is this right? Do you disable interrupts in the read and write functions in the driver? It seems not possible.
This post is from MCU

Comments

Why not disable interrupts before calling the write function and enable interrupts immediately after executing the write function? The same is true for calling the read function.  Details Published on 2013-10-13 11:59

37

Posts

0

Resources
5
I set the temperature module to execute in the interrupt, and then put the display in the main function, and it works. Although it can achieve the purpose, it is not easy to use if other work needs to be done. So,,, I still don't know how to use it.
This post is from MCU

3w

Posts

0

Resources
6
Why not disable interrupts before calling the write function and enable interrupts immediately after executing the write function? The same is true for calling the read function.
This post is from MCU

Comments

But, I tried it. It is really no different from the original. It is really annoying. Does anyone know the specific timing of 18B20? For example, how long does it take to reset, convert temperature, read temperature, etc.? It seems that it takes less than 1s. Newbie please help!!!  Details Published on 2013-10-13 12:10

37

Posts

0

Resources
7
But, I tried it. It's really no different from the original. It's really annoying. Does anyone know the specific timing of 18B20? For example, how long does it take to reset, convert temperature, read temperature, etc.? It seems that it takes less than 1s. Newbie help!!!
This post is from MCU

3w

Posts

0

Resources
8
DS18B20.pdf (276 KB, downloads: 15)
This post is from MCU

3w

Posts

0

Resources
9
For example, how long does it take to reset, convert the temperature, read the temperature, etc.? It seems that it will take less than 1 second.
This post is from MCU

Comments

What about the rest of the time? Are they all converting temperatures? Can we do other things during the rest of the time?  Details Published on 2013-10-13 13:03

37

Posts

0

Resources
10
What about the rest of the time? Are they all converting temperatures? Can we do other things during the rest of the time?
This post is from MCU

Comments

The 750ms is for temperature conversion, and there is no read or write operation. Therefore, the interrupt can be enabled to execute the operation in the interrupt routine as shown. The interrupt cannot be enabled during the read or write operation. If an interrupt occurs during the read or write process and the interrupt operation is executed, the 18B20 operation timing will be destroyed. There are nine operations behind, all of which take microseconds.  Details Published on 2013-10-13 13:12

3w

Posts

0

Resources
11
The 750ms is for temperature conversion, and there is no read or write operation, so the interrupt can be turned on to execute the operation in the interrupt routine, such as display. The interrupt cannot be turned on during the read or write operation. If an interrupt occurs during the read or write process and the interrupt operation is executed, the 18B20 operation timing will definitely be destroyed. There are nine operations behind, all of which are in the microsecond level. Turning off the interrupt in less than 1ms will affect the display, but the human eye usually cannot feel it because the time is very short.
This post is from MCU

Comments

while(1) { if(time_1ms>2) //digital tube display, { time_1ms=0; dis_one(); } TR0=0; temper=getTmpValue(); //read temperature command sendChangeCmd(); //temperature conversion command  Details Published on 2013-10-13 13:36

37

Posts

0

Resources
12
while(1) { if(time_1ms>2) //digital tube display, { time_1ms=0; dis_one(); } TR0=0; temper=getTmpValue(); //read temperature command sendChangeCmd(); //temperature conversion command TR0=1; Is this right? It seems to have no effect.
This post is from MCU

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list