Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/30/10 14:43
Read: times


 
#174632 - 8051 using i2c
Hello there,
i have looked for a similar thread but i didnt find any.

I use a DS89C450 and a Humidity and Temperature sensor to measure temperature and humidity. They communicate using I2C protocol. I wrote the code using assembly language (i dont know C)
The results i get are wrong.
I probably have a problem using I2C protocol.
This is a part of code i've written so someone tell me whats the problem.



sda equ P3.0 ;data pin
scl equ P3.1 ;clock pin
en equ p2.5 ;lcd comunication enable pin
rs equ p2.3 ;lcd data/command pin
r_w equ p2.2 ;lcd read/write pin


;__________________________________TEMPERATURE___________________________________



clr c
mov a,#00000011b ;00000011 <-- Measure temperature command
mov r3,#08d
temp: ;Sending the temperature command
rlc a
mov sda,c
setb scl
acall delay1
clr scl
acall delay1
djnz r3, temp

jnb sda,$


mov r4,#03d
mov r0,#50h ;1st temperature byte saved at memory


t1: mov r3,#08d
clr c
clr a

t2: ;Receive Temperature measurement bit-by-bit
mov c, sda
rlc a
clr scl
acall delay1
setb scl
acall delay1
djnz r3,t2 ;do it for 8 times

mov @r0,a ;store byte
inc r0

clr sda ;send ack
clr scl
acall delay1
setb scl
acall delay1

djnz r4,t1


acall print_Temp
acall delay



;___________________________DISPLAY TEMPERATURE_________________________

print_Temp:
setb en
clr r_w
clr rs
mov p0,#80h ;move to 1st line
call lcd_delay

setb rs
mov p0,#'T' ;print "T"
acall lcd_delay
mov p0,#'e' ;print "e"
acall lcd_delay
mov p0,#'m' ;print "m"
acall lcd_delay
mov p0,#'p' ;print "p"
acall lcd_delay
mov p0,#'=' ;print "="
acall lcd_delay

mov r4,#03d
mov r0,#50d
ptemp1:
mov p0,@r0 ;print data
acall lcd_delay
inc r0
djnz r4,ptemp1


clr rs
ret



List of 24 messages in thread
TopicAuthorDate
8051 using i2c            01/01/70 00:00      
   What was your result?            01/01/70 00:00      
      Results            01/01/70 00:00      
         Binary data or printable ASCII data?            01/01/70 00:00      
            Binary data            01/01/70 00:00      
   I probably have a problem using I2C protocol.            01/01/70 00:00      
      I2C protocol            01/01/70 00:00      
         that being the case            01/01/70 00:00      
         So it clearly tells you that it is *not* I2C!!            01/01/70 00:00      
   start over            01/01/70 00:00      
      Why not start with the code they give you?            01/01/70 00:00      
         what code?            01/01/70 00:00      
            compile it            01/01/70 00:00      
            You have to be prepared to do some work, you know            01/01/70 00:00      
               Ripping assembler from the debugger            01/01/70 00:00      
      I need some help            01/01/70 00:00      
         Not a Contracting Site            01/01/70 00:00      
         We may be able to come to an arrangement - on one condition            01/01/70 00:00      
            BRAVO            01/01/70 00:00      
            I need some help 2            01/01/70 00:00      
               Have you checked the debugger/simulator yet?            01/01/70 00:00      
                  Compiler/simulator            01/01/70 00:00      
                     No compiler in the C51 kit???            01/01/70 00:00      
                        you were so right            01/01/70 00:00      

Back to Subject List