⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i2cmem1.sdi

📁 proteus 仿真实例
💻 SDI
📖 第 1 页 / 共 2 页
字号:
00C5,2005,,                 call  set_sdo_high
00C6,201D,,                 call  wait_quarter_bit
00C7,2011,,                 call  set_clk_high
00C8,201D,,                 call  wait_quarter_bit
00C9,0807,,                 movf  PORTC,W
00CA,3980,,                 andlw (1<<SDO)
00CB,3A80,,                 xorlw (1<<SDO)
00CC,00B4,,                 movwf ack
00CD,201D,,                 call  wait_quarter_bit
00CE,2017,,                 call  set_clk_low
00CF,201D,,                 call  wait_quarter_bit
00D0,0008,,                 return
,,,
,,,;-----------------------------------------------------------
00D1,1283,rd_bit,rd_bit           bcf    STATUS,RP0
00D2,2005,,                 call   set_sdo_high
00D3,2017,,                 call   set_clk_low
00D4,2022,,                 call   wait_half_bit
00D5,2011,,                 call   set_clk_high
00D6,201D,,                 call   wait_quarter_bit
00D7,0807,,                 movf   PORTC,W
00D8,3980,,                 andlw  (1<<SDO)
00D9,1903,,                 btfsc  STATUS,Z
00DA,28DD,,                 goto   rd_bit_clear
00DB,0833,,                 movf   bit,W
00DC,04B2,,                 iorwf  byte,F
00DD,201D,rd_bit_clear,rd_bit_clear     call   wait_quarter_bit
00DE,2017,,                 call   set_clk_low
00DF,0008,,                 return
,,,
,,,;-----------------------------------------------------------
00E0,3000,rd_byte,rd_byte          movlw  0x00
00E1,00B2,,                 movwf  byte
00E2,3080,,                 movlw  0x80
00E3,00B3,,                 movwf  bit
,,,
00E4,20D1,rbyte0,rbyte0           call   rd_bit
00E5,1003,,                 bcf    STATUS,C
00E6,0CB3,,                 rrf    bit,F
00E7,08B3,,                 movf   bit,F
00E8,1D03,,                 btfss  STATUS,Z
00E9,28E4,,                 goto   rbyte0
00EA,0832,,                 movf   byte,W
00EB,0008,,                 return
,,,
,,,;-----------------------------------------------------------
,,,; Write W register to PORTD and hang.
00EC,1283,wr_error,wr_error         bcf   STATUS,RP0
00ED,0088,,                 movwf PORTD
00EE,1683,,                 bsf   STATUS,RP0
00EF,0188,,                 clrf  TRISD
00F0,1283,,                 bcf   STATUS,RP0
,,,
00F1,1405,wre_flash,wre_flash        bsf    PORTA,0
00F2,30FF,,                 movlw  0xFF
00F3,2116,,                 call   longwait
00F4,30FF,,                 movlw  0xFF
00F5,2116,,                 call   longwait
00F6,1005,,                 bcf    PORTA,0
00F7,30FF,,                 movlw  0xFF
00F8,2116,,                 call   longwait
00F9,30FF,,                 movlw  0xFF
00FA,2116,,                 call   longwait
00FB,28F1,,                 goto   wre_flash
00FC,0008,,                 return
,,,
,,,;-----------------------------------------------------------
,,,; Write W register to PORTD and hang.
00FD,1283,wr_result,wr_result        bcf   STATUS,RP0
00FE,0088,,                 movwf PORTD
00FF,1683,,                 bsf   STATUS,RP0
0100,0188,,                 clrf  TRISD
0101,1283,,                 bcf   STATUS,RP0
,,,
0102,1405,wrr_flash,wrr_flash        bsf    PORTA,0
0103,3030,,                 movlw  0x30
0104,210A,,                 call   vlongwait
0105,1005,,                 bcf    PORTA,0
0106,3003,,                 movlw  0x03
0107,210A,,                 call   vlongwait
0108,2902,,                 goto   wrr_flash
0109,0008,,                 return
,,,
,,,;-----------------------------------------------------------
010A,00B5,vlongwait,vlongwait        movwf  lc1
010B,30FF,vlw1,vlw1             movlw  0xFF
010C,00B6,,                 movwf  lc2
010D,30FF,vlw2,vlw2             movlw  0xFF
010E,00B7,,                 movwf  lc3
010F,0BB7,vlw3,vlw3             decfsz lc3,F
0110,290F,,                 goto   vlw3
0111,0BB6,,                 decfsz lc2,F
0112,290D,,                 goto   vlw2
0113,0BB5,,                 decfsz lc1,F
0114,290B,,                 goto   vlw1
0115,0008,,                 return
,,,
,,,;-----------------------------------------------------------
0116,00B5,longwait,longwait         movwf  lc1
0117,30FF,lw1,lw1              movlw  0xFF
0118,00B6,,                 movwf  lc2
0119,0BB6,lw2,lw2              decfsz lc2,F
011A,2919,,                 goto   lw2
011B,0BB5,,                 decfsz lc1,F
011C,2917,,                 goto   lw1
011D,0008,,                 return
,,,
,,,;-----------------------------------------------------------
011E,291E,hang,hang             goto  hang
,,,
,,,
,,,;===========================================================
011F,2027,start,start            call  init
0120,2061,,                 call  wr_reset
,,,
,,,
0121,1283,,                 bcf   STATUS,RP0
0122,0185,,                 clrf  PORTA
0123,0188,,                 clrf  PORTD
,,,
0124,1683,,                 bsf   STATUS,RP0
0125,3006,,                 movlw 0x06
0126,009F,,                 movwf ADCON1
0127,3020,,                 movlw 0x20
0128,0085,,                 movwf TRISA
0129,0188,,                 clrf  TRISD
,,,
012A,1283,,                 bcf   STATUS,RP0
012B,0185,,                 clrf  PORTA
012C,01B0,,                 clrf  address
012D,01B1,,                 clrf  value
,,,
,,,                 ; Test RA5 to see if we do writes:
012E,1E85,,                 btfss PORTA,5
012F,2952,,                 goto  reset_addr
,,,
,,,                 ; Do start condition:
0130,202E,main_wr_loop:,main_wr_loop:    call   wr_start
,,,
,,,                 ; Send write command:
0131,30A6,,                 movlw  0xA6
0132,20A5,,                 call   wr_byte
0133,3001,,                 movlw  0x01
0134,08B4,,                 movf   ack,F
0135,1903,,                 btfsc  STATUS,Z
0136,20EC,,                 call   wr_error
,,,
,,,                 ; Send address:
0137,0830,,                 movf   address,W
0138,20A5,,                 call   wr_byte
0139,3002,,                 movlw  0x02
013A,08B4,,                 movf   ack,F
013B,1903,,                 btfsc  STATUS,Z
013C,20EC,,                 call   wr_error
,,,
,,,                 ; Send value:
013D,0831,,                 movf   value,W
013E,20A5,,                 call   wr_byte
013F,3003,,                 movlw  0x03
0140,08B4,,                 movf   ack,F
0141,1903,,                 btfsc  STATUS,Z
0142,20EC,,                 call   wr_error
,,,
,,,                 ; Do stop. This starts the write cycle.
0143,2037,,                 call   wr_stop
,,,
,,,                 ; Now poll for acknowledge:
0144,202E,poll_for_ack,poll_for_ack     call   wr_start
0145,30A6,,                 movlw  0xA6
0146,20A5,,                 call   wr_byte
0147,3004,,                 movlw  0x04
0148,08B4,,                 movf   ack,F
0149,1903,,                 btfsc  STATUS,Z
014A,2944,,                 goto   poll_for_ack
,,,
,,,                 ; Increment address/data and loop round:
014B,0AB0,,                 incf   address
014C,0AB1,,                 incf   value
014D,1E30,,                 btfss  address,4
014E,2930,,                 goto   main_wr_loop
,,,
,,,                 ; Cancel sucessful poll command:
014F,2037,,                 call   wr_stop
,,,
0150,3010,wait,wait             movlw  0x10
0151,2116,,                 call   longwait
,,,
0152,,reset_addr,reset_addr       ; Generate start condition...
0152,202E,,                 call   wr_start
,,,
,,,                 ; Write command:
0153,30A6,,                 movlw  0xA6
0154,20A5,,                 call   wr_byte
0155,3005,,                 movlw  0x05
0156,08B4,,                 movf   ack,F
0157,1903,,                 btfsc  STATUS,Z
0158,20EC,,                 call   wr_error
,,,
,,,                 ; Send address:
0159,01B0,,                 clrf   address
015A,0830,,                 movf   address,W
015B,20A5,,                 call   wr_byte
015C,3006,,                 movlw  0x06
015D,08B4,,                 movf   ack,F
015E,1903,,                 btfsc  STATUS,Z
015F,20EC,,                 call   wr_error
,,,
,,,                 ; Send stop:
0160,2037,,                 call   wr_stop
,,,
0161,202E,read_bytes,read_bytes       call  wr_start
0162,30A7,,                 movlw  0xA7
0163,20A5,,                 call   wr_byte
0164,3007,,                 movlw  0x07
0165,08B4,,                 movf   ack,F
0166,1903,,                 btfsc  STATUS,Z
0167,20EC,,                 call   wr_error
,,,
0168,1485,,                 bsf    PORTA,1
0169,0000,,                 nop
016A,0000,,                 nop
016B,0000,,                 nop
016C,1085,,                 bcf    PORTA,1
,,,
,,,                 ; Do read:
016D,20E0,main_rd_loop,main_rd_loop     call   rd_byte
,,,
,,,                 ; Is this the value we expected?
016E,0830,,                 movf   address,W
016F,0232,,                 subwf  byte,W
0170,3008,,                 movlw  0x08
0171,1D03,,                 btfss  STATUS,Z
0172,20EC,,                 call   wr_error
,,,
,,,                 ; Increment address/data and loop round:
0173,0AB0,,                 incf   address
0174,1A30,,                 btfsc  address,4
0175,2978,,                 goto   done
,,,
,,,                 ; Not done yet so acknowledge byte and read next one:
0176,204C,,                 call   wr_ack
0177,296D,,                 goto   main_rd_loop
,,,
,,,
,,,                 ; Stop condition marks end of sequential read:
0178,2057,done,done             call   wr_no_ack
0179,2037,,                 call   wr_stop
,,,
,,,                 ; End of test:
017A,211E,,                 call hang
,,,
,,,                 END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -