This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Help me: 8051 asm. Indirect coding skill .

Could anyone help me ?

Below "case1" function works well in 8051 based.
Because this function uses under 0x7F sram address.

But, in "case2", cause short of memory,
I have to change registers to upper 0x80 address.
Currently, "case 2" is not working,
because it coded like direct coding.
In this case, I heard that indirect address method.
I strongly want to know this indirect coding method.

;case 1: ===============================================
rd_i2c_buf0 equ 50h
rd_i2c_buf1 equ 51h
rd_i2c_buf2 equ 52h
rd_i2c_buf3 equ 53h

fncI2C_write_Nbyte:
mov rd_i2c_buf0,#0d0h ;dir
mov rd_i2c_buf1,#00h ;dir
mov rd_i2c_buf2,#01h ;dir

mov rd_i2c_byte_cnt,#03h

ACALL ifncI2C_start_Condition ;
mov a, #rd_i2c_buf2 ;dir
mov R0,a ;dir
i2c_Nbyte_loop:
mov a,@R0
ACALL ifncI2C_write_8bit ;
ACALL ifncI2C_wait_ack ;
CJNE A,#0,i2c_Nbyte_error
mov a,R0
inc a
mov R0,a djnz rd_i2c_byte_cnt,i2c_Nbyte_loop
i2c_Nbyte_error:
ACALL ifncI2C_stop_Condition ;
RET

;case 2: ========= for change to indirect sram ==========

ri_i2c_tmp_buf0 equ 80h
ri_i2c_tmp_buf1 equ 81h
ri_i2c_tmp_buf2 equ 82h
ri_i2c_tmp_buf3 equ 83h
ri_i2c_tmp_buf4 equ 84h

fncI2C_write_Nbyte:
mov ri_i2c_tmp_buf0,#0d0h ;indir?
mov ri_i2c_tmp_buf1,#00h ;indir?
mov ri_i2c_tmp_buf2,#01h ;indir?

mov rd_i2c_byte_cnt,#03h

ACALL ifncI2C_start_Condition ;
mov a, #ri_i2c_tmp_buf0 ;indir?
mov R0,a ;indir?
i2c_Nbyte_loop:
mov a,@R0
ACALL ifncI2C_write_8bit ;
ACALL ifncI2C_wait_ack ;
CJNE A,#0,i2c_Nbyte_error
mov a,R0
inc a
mov R0,a djnz rd_i2c_byte_cnt,i2c_Nbyte_loop
i2c_Nbyte_error:
ACALL ifncI2C_stop_Condition ;
RET
;=========================================================

Parents Reply Children