导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→给你个汇遍程序片段

* 44790: 弱弱的问个问题,关于EEPROM

   Kuang-chingTsui 
Kuang-chingTsui发表的帖子 

 给你个汇遍程序片段
其中写EEPROM一段供你参考;其中的数据是我自己程序用的.你可以按照EEPROM的操作写读数据子程序.
关于IIC总线的那些子程序应当是完整的,注释我自己能看懂,不知你是否看得懂.有问题互相交流.
2402的从地址你自己定义

;IIC bus data section define:

bit_cnt     data 08h            ;Bit counter for iic routines
slv_addr    data 0ah            ;Slave address for iic routines


flags       data 28h             ;Location for bit flags
no_ack      bit flags.0         ;Iic no acknowledge flag
bus_fault   bit flags.1         ;Iic bus fault flag
iic_busy    bit flags.2         ;Iic bus is busy flag


eeprom_addr equ 0a6h            ;The address of 24c02

;a write data to eeprom subprograming

wri_rom:
            mov slv_addr,#eeprom_addr
            call master
            mov a,#18h
            call send_byte
            mov slv_addr,#eeprom_addr
            call master
            mov a,#01h
            call send_byte
            mov a,#01h
            call send_byte
            mov a,32h
            call send_byte
            mov a,33h
            call send_byte
            mov a,#02h
            call send_byte
            mov a,#02h
            call send_byte
            mov a,36h
            call send_byte
            mov a,37h
            call send_byte
            call send_stop
            call delay10

            ret


;iic bus operating subprograming

send_stop:  clr sda_pin         ;get sda ready for stop.
            setb scl_pin        ;set clock for stop.
            jnb scl_pin,$
            nop
            nop
            nop                 ;delay 3 cycles
            setb sda_pin        ;send iic stop.
                                ;delay satisfied via software.
            clr iic_busy        ;clear iic busy status.
            ret                 ;bus should now be released.

master:     setb iic_busy       ;indicate that 12c frame is in progress.
            clr no_ack          ;clear error status flags.
            clr bus_fault
            jnb scl_pin,fault   ;check for bus clear.
            jnb sda_pin,fault
            clr sda_pin         ;begin 12c start.
            nop
            nop
            nop                 ;delay_3_cycles.
            clr scl_pin         ;completa 12c start.
            nop
            nop
            nop                 ;delay_3_cycles.
            mov a,slv_addr      ;get slave address.
            call send_byte      ;send slave address.
            ret
fault:      setb bus_fault      ;set fault status.
            ret                 ;and return.

send_byte:  mov bit_cnt,#8      ;set bit count value.
sb_loop:    rlc a               ;send one data bit.
            mov sda_pin,c       ;put data bit on pin.
            setb scl_pin
            jnb scl_pin,$       ;drive scl high.
            nop
            nop
            nop                 ;delay_3_cycles.
            clr scl_pin         ;clear scl.
            nop
            nop
            nop                 ;delay_3_cycles.
            djnz bit_cnt,sb_loop;repeat until all bits sent.
            setb sda_pin        ;release data line for acknowledge.
            setb scl_pin
            jnb scl_pin,$       ;sent clock for acknowledge.
            nop
            nop
            nop
            nop                 ;delay_4_cycles.
            jnb sda_pin,sb_ex   ;cheek for valid acknowledge bit.
            setb no_ack         ;set status for no acknowledge.

sb_ex:      clr scl_pin         ;finish acknowledge bit.
            nop
            nop
            nop                 ;delay_3_cycles.
            ret                 ;return.


recv_byte:  mov bit_cnt,#8      ;set bit count.
rb_loop:    setb scl_pin
            jnb scl_pin,$       ;read one data bit.
            nop
            nop
            nop                 ;delay_3_cycles.
            mov c,sda_pin       ;get data bit from pin.
            rlc a               ;rotate bit into result byte.
            clr scl_pin         ;clear scl pin.
            nop
            nop
            nop                 ;delay_3_cycles.
            djnz bit_cnt,rb_loop;repeat accumulator.
            push acc            ;save accumulator.
            mov a,byte_cnt      ;copies byte count into a.
            cjne a,#1,rb_ack    ;check for last byte of frame.
            setb sda_pin        ;send no acknowledge on last byte.
            sjmp rb_aclk        ;no ack on last byte;jump to rb_aclk.
rb_ack:     clr sda_pin         ;send acknowledge bit.
rb_aclk:    setb scl_pin
            jnb scl_pin,$       ;send acknowledge clock.
            pop acc             ;restore accumulator.
            nop
            nop
            nop                 ;delay_3_cycles.
            clr scl_pin         ;clear scl pin.
            setb sda_pin        ;clear ackonwledge bit.
            nop
            nop
            nop
            nop                 ;delay_4_cycles.
            ret                 ;return from recv_byte.


;Delay subprograming

delay10:    mov r7,#28
delay10_lp: mov r6,#8fh
            djnz r6,$
            djnz r7,delay10_lp
            ret



发表时间:2003年11月14日16:58:54

  
回复该帖

本主题共有 19 帖,分页:>>>>>该主题的所有内容[19]条

 *树形目录 只列出部分跟帖的标题以及简单的摘要信息 该主题的部分跟帖如下:

  44791.[详细]呵呵,谢谢大家啊,很长知识的哦
摘要:......(无内容)
- [hatereg][887次] 2003年11月14日

  44804.[详细]24c08 除芯片地址定义与24c02不同外,读写方式是一样的。
摘要:......(无内容)
- [Kuang-chingTsui][3306次] 2003年11月14日

  44813.[详细]在写完address 后,等到应答。之后在发完启动信号,24c08就会发出位于addre..
摘要:在写完address 后,等到应答。之后在发完启动信号,24c08就会发出位于address的内容,为何还要写0xa1?......(95字)
- [guest][1097次] 2003年11月15日

[上一篇帖子]:呵呵,谢谢大家啊,很长知识的哦
[下一篇帖子]:你做过哪方面的硬件?几年?交个朋友。