<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 使用PIC讀寫(xiě)1-wire EEPROM DS2430的實(shí)例

          使用PIC讀寫(xiě)1-wire EEPROM DS2430的實(shí)例

          作者: 時(shí)間:2011-05-17 來(lái)源:網(wǎng)絡(luò) 收藏

          banksel INTCON
          bsf INTCON,GIE ;; GIE=1
          bcf INTCON,PEIE ;;
          bcf INTCON,T0IE ;; T0IE=1
          bcf INTCON,INTE ;; GP2 interrupt enable
          ; bcf INTCON,RAIE ;; disable GPIO port change interrupt

          ;------------------------------------------------
          ; clear int flag
          ;------------------------------------------------
          bcf INTCON,T0IF
          bcf INTCON,INTF
          ; bcf INTCON,RAIF
          bcf PIR1,TMR1IF
          ; movlw H'00'
          ; movwf INTCON

          banksel PIE1
          bcf PIE1,EEIE
          bcf PIE1,ADIE
          bcf PIE1,CMIE
          bsf PIE1,TMR1IE ; enable Timer 1, timer 1 use as delay
          return

          ;--------------------------------------------
          ; Tx BYTE to 2430A
          ; LSB first, MSB last
          ;--------------------------------------------
          TxBYTE
          movlw .8
          movwf LoopCounter
          bcf CARRY
          RollTxB
          banksel TxB
          rrf TxB,F
          btfss CARRY
          goto LoBit
          call TxHi
          goto bloop
          LoBit
          call TxLo
          bloop
          banksel LoopCounter
          decfsz LoopCounter,F
          goto RollTxB
          return

          ;;---------------------------------------------------------
          TxL
          call SetLo
          call delay60us ; min 60 us
          call SetHi
          nop ; recovery time min 1us
          nop
          return
          ;-----------------------------------------------------------
          ; tx hi
          ;-----------------------------------------------------------

          TxHi:
          call SetLo ;1ustlow115us
          nop
          call SetHi
          call delay60us
          nop
          nop ;recovery time min 1us
          return


          ;;---------------------------------------------------------------------------
          ;; toggle the RC0 as input and the bus was pulled up by externl resistor
          ;; application default PCDir.Bit0 to output
          ;;---------------------------------------------------------------------------
          SetHi:
          bsf PBDir,Bit2
          movf PBDir,w
          ; bsf bank1
          banksel TRISB
          movwf TRISB
          return
          ;;----------------------------------------------------------------------------
          ;; clear register file RC0
          ;;----------------------------------------------------------------------------

          SetL
          banksel PORTB
          bcf PORTB,Bit2 ; data lo
          bcf PBDir,Bit2 ; direction out
          movf PBDir,W
          banksel TRISB
          movwf TRISB
          return

          ;---------------------------
          ; fix delay 60 us
          ; 0xffff - 8 = 0xfff7
          ;---------------------------
          delay60us
          banksel PIR1
          bcf PIR1,TMR1IF
          movlw H'EE'
          movwf TMR1L
          movlw H'FF'
          movwf TMR1H
          bsf T1CON,TMR1ON
          btfss PIR1,TMR1IF
          goto $-1
          bcf T1CON,TMR1ON
          bcf PIR1,TMR1IF
          return

          ;---------------------------
          ; fix delay 500 us
          ; 0xffff - 0x3e = 0xffc1
          ;---------------------------
          delay500us

          banksel PIR1
          bcf PIR1,TMR1IF
          movlw H'C0'
          movwf TMR1L
          movlw H'FF'
          movwf TMR1H
          bsf T1CON,TMR1ON
          btfss PIR1,TMR1IF
          goto $-1
          bcf T1CON,TMR1ON
          bcf PIR1,TMR1IF
          return

          ;---------------------------
          ; fix delay 100 ms
          ; 0xffff - 30d4 = 0xcf26
          ;---------------------------
          delay100ms
          banksel PIR1
          bcf PIR1,TMR1IF
          movlw H'26'
          movwf TMR1L
          movlw H'CF'
          movwf TMR1H
          bsf T1CON,TMR1ON
          btfss PIR1,TMR1IF
          goto $-1
          bcf T1CON,TMR1ON
          bcf PIR1,TMR1IF
          return

          org H'800'
          VendorTable
          movf Offset,W ; Save offset in Temp
          andlw H'ff'
          addwf PCL,f ; PCL = PCL+Offset

          dt MiCallChip,0
          end


          上一頁(yè) 1 2 3 下一頁(yè)

          評(píng)論


          相關(guān)推薦

          技術(shù)專(zhuān)區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();