Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Help] 8051 interfacing sensirion SHT7X digital sensor

Status
Not open for further replies.
Hi,
Regarding the subtraction of the term 2n1n2, you can keep the structure of your program same as above, except, in the case of 2n1n2, use SUB/SUBB instead of ADD/ADDC.
Regards,
Laktronics
 

Regarding the subtraction of the term 2n1n2, you can keep the structure of your program same as above, except, in the case of 2n1n2, use SUB/SUBB instead of ADD/ADDC

3. The term 2n1n2 is to be added to the table value after MUL by 100 and then to be subtracted from the basic term. I also did not notice this error earlier.

Hi,regarding of this 2n1n2 error term, as it should be minus from the basic term.
as
Rh=0.01[4(Rdh-100D)]-[2.8X10^-6(n1.256)^2 - 2n1n2x10^-2]
but i take it out and the negative sign equal to positive sign

Rh=0.01[4(Rdh-100D)]-[2.8X10^-6(n1.256)^2 ] +2n1n2X10^-2
and i could be bring to front

Rh=0.01[4(Rdh-100D)+2n1n2]-[2.8X10^-6(n1.256)^2 ]

Rh=0.01[4(Rdh-100D)+2n1n2-2.8X10^-4(n1.256)^2 ]
So my code work for this formula.

Below is the update i double checked :

ORG 0000H ;initially store the sensor reading LSbyte in R3 ,MSbyte in R2

MOV R3,A
SWAP A
ANL A,#0FH
MOV R7,A

CLR C
MOV A,R3
SUBB A,#64H
MOV R4,A
MOV A,R2
SUBB A,#00H
MOV R5,A

;now n1 in R2, n2n3 in R3 , R4 hold LSbyte value after -100D , R5 hold MSbyte value after - carry if there are carry, R7 hold n2

MOv B,#4D ;multiply 4 for Rdt-100D
MUL AB
MOV R5,A

MOV A,R4
MOV B,#4D
MUL AB
MOV R0,A
MOV R1,B
MOV A,R5
ADD A,R1
MOV R5,A

;now R0 hold the LSbyte after x4 , R5 hold the MSbyte after x4

MOV B,R7 ;getting 2n1.n2
MOV A,R2
MUL AB

MOV B,#2
MUL AB ;A store LSByte of 2n1.n2 ,B store MSByte of 2n1.n2

CLR C
ADD A,R0
MOV R0,A
MOV A,B
ADDC A,R5
MOV R5,A

;So until now i had calculated this part [4(RDh-100D)+2n1n2], with MSbyte stored in R5 and LSbyte store in R0

MOV DPTR,#1EFFH
MOV A, R2
MOVC A,@A+DPTR ; A will get the data corresponding to value of n1 (2.8x10^-6[n1.256]^2
MOV B,#100D ;getting (2.8x10^-4[n1.256]^2
MUL AB
MOV R1,B ;R1 hold MSbyte
MOV R4,A ;R4 hold LSbyte

CLR C
MOV A,RO
SUBB A,R4
MOV R0,A
MOV A,R5
SUBB A,R1
MOV R5,A ;R5 hold MSbyte and R0 hold LSbyte for [4(Rdh-100D)+2n1.n2-2.8x10^-4(n1.256)^2]


CSEG AT 1EFFH
DB 0D,0D,0D,2D,3D,5D,7D,9D,12D,15D,18D,22D,26D,31D,36D,41D

END
 

Hi,
Other corrections are in place, but 2n1n2 is basically a part of Rdh^2 and hence to be added to the table value or to be subtracted from the basic reading. Rdh^2 is expanded as (a+b)^2 and 2n1n2 is basically the 2ab term and the table value is nothing but the a^2 term. Please see my earlier post in this connection.

Regards,
Laktronics
 

Okie sorry,noted !

Added after 11 minutes:

Halo, again
Now i am sending the reading to LCD (HD44780,16pin)

Now i have my result store ;R5 hold MSbyte and R0 hold LSbyte for [4(Rdh-100D)-2n1.n2-2.8x10^-4(n1.256)^2]

So how do i send to LCD those data?
Is it like in BCD as u mention ealier? And build a ASCII look-up table for 0-9 ?
 

Hi,
You have to use a subroutine to convert the calculated binary data to BCD first and store the result in five memory locations as digits only. Then while sendinding to the display, take each BCD digit and add 30h to it to make it ASCII, and then only send to the display. The idea in keeping the data as BCD in the memory is that you can even output it to a port and view it to crosscheck your LCD, at least during development phase.

Also remember to put the decimal point on the display corresponding to multiplication by 0.01D

Regards,
Laktronics.
 

Okie,thank you.I think i know how to do it.
Currently i facing another problem,my LCD dont give me display !!
This is my test code on it...is it correct?
I tested many times the hardware configuration and coding...but can't find out why.Will the LCD spoiled?

;P2.0 connect to RS,P2.1 -> R/W, P2.2 -> EN
;P0.0-P0.7 connected to LCD's DB0-DB7...


ORG 0000H
MOV A,#38H
CALL WRT_COMN
MOV A,#0EH
CALL WRT_COMN
MOV A,#01H
CALL WRT_COMN
MOV A,#06H
CALL WRT_COMN
MOV A,#84H
CALL WRT_COMN
MOV A,#'O'
CALL WRT_DATA
MOV A,#'K'
CALL WRT_DATA
HALT: SJMP HALT

WRT_COMN:
CALL READY
MOV P0,A
CLR P2.0
CLR P2.1
SETB P2.2
CLR P2.2

WRT_DATA:
CALL READY
MOV P0,A
SETB P2.0
CLR P2.1
SETB P2.2
CLR P2.2
RET

READY:
SETB P0.7
CLR P2.0
SETB P2.1

READY2:
CLR P2.2
SETB P2.2
JB P0.7,READY2
RET

END
 

Hi,
Your code appears to be ok, but you mostly need to do software initialisation in the beginning. Do you get the cursor display? Have you connected the display voltage pin Vlcd to ground? If the display does not provide pullups on Data lines, you need to pullup P0 port pins.
If you have readily the user manual of the display, please upload it, may be useful to others also. Also, add some more comments to your code.

Regards,
Laktronics

Added after 20 minutes:

Hi,
Also, after Poweron, display expects a delay before giving any commands and during this period, you can not check the readiness of the display using the Busy Flag.

Regards,
Laktronics
 

Hi,i do not have the cursor display at all too.Just blank.

Yes,pin1 Vss and pin3 Vee connected to ground , while pin2 Vdd connected to 5V.

I uploaded the data sheet here.
 

Okie, i try to give it some delay.Thank you !!
 

Hi,
Since now there are two CPU's, 8051 and the display CPU, it is likely that 8051 may come out of Reset earlier than the display CPU and start issuing instructions to the display CPU. Reading of the Busy flag may give wrong results now and 8051 may goahead with its software. So initially give a delay of about 500msec before giving any command to LCD. If it does not work, do a software Init and then only send commands to LCD.

Regards,
Laktronics
 

Hi,
1. RET is missing in WRT_COMN and also in the busy flag check routine, return after clearing the enable bit. May be read busy flag into C first. Also P2.1 may be normally kept in high state before leaving the subroutine and make it low only for write within the subroutine. Does your assembler support CALL statement, 8051 code is acall or Lcall.
Regards,
Laktronics

Added after 30 minutes:

Hi,
Also in the busy flag check routine, make all bits of P0 high since the LCD outputs address on other bits and if P0 not fully set high, will load these LCD signals.
Regards,
Laktronics
 
Hi,

I had reading on my lcd finally.

Now i going to combine all function and try to output temperature reading to LCDs.

For the HEX2BCD code , i found it on 8052.com , and modify abit for my uses. I don't think i can write it out because i don't know the concept or formula behind.But basically i tested the code with some calculation and it is working.

I upload my full code here for you to double check. The codes still not been packed but i will do that at final stage, after succesfully getting the result first.

Thank you again.
 

Hi,
That is really great !! Finally, was it the mssing RET or the LCDINIT which was responsible for the LCD problem? I will get back to you a bit late regarding your code.
Regards,
Laktronics

Added after 1 hours 49 minutes:

Hi,
1. Regarding your code, if you want you can compact your store data subroutine as follows:

Store_data:
CALL rdbyte
MOV R0,A ;R0 stores MSbyte
CALL ACK_MINUS
CALL rdbyte
MOV R1,A ;R1 stores LSbyte
RET
rdbyte:
SETB DATAA
Mov R3,#08h
looprd: SETB SCK
NOP
MOV C,DATAA
RLC A
CLR SCK
NOP
DJNZ R3,looprd
ret

ACK_MINUS:
CLR DATAA ;Negative Ack for the received byte
SETB SCK
NOP
NOP
CLR SCK
NOP
NOP
SETB DATAA
RET

2. Also in the READY routine, you can set full port P0 to high and also leave EN in cleared state when leaving the subroutine as follows:

READY:

;SETB P0.7
MOV P0,#0FFh
CLR P2.0
SETB P2.1

READY2:
CLR P2.2
SETB P2.2
JB P0.7,READY2
CLR P2.2
RET

Regards,
Laktronics.

Added after 42 minutes:

Hi,
Also, Hex to BCD is done in the software as follows:

1.First take LS bye and divide by 10 successively till the final quotient becomes less than 10. Since the max. vlaue of a byte is 255, it will happen after two divisions at worst. After each division by 10 store the remainders in registers R3 followed by R4 and the final quotient in R5.

2.Next do a BCD addition of 256 to contents of R3, R4 and R5 as many times as the count in the MS byte, since the weightage of the MS byte is 256. In this process, you also divide everytime R5 also by 10 and keep adding the quotient to R6 and keep remainder in R5.

3.Finally, divide R6 by ten and leave remainder to R6 and quotient to R7.

Regards,
Laktronics.
 
I think is the missing of RET and the LCD spoiled(as i bought a new 1),i did not initiate the LCD yet.

Thanks for telling me the concept of HEX->BCD, and the correction for all my mistake :)

Added after 1 minutes:

Oh, before i forgot.I notice 'call' command is functionable in 89c52.
 

Hi,
Thanks for the info about CALL.

I also notice that you have a routine already called ACK. In my above post, so I am going to rename the new ACK routine as ACK_Minus.

LCD is generally supposed to self initiate and if it works OK, you need not initiate by software again.

But why the LCD had to fail, any clue?

Regards,
Laktronics.
 

Ohic

Maybe my soldering melted the brown conducting surface? haha...i am bad at soldering...

Or the LCD initially spoiled?
 

Hi,
Not bad, good experience indeed.

Regards,
Laktronics
 

Hi,
My codes is working,except for the inverse reading of BCD display on LCD.

Now i am working for the full code. Thank you !
 

Hi,
Good to know that your code is working, hope you know the reason behind why the BCD is shown reverse and that you can correct it. All the best.

Regards,
Laktronics
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top