Discussion in "8051 Discussion Forum" started by    Gastonio    Sep 9, 2010.
Mon Sep 13 2010, 04:13 am
#11
A one second(or so), delay in your main while(1) loop is good method.
Also take "init()" out of the while() loop.
As a general rule, any routine with "init" in the name should not be called repeatedly.

You might consider comparing the latest value, to the one already being displayed.
If they are the same,skip writing to the display.


[ Edited Mon Sep 13 2010, 04:20 am ]
 Gastonio like this.
Mon Sep 13 2010, 04:23 am
#12
Thanks, I'll try your suggestion. I was considering about refreshing temperature value if there are any changes but I thought it won't help because if changes are rapid the temp value will still blink. Of course I didn't try so maybe it'll work just fine.
Mon Sep 13 2010, 04:29 am
#13
Once I took that init() out of the loop, the value didn't blink, however temp values were all over the screen from one line to another.
Mon Sep 13 2010, 04:48 am
#14
Added command to while(1) loop and it works fine, no blinking, that was the problem
Mon Sep 13 2010, 11:33 pm
#15
Could you verify if I am wrong or right understanding this routine.
If read_bit() is 1 (true) then this bit initiates value|=0x01<<i; and if bit is 0, then it doesn't initiate value|=0x01<<i. So as example if value of temperature is: (0000 0111)MSB (11010000)LSB then called read_byte routine will read LSB part bit by bit starting from 0 and 0,0,0,1,0,1,1 and when the bit value is 1 then this bit is moved by i places left creating 11010000 and calling read_byte the second time, routine reads MSB part. What role the 0x01 plays?

unsigned char read_byte(void)
{
unsigned char i;
unsigned char value = 0;
for (i=0;i<8;i++)
{
if(read_bit())
value|=0x01<<i;
delay(6);
}
return(value);
Tue Sep 14 2010, 12:47 am
#16
read_bit() tells the state of pin (proabably) when reading data from external device. so if bit is 1 at time and i = 0, it meas first bit is 1 and hence
Value |= 0x01 << i
simplifying:
i = 0 so, 0x01 << 0 = 0x01
value |= 0x01; => value = value | 0x01; => value = 0x00 | 0x01 = 0x01;

so value will have a 0x01 stored in it after execution.

incase the bit is 0 then no need to shift 1 inside value. understand now?

and data stored in value depends on what is being transferred first, LSB or MSB. in this case i guess LSB is transferred first.
 Gastonio like this.
Tue Sep 14 2010, 01:59 am
#17
Yes, I understand, thanks, even did it on the paper . I didn't know, that at first shifting is executed and only then OR, I thought that everything works successively: first OR and then shifting and that is way I couldn't understand why I can't get the value on the paper. Finally I almost fully understand programming of DS18B20.
Tue Sep 14 2010, 10:44 pm
#18
You're welcome glad you understood.
Mon Oct 11 2010, 01:58 am
#19
Hi, in order not to create new thread, I'll ask here. In C language it is relatively easy to write a routine for receiving string from PC to 8051, however I would like to ask, how it is done in ASM? I know how to send string to PC in ASM, but how to receive it form PC? To send string to pc or lcd it is needed to use for example: text: db "Text to send". But how to do vise versa?
Mon Oct 11 2010, 08:54 am
#20
Hi,

I know how to send string to PC in ASM, but how to receive it form PC



You need to write UART reception using Serial Interrupt.


--
Gurpreet Singh


IMBUENT TECHNOLOGIES PVT.LTD.
www.imbuent.com
www.embeddedcraft.org

EMBEDDED SYSTEM TRAINING IN LUDHIANA(PUNJAB)

"A person who never make mistakes,never try new things"

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am
Anthonyvab
Wed Apr 17 2024, 08:48 am
RobertCix
Wed Apr 17 2024, 06:46 am