I2C PROBLEM IN ASSEMBLY(8051).Help me,please.

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I have a problem in my program.
This program is to write in eeprom(hn58x2432) & read from it to
display
to lcd  module.It is transmit by I2C.
Please help me to check my program.

Thanks.
It have some problem when it compiled.Below is the error message.


LINE 11       ACK     REG P2.0==============>ILLEGAL MNEMONIC
LINE 12       SCL     REG P2.1==============>ILLEGAL MNEMONIC
LINE 13       SDA     REG P2.2==============>ILLEGAL MNEMONIC
LINE 14       COUNTD  EQU 41H ==============>ILLEGAL MNEMONIC
....
Just like that
===============================================================
I don't know some else bugs in it,so help me check it,please.
Thanks.
===============================================================





;=======================================================
;                MAIN PROGRAM
;=======================================================
    ORG    0000H
;=====================================================
;I2C    SET I2C MODULE PINS
;=====================================================
;P1為LCM資料線專用接腳,P3為LCM之E,R/S,W/R用
;=====================================================
    ACK    REG    P2.0    ;I2C ACKNOWLEDGE
    SCL    REG    P2.1    ;I2C SERIAL CLOCK
    SDA    REG    P2.2    ;I2C SERIAL DATA
    COUNTD    EQU    41H    ;倒數用計數器
    COUNTU    EQU    42H    ;計數用
    ADR    EQU    43H    ;I2C EEPROM ADDRESS
    DATA    EQU    44H    ;I2C要傳輸的資料
    X    EQU    45H    ;界面常數
;-------------------------------------------------------------------------------
           MOV    SP,#5FH
          MOV        P2,#0EH
           ACALL    INIT        ;INITIAL LCM
    ACALL
    LINE1        ;游標停在第一行第一個字
    MOV           DPTR,#TAB1
    ;將資料指標暫存器指向程式內資料所在
    ACALL       WR_TO_ROM    ;將資料寫入ROM
    ACALL    RD_FR_ROM    ;將ROM資料讀出並顯示於LCM
;===============================
OK    AJMP    OK
;===============================    
;    SUB ROUTINE
;===============================
INIT    ACALL    DLY40        ;INITIAL LCM
    MOV    A,#38H        ;設定LCM為8位元及2行顯示,5x7
dots
    ACALL    WRINS        ;設定E ENABLE
把指令碼設定進去
     MOV    A,#38H
    ACALL    WRINS
    MOV    A,#38H
    ACALL    WRINS
    MOV    A,#38H
    ACALL    WRINS

    MOV    A,#08H        ;#00001000B 液晶顯示OFF
    ACALL    WRINS
;=============================
    MOV    A,#01H        ;#00000001B
清除液晶顯示
    ACALL    WRINS
;=============================
    MOV    A,#06H        ;#00000110B
寫入1BYTE,游標右移且ACC加一
    ACALL    WRINS
;=============================
    MOV    A,#0CH        ;#00001100B
液晶顯示ON,不顯示游標
    ACALL    WRINS
    RET
;\\\\\\\\\\\\\\\\\\\
LINE1    MOV    A,#10000000B    ;顯示起始位址為第一行第一個字
    ACALL    WRINS
    RET
;=============================
LINE2    MOV    A,#11000000B    ;顯示起始位址為第二行第一個字
    ACALL    WRINS
    RET
;------------------------------------------------------------
;LCD
    把指令碼設定進去直接控制LCD的螢幕顯示
;------------------------------------------------------------
WRINS    MOV    P3,#00011111B    ;P3為R/S, E , R/W
    NOP
    SETB    P3.5        ;設定E為 ENABLE
    MOV    P1,A        ;將A內容設定進去
    NOP
    CLR    P3.5
    ACALL    DLY8
    RET
;------------------------------------------------------------
;LCD        把DATA碼設定進去
來顯示內定的文字
;------------------------------------------------------------
WRDATA    MOV    P3,#10011111B
    NOP
    SETB    P3.5
    MOV    P1,A
    NOP
    CLR    P3.5
    ACALL    DLY16
    RET
;------------------------------------------------------------

;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;I2C    把程式中之字元碼寫入ROM中
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
WR_TO_ROM:
    CALL    I2C_WRITE_ADR    ;傳輸目的ROM的位址,狀態為寫入
    MOV    R7,#00H        ;把位址DPTR起的字元碼逐一送至EEPROM模組
NEXT    MOV    A,R7    
    ;直至遇到結束碼10H才返回主程式
    MOVC    A,@A+DPTR    ;DPTR指到程式內的資料起始位址
    CLR    SDA        ;開始傳輸程式內的資料到ROM
    MOV    COUNTD,#8
    MOV    DATA,A        ;將A的內容傳至DATA,由DATA作暫存器寫入
IWA    RLC    DATA
    MOV    SDA,C
    SETB    SCL
    CLR    SCL
    DJNZ    COUNTD,IWA
    CLR    ACK
    SET    ACK    
;=======檢查後面字元是否10H================================================
    CJNE    A,#10H,RD_NX    ;讀到10H,即停止讀取及寫入動作
    RET
RD_NX:     
    INC    R7        ;不是讀到10H,即繼續讀取下一個字元R7作為計數器
    AJMP    NEXT        ;R7作為計數器看傳入多少字元
=========================================================================
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;I2C    開始讀出ROM內的資料並顯示於螢幕
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
RD_FR_ROM:
    MOV    DATA,#0
    CALL    I2C_READ_ADR    ;傳輸目的ROM的位址,狀態為讀出
    MOV    A,R7        ;把傳至ROM的字元碼,倒數送出至LCM模組來顯示
    MOV    COUNTU,A
    ;由R7可看出傳入多少字元到ROM裡面,此值傳入COUNTU
RD_NX    CLR    SDA        ;開始傳輸ROM內的資料到LCM
    MOV    COUNTD,#8
RFR    MOV    X,#0
    MOV    A,#0
    MOV    C,SDA        ;從SDA開始接收資料
    ADDC    A,X        ;接收SDA加到A累積器中
    ADD    DATA,A        ;A內容傳給DATA
    RL    DATA
    SETB    SCL
    CLR    SCL    
    DJNZ    COUNTD,RFR    ;傳完8個字元後
    CLR    ACK        ;給一個應答
    SET    ACK
    MOV    A,DATA        ;將傳入的字元傳至A累積器
    CALL    WRDATA        ;送出字元讓LCM顯示
    DJNZ    COUNTU,RD_NX    ;持續讀出下一個字元,直到所有字元讀出
     RET

;===========================================================    

;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;I2C    設定指定
ROM的位址並設定為寫入狀態
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;===========================================================
I2C_WRITE_ADR:
    CLR    SDA
    SET    ACK
    MOV    COUNTD,#8
    MOV    ADR,#11100010B    ;設定寫入之ROM及其位址,狀態為寫入
    CALL    I2C_START
IWA    RLC    ADR
    MOV    SDA,C
    SETB    SCL        ;資料傳輸完SCL須為高準位
    CLR    SCL        ;資料傳輸時SCL須為低準位
    DJNZ    COUNTD,IWA
    CLR    ACK    
    SET    ACK
    RET    
;===========================================================
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;I2C    設定指定
ROM的位址並設定為讀出狀態
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;===========================================================
I2C_READ_ADR:
    CLR    SDA
    SET    ACK
    MOV    COUNTD,#8
    MOV    ADR,#11100011B    ;設定寫入之ROM及其位址,狀態為寫入
    CALL    I2C_START
IRA    RLC    ADR
    MOV    SDA,C
    SETB    SCL        ;資料傳輸完SCL須為高準位
    CLR    SCL        ;資料傳輸時SCL須為低準位
    DJNZ    COUNTD,IRA
    CLR    ACK
    SET    ACK    
    RET    
;===========================================================
;===============================
; I2C    I2C START CONDITION
;===============================
I2C_START:
    SETB    SCL
    SETB    SDL
    CLR    SDL    
    CLR    SCL    ;資料傳輸時SCL須為低準位
    RET
;===============================
;I2C     I2C STOP CONDITION    
;===============================
I2C_STOP:
    SETB    SCL    
    CLR    SDL    
    SETB    SDL
    CLR    SCL
    RET
;==============================
;I2C    I2C INPUT DATA STATE
;==============================
;==============================
;
;==============================    
;++++++++++++++++++++++++++++++++
;DELAY 40ms
;++++++++++++++++++++++++++++++++
DLY40    MOV    R6,#100
DL0    MOV    R7,#200
    DJNZ    R7,$
    DJNZ    R6,DL
    RET
;++++++++++++++++++++++++++++++++
;DELAY 8ms
;++++++++++++++++++++++++++++++++
DLY8    MOV    R6,#20
DL1    MOV    R7,#200
    DJNZ    R7,$
    DJNZ    R6,DL1
    RET
;++++++++++++++++++++++++++++++++
;DELAY 160us
;++++++++++++++++++++++++++++++++
DLY16    MOV    R6,#80
    DJNZ    R6,$
    RET
;++++++++++++++++++++++++++++++++

;==============================
;====       STORE DATA       =========
;==============================
TAB1    DB    "4444"
    DB    "4444"
    DB    10H
TAB2    DB    "abcdABCD"
    DB    10H
    END
;======================================================================

Re: I2C PROBLEM IN ASSEMBLY(8051).Help me,please.
Quoted text here. Click to load it
It means that you have a word that your compiler doesn't understand.
First make sure that there are no spaces before ACK, SCL, SDA and COUNTD
otherwise the assembler will treat these as instructions (mnemonics) rather
than a logical name.

If that fails you should look up how to declare port bits. I have never
touched an 8051 but my next guess would be that it doesn't like REG and
maybe you could replace "REG" with "bit".

Peter



Re: I2C PROBLEM IN ASSEMBLY(8051).Help me,please.
First what assembler are you using.
Second try www.8052.com





Re: I2C PROBLEM IN ASSEMBLY(8051).Help me,please.
Hi!
In case the REG command, you must previously define the Port2 address, and
than define your bits.
For example:

P2   EQU    0A0H   ; define real port address

SDA  REG    P2.0   ; at now we can define our signals
...
..

Best regards!





Re: I2C PROBLEM IN ASSEMBLY(8051).Help me,please.
Hi!
In case the REG command, at first, you must define the port address, and
than define bits.
For example:

P2      EQU     0A0H    ; real port address

ACK    REG    P2.0    ;I2C ACKNOWLEDGE
SCL    REG    P2.1    ;I2C SERIAL CLOCK
SDA    REG    P2.2    ;I2C SERIAL DATA

Best regards!




Site Timeline