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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/20/03 09:49
Read: times


 
#52925 - RE: Problem with 24c16
Responding to: ???'s previous message

Dear sir,

Menno van den berg

Thank you,

I am posting the code. Please comment on the same. Waiting for the reply

the code is

sda .REG p1.0
scl .REG p1.1

eeprom_read_page0 equ 0a1h
eeprom_write_page0 equ 0a0h

;Page0 data address
mpp_slow_turns_lsb_add equ 00h
mpp_slow_turns_msb_add equ 01h

mpp_high_turns_lsb_add equ 02h
mpp_high_turns_msb_add equ 03h

mpp_end_turns_lsb_add equ 04h
mpp_end_turns_msb_add equ 05h

pp_turns_lsb_act_add equ 06h
pp_turns_msb_act_add equ 07h

pp_slow_turns_lsb_add equ 08h
pp_slow_turns_msb_add equ 09h

pp_high_turns_lsb_add equ 0ah
pp_high_turns_msb_add equ 0bh

pp_end_turns_lsb_add equ 0ch
pp_end_turns_msb_add equ 0dh

bobbine_count_lsb_add equ 0eh
bobbine_count_msb_add equ 0fh


eeprom_read_page1 equ 0a3h
eeprom_write_page1 equ 0a2h

i2c_fault .REG 28h.4
;-------------------------------------------------------------------------
;*************************** Vector Addresses ****************************

org 0
jmp start

org 3 ;EXT INT0 - FOR
reti

org 0bh
ljmp time0 ; For 1 sec timer

org 13h ;EXT INT1 - FOR
reti

org 1bh
ljmp time1 ; Function for Multiplexing Display

org 23h
reti


start:
mov sp,#<sptr

; call initialise_eeprom
setb scl
setb sda

mov <device_address,#0a0h
mov <byte_address,#0
mov <eeprom_data,#55h
; call mem_write
call mem_read
mov a,#02h
call write_lcd_command
mov a,<eeprom_data
call display_byte
; mov a,#02h
; call write_lcd_command
; mov dptr,#msg_operation_over
; call display
jmp $
;****************** i2c test program*************************

mem_write:
push a
push b

setb scl
setb sda
mem_again:
call start_condition
jb i2c_fault,mem_again
call send_device_address1
jb i2c_fault,mem_again
call send_byte_address1
jb i2c_fault,mem_again
call send_eeprom_data
jb i2c_fault,mem_again
call stop_condition
push b
push a

ret
;---------------------------------------------------------------------
mem_read:
push a
push b

setb scl
setb sda
mem_read_again:
call start_condition
jb i2c_fault,mem_read_again
mov <device_address,#0a0h
call send_device_address1
jb i2c_fault,mem_read_again
mov <byte_address,#0
call send_byte_address1
jb i2c_fault,mem_read_again
call send_eeprom_data
jb i2c_fault,mem_again

call start_condition
jb i2c_fault,mem_read_again

mov <device_address,#0a1h
call send_device_address1
jb i2c_fault,mem_read_again

mov a,#02h
call write_lcd_command
call delay
call get_eeprom_data
call get_eeprom_data
; call delay

jmp $
call stop_condition
push b
push a

ret
;---------------------------------------------------------------------
start_condition:
start_again:
clr i2c_fault
jnb sda,fault_i2c
jnb sda,fault_i2c
jmp i2c_nxt1

fault_i2c:
mov a,#02h
call write_lcd_command
mov dptr,#msg_i2c_busy
call display
setb i2c_fault
jmp start_end

i2c_nxt1:
nop
clr sda
nop
nop
nop
nop
nop
nop
clr scl
start_end:
; setb sda
; setb scl
ret
;---------------------------------------------------------------------------
send_device_address1:
clr i2c_fault
mov a,<device_address
mov b,#8
device_address_again:
rlc a
mov sda,c
nop
setb scl
nop
nop
nop
nop
clr scl
djnz b,device_address_again

setb sda
nop
nop
setb scl
nop
nop
nop
nop
nop
nop
mov c,sda
clr scl

jnc device_address_end

call stop_condition
mov a,#02h
call write_lcd_command
mov dptr,#msg_device_address
call display_byte

mov a,#0c0h
call write_lcd_command
mov dptr,#msg_i2c_fault
call display
setb i2c_fault

device_address_end:
; setb scl
; setb sda
ret
;---------------------------------------------------------------------------
send_byte_address1:
clr i2c_fault
mov a,<byte_address
mov b,#8
byte_address_again:
rlc a
mov sda,c
nop
setb scl
nop
nop
nop
nop
clr scl
djnz b,byte_address_again

setb sda
nop
nop
setb scl
nop
nop
nop
nop
nop
nop
mov c,sda
clr scl

jnc byte_address_end

call stop_condition

mov a,#02h
call write_lcd_command
mov dptr,#msg_byte_address
call display

mov a,#0c0h
call write_lcd_command
mov dptr,#msg_i2c_fault
call display
setb i2c_fault
; jmp start_again

byte_address_end:
; setb scl
; setb sda
ret
;---------------------------------------------------------------------------
send_eeprom_data:
clr i2c_fault
mov a,<eeprom_data
mov b,#8
eeprom_data_again:
rlc a
mov sda,c
nop
setb scl
nop
nop
nop
nop
clr scl
djnz b,eeprom_data_again

setb sda
nop
nop
setb scl
nop
nop
nop
nop
nop
nop
mov c,sda
clr scl

jnc send_eeprom_data_end

call stop_condition
mov a,#02h
call write_lcd_command
mov dptr,#msg_eeprom_data
call display

mov a,#0c0h
call write_lcd_command
mov dptr,#msg_i2c_fault
call display
setb i2c_fault
; jmp start_again

send_eeprom_data_end:
ret
;---------------------------------------------------------------------------
stop_condition:
clr sda ;send STOP
nop
nop
setb scl
nop
nop
nop
nop
nop
setb sda

ret

;---------------------------------------------------------------------------
get_eeprom_data:
again_read:
setb sda
mov b,#8

read_again:
nop
nop
nop
setb scl
nop
nop
nop
; clr scl
nop
mov c,sda
rlc a
clr scl
djnz b,read_again

mov <eeprom_data,a
; mov a,#02h
; call write_lcd_command
mov a,<eeprom_data
call display_byte
; jmp again_read
setb sda
nop
nop
setb scl
nop
nop
nop
nop
clr scl

ret
;---------------------------------------------------------------------------



List of 6 messages in thread
TopicAuthorDate
Problem with 24c16            01/01/70 00:00      
   RE: Problem with 24c16            01/01/70 00:00      
      RE: Problem with 24c16            01/01/70 00:00      
         RE: Problem with 24c16            01/01/70 00:00      
   RE: Problem with 24c16            01/01/70 00:00      
      RE: Problem with 24c16            01/01/70 00:00      

Back to Subject List