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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/22/09 18:42
Read: times


 
#164792 - 89s52 with 24c512 and ds 1307
i have been trying to interface 24c512 with 89s52 but not successful yet. i am sending letter 'S' to be written on it and then to be read,but display is showing some other character.

also i interfacing ds1307 with it and no display for it too.see my codes and try to help.otherwise if you have code then please give.


first code is for 24c512
g
org 00h

sda equ P1.1
scl equ P1.0

write equ 10100000b ;control byte for writing
read equ 10100001b ;control byte for reading

;init
clr sda
clr scl
nop
setb sda
setb scl
ret

startc:
setb scl
clr sda
clr scl
nop
nop
lcall writenow
stop:
clr scl
clr sda
setb scl
setb sda
ret


writenow:clr sda
clr scl
mov a,#write
lcall send
setb sda
setb scl
jb sda,writenow
clr scl
mov a,#00000000b
lcall send
setb sda
setb scl
jb sda,writenow
clr scl
mov a,#00000000b
lcall send
setb sda
setb scl
jb sda,writenow
clr scl

mov a,#33h ;hex equivalent for 'S'
lcall send
setb sda
setb scl
jb sda,writenow

clr scl

setb sda
clr scl
setb scl
setb sda
ret

readnow:clr sda
clr scl
mov a,#write
lcall send
setb sda
setb scl
jb sda,readnow
clr scl
mov a,#00000000b
lcall send
setb sda
setb scl
jb sda,readnow
clr scl
mov a,#00000000b
lcall send
setb sda
setb scl
jb sda,readnow
clr scl
mov a,#read
lcall send
setb sda
setb scl
jb sda,readnow
clr scl
lcall recv
setb sda
setb scl
clr scl

setb sda
acall display
lcall stop

display: mov r0,#38h ;LCD initialization subroutine
acall command
acall delay
mov r0,#0ch
acall command
acall delay
mov r0,#01h
acall command
acall delay
mov r0,#06h
acall command
acall delay
mov r0,#0c5h
acall command
acall delay
mov r0,a
acall data
acall delay
command:
mov p2,r0
acall delay
clr p1.2
setb p1.4
acall delay
clr p1.4
ret

data:
mov p2,r0
acall delay
setb p1.2
setb p1.4
acall delay
clr p1.4
ret


delay: mov r6,#60
here4: mov r7,#50
here1: djnz r7,here1
djnz r6,here4


send:
mov r7,#08
back:
clr scl
rlc a
mov sda,c
setb scl
djnz r7,back
clr scl
setb sda
ret

recv:
mov r7,#08
back2:
clr scl
setb scl
mov c,sda
rlc a
djnz r7,back2
clr scl
setb sda
ret
end



here is the code for the clock

ec equ 30h ;second register
min equ 31h ;minutes register
hour equ 32h ;hour register
days equ 33h ;days register
date equ 34h ;date register
month equ 35h ;month register
year equ 36h ;year register
sda equ P1.1 ;Serial data pin
scl equ P1.0 ;Serial clock pin

en equ p1.4 ;enable pin of LCD
rs equ p1.2 ;register select pin of LCD
org 00h

acall initial
acall disp_const
mov sec,#00h
mov min,#0h
mov hour,#21h ;21h for 24 hour format
mov days,#01h
mov date,#1h
mov month,#04h
mov year,#09h



mov r6,#7h
mov r0,#30h

acall rtc_ini

run: acall initial
acall disp_const



run1: acall startc ;Actual Starting
mov a,#0d0h
acall send
mov a,#00h
acall send
mov r6,#3fh
acall startc ;Reading the RCT content
mov a,#0d1h
acall send
mov r0,#40h
here: acall recv
djnz r6,here
acall stop
acall display ;Display RTC

rtc_ini:acall startc ;RTC initialization subroutine
mov a,#0d0h
acall send
mov a,r1
acall send
mov a,@r0
acall send
inc r0

acall stop
djnz r6,rtc_ini
acall stop
ret

initial:mov a,#38h ;LCD initialization subroutine
acall command
mov a,#0ch
acall command
mov a,#01h
acall command
mov a,#06h
acall command
ret

startc: ;I2C atart condition subroutine
setb scl
clr sda
nop
clr scl
nop
ret
send: ;Sending data to I2C bus
mov r7,#08
back:
clr scl
nop
rlc a
mov sda,c
setb scl
nop
clr scl
nop
djnz r7,back
setb sda
setb scl
nop
clr scl
nop
ret

stop: nop ;I2C stop Condition
clr sda
setb scl
nop
setb sda
nop
clr scl
ret

recv: ;Recieving data from I2C bus
mov r7,#08
back2:
setb sda
setb scl
nop
mov c,sda
rlc a
clr scl
nop
djnz r7,back2
setb sda
clr scl
nop
clr sda
setb scl
nop
clr scl
nop
mov @r0,a
inc r0
ret

display:mov r1,#40h ;Displaying RTC content
mov a,#0Cah
acall command
mov a,@r1
mov 50h,@r1
acall disp_val
;mov r4,a
; anl a,#1fh
; acall disp_val
; mov a,r4
; anl a,#20h
;cjne a,#00h,pim
; mov a,#0cdh
; acall command
;mov a,#"am"
acall data_in
;sjmp pass3
;pim: mov a,#0cdh
;acall command
; mov a,#"pm"
; acall data_in


pass3: inc r1
mov a,#88h
acall command
mov a,@r1
mov 54h,@r1
acall disp_val
PASS4: inc r1
mov a,#8bh
acall command
mov a,@r1
mov 55h,@r1
acall disp_val
disp_val: ;Display 8-bit Decimal Value
push acc
mov r5,a
swap a
anl a,#0fh
orl a,#30h
mov dptr,#ascii
movc a,@a+dptr
acall data_in
mov a,r5
anl a,#0fh
orl a,#30h
movc a,@a+dptr
acall data_in
pop acc
ret

disp_const: ;Display constant characters
mov a,#8ah
acall command
mov a,#'/'
acall data_in
mov a,#8dh
acall command
mov a,#'/'
acall data_in
mov a,#0c6h
acall command
mov a,#':'
acall data_in
mov a,#0c9h
acall command
mov a,#':'
acall data_in
ret
command:acall delay ;Sending command to LCD
mov p2,a
acall delay
clr p1.2
setb p1.4
acall delay
clr p1.4
ret

data_in:acall delay ;Sending data to LCD
mov p2,a
acall delay
setb p1.2
setb p1.4
acall delay
clr p1.4
ret





delay: mov r6,#60
here4: mov r7,#50
here1: djnz r7,here1
djnz r6,here4

ascii: ;ASCII lookup table
db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h

end




List of 10 messages in thread
TopicAuthorDate
89s52 with 24c512 and ds 1307            01/01/70 00:00      
   Please format your code            01/01/70 00:00      
      Why you should comment your code            01/01/70 00:00      
         Why you should comment your code            01/01/70 00:00      
            Yes, but this is difficult for a new learner.            01/01/70 00:00      
               RTC and EEPROM            01/01/70 00:00      
                  thanks            01/01/70 00:00      
   33h != 'S'            01/01/70 00:00      
      ASCII characters shouldn't be converted to hex or decimal            01/01/70 00:00      
   EEPROM            01/01/70 00:00      

Back to Subject List