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

📄 base1.sdi

📁 代码保护功能处于持续发展中。Microchip 承诺将不断改进产品的代码保护功能。任何试图破坏Microchip 代码保护功能的行为均可视 为违反了《数字器件千年版权法案(Digital Mille
💻 SDI
📖 第 1 页 / 共 3 页
字号:
00000101,3003,,        MOVLW   B'00000011'     ; Analogue input setup code
00000102,009F,,        MOVWF   ADCON1          ; Left justify, analogue
00000103,1283 1303,,        BANKSEL ADCON0          ; Bank 0
,,,
,,,; Sample & hold settling delay 20us .........................
,,,
00000105,3007,getADC,getADC  MOVLW   007             ;
00000106,00A0,,        MOVWF   Count           ;
00000107,0BA0,down,down    DECFSZ  Count           ;
00000108,2907,,        GOTO    down            ;
,,,
,,,; Read input ................................................
,,,
00000109,151F,,        BSF     ADCON0,GO       ; start ADC..
0000010A,191F,wait,wait    BTFSC   ADCON0,GO       ; and wait..
0000010B,290A,,        GOTO    wait            ; for finish
0000010C,081E,,        MOVF    ADRESH,W        ; store result
,,,
,,,; Set level indicator .......................................
,,,
0000010D,00A2,,        MOVWF   Vin             ; Get input volts
0000010E,3080,,        MOVLW   080             ; Half scale
0000010F,1403,,        BSF     STATUS,C        ; Compare
00000110,02A2,,        SUBWF   Vin             ;
00000111,1803,,        BTFSC   STATUS,C        ;
00000112,2916,,        GOTO    ledon           ; input high
,,,
00000113,1086,,        BCF     PORTB,1         ; below 1.25V
00000114,081E,,        MOVF    ADRESH,W        ; reload result
00000115,0008,,        RETURN                  ; done
00000116,1486,ledon,ledon   BSF     PORTB,1         ; above 1.25V
00000117,081E,,        MOVF    ADRESH,W        ; reload result
00000118,0008,,        RETURN                  ; done
,,,
,,,; ...........................................................
,,,
,,,;
,,,;----------------------------------------------------------
,,,; SERIAL MEMORY DRIVER
,,,;       Write high address into 'HiReg' 00-3F
,,,;       Write low address into 'LoReg' 00-FF
,,,;       Load data send into 'SenReg'
,,,;       Read data received from 'RecReg'
,,,;
,,,;       To initialise call 'inimem'
,,,;       To write call 'writmem'
,,,;       To read call 'readmem'
,,,;
,,,        INCLUDE "SERMEM.INC"
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,;       SERMEM.INC      MPB     14-1-06
,,,;
,,,;       24XX128 Serial Memory Driver
,,,;       Include file for demo system
,,,;
,,,;       Version: under development
,,,;
,,,;       TO WRITE A BYTE
,,,;       Load data into SenReg
,,,;       Load address into Hireg,Loreg
,,,;       Call writmem
,,,;
,,,;       TO READ A BYTE
,,,;       Load address into Hireg,Loreg
,,,;       Call readmem
,,,;       Read data from RecReg
,,,;
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,
,,,; Data, address & control registers ;;;;;;;;;;;;;;;;;;;;;
,,,
,,,SenReg  EQU     0x60            ; writem data store
,,,HiReg   EQU     0x61            ; High address store
,,,LoReg   EQU     0x62            ; Low address store
,,,RecReg  EQU     0x63            ; Receive data store
,,,ConReg  EQU     0x64            ; Control byte store
,,,
,,,
,,,; Initialisation sequence ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
00000119,0000,inimem,inimem  NOP                     ;
0000011A,1683 1303,,        BANKSEL SSPCON2         ;
0000011C,3060,,        MOVLW   b'01100000'     ; Set ACKSTAT,ACKDT bits
0000011D,0091,,        MOVWF   SSPCON2         ; Reset SEN,ACK bits
0000011E,3080,,        MOVLW   b'10000000'     ;
0000011F,0094,,        MOVWF   SSPSTAT         ; Speed & signal levels
00000120,3013,,        MOVLW   0x13            ; Clock = 50kHz
00000121,0093,,        MOVWF   SSPADD          ; Load baud rate count-1
00000122,1283 1303,,        BANKSEL SSPCON          ;
00000124,3008,,        MOVLW   b'00001000'     ;
00000125,0094,,        MOVWF   SSPCON          ; Set mode & disable
00000126,118C,,        BCF     PIR1,SSPIF      ; clear interrupt flag
,,,
,,,; Initialise TIMER0 for write delay ---------------------
,,,
00000127,1683 1303,,        BANKSEL OPTION_REG      ;
00000129,30C5,,        MOVLW   B'11000101'     ; TIMER0 setup code
0000012A,0081,,        MOVWF   OPTION_REG      ; Internal clock,1/64
0000012B,1283 1303,,        BANKSEL TMR0
0000012D,0008,,        RETURN
,,,
,,,
,,,; MAIN ROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,; Write a test byte to given address ;;;;;;;;;;;;;;;;;;;;
,,,
0000012E,,writmem,writmem
0000012E,0000,,        NOP                     ; Setup
0000012F,1683 1303,,        BANKSEL TRISC           ; port
00000131,30FF,,        MOVLW   b'11111111'     ; for
00000132,0087,,        MOVWF   TRISC           ; SSP
00000133,1283 1303,,        BANKSEL PORTC           ; operation
00000135,1694,,        BSF     SSPCON,SSPEN    ; Enable serial port
,,,
00000136,30A0,,        MOVLW   0xA0            ; Control byte for WRITE
00000137,00E4,,        MOVWF   ConReg          ; Load it
00000138,2160,,        CALL    sencon          ; write control byte
00000139,216C,,        CALL    senadd          ; write address bytes
0000013A,2174,,        CALL    sendat          ; write data byte
0000013B,2177,,        CALL    senstop         ; write stop bit
0000013C,2184,,        CALL    waitm           ; Wait 10ms for write
,,,
0000013D,1294,,        BCF     SSPCON,SSPEN    ; Disable serial port
0000013E,0008,,        RETURN
,,,
,,,
,,,; Read the byte from given address ;;;;;;;;;;;;;;;;;;;;;;
,,,
0000013F,,readmem,readmem
0000013F,0000,,        NOP                     ; Setup
00000140,1683 1303,,        BANKSEL TRISC           ; port
00000142,30FF,,        MOVLW   b'11111111'     ; for
00000143,0087,,        MOVWF   TRISC           ; SSP
00000144,1283 1303,,        BANKSEL PORTC           ; operation
00000146,1694,,        BSF     SSPCON,SSPEN    ; Enable serial port
,,,
00000147,30A0,,        MOVLW   0xA0            ; Control byte to WRITE
00000148,00E4,,        MOVWF   ConReg          ; address to memory
00000149,2160,,        CALL    sencon          ; write control byte
0000014A,216C,,        CALL    senadd          ; write address bytes
0000014B,2177,,        CALL    senstop         ; Stop
,,,
0000014C,30A1,,        MOVLW   0xA1            ; Control byte to READ
0000014D,00E4,,        MOVWF   ConReg          ; data from memory
0000014E,2160,,        CALL    sencon          ; write control byte
0000014F,1683 1303,,        BANKSEL SSPCON2
00000151,1591,,        BSF     SSPCON2,RCEN    ; Enable receive mode
00000152,1C14,war,war     BTFSS   SSPSTAT,BF      ; Check ...
00000153,2952,,        GOTO    war             ; for read done
00000154,217D,,        CALL    senack          ; write NOT acknowledge
00000155,2177,,        CALL    senstop         ; write stop bit
,,,
00000156,0813,,        MOVF    SSPBUF,W        ; Read receive buffer
00000157,00E3,,        MOVWF   RecReg          ; and store it
00000158,1294,,        BCF     SSPCON,SSPEN    ; Disable serial port
00000159,0008,,        RETURN
,,,
,,,
,,,; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,; Load buffer for write to memory -----------------------
,,,
0000015A,0000,writem,writem  NOP                     ; Select..
0000015B,1283 1303,,        BANKSEL SSPBUF          ; .. bank
0000015D,0093,,        MOVWF   SSPBUF          ; write address/data
0000015E,2191,,        CALL    wint            ; Wait until sent
0000015F,0008,,        RETURN                  ; done
,,,
,,,; Routines to write, start, control, address, data, stop
,,,
00000160,0000,sencon,sencon  NOP                     ; GENERATE START BIT
00000161,1283 1303,,        BANKSEL PIR1
00000163,118C,,        BCF     PIR1,SSPIF      ; Clear interrupt flag
00000164,1683 1303,,        BANKSEL SSPCON2         ; select register page
00000166,1711,,        BSF     SSPCON2,ACKSTAT ; Set acknowledge flag
00000167,1411,,        BSF     SSPCON2,SEN     ; Generate start bit
00000168,2191,,        CALL    wint            ; wait till done
00000169,0864,,        MOVF    ConReg,W        ; write CONTROL BYTE
0000016A,215A,,        CALL    writem          ; Memory ID & address
0000016B,0008,,        RETURN                  ; done
,,,
,,,; Write address to memory -------------------------------
,,,
0000016C,0000,senadd,senadd  NOP
0000016D,1283 1303,,        BANKSEL SSPCON          ; writem ADDRESS BYTES
0000016F,0861,,        MOVF    HiReg,W         ; load address high byte
00000170,215A,,        CALL    writem          ; and write
00000171,0862,,        MOVF    LoReg,W         ; load address low byte
00000172,215A,,        CALL    writem          ; and write
00000173,0008,,        RETURN
,,,
,,,; Write data to memeory ---------------------------------
,,,
00000174,0860,sendat,sendat  MOVF    SenReg,W        ; Load data
00000175,215A,,        CALL    writem          ; and write
00000176,0008,,        RETURN                  ; done
,,,
,,,; Genearte stop bit -------------------------------------
,,,
00000177,0000,senstop,senstop NOP
00000178,1683 1303,,        BANKSEL SSPCON2         ; GENERATE STOP BIT
0000017A,1511,,        BSF     SSPCON2,PEN     ; Generate stop bit
0000017B,2191,,        CALL    wint            ; wait till done
0000017C,0008,,        RETURN                  ; done
,,,
,,,; Generate acknowledge ----------------------------------
,,,
0000017D,0000,senack,senack  NOP
0000017E,1683 1303,,        BANKSEL SSPCON2
00000180,1691,,        BSF     SSPCON2,ACKDT   ; Set ack. bit high
00000181,1611,,        BSF     SSPCON2,ACKEN   ; Initiate ack.sequence
00000182,2191,,        CALL    wint            ; Wait for ack. done
00000183,0008,,        RETURN                  ; done
,,,
,,,; Wait for write to finish ------------------------------
,,,
00000184,0000,waitm,waitm   NOP
00000185,1283 1303,,        BANKSEL TMR0            ; WAIT FOR WRITE DONE
00000187,309C,,        MOVLW   d'156'          ; Set starting value
00000188,0081,,        MOVWF   TMR0            ; and load into timer
00000189,1283 1303,,        BANKSEL INTCON          ; 64 x 156us = 10ms
0000018B,110B,,        BCF     INTCON,T0IF     ; Reset timer out flag
0000018C,1D0B,wem,wem     BTFSS   INTCON,T0IF     ; Wait 10ms
0000018D,298C,,        GOTO    wem             ; for timeout
0000018E,1283 1303,,        BANKSEL TMR0            ; default bank
00000190,0008,,        RETURN                  ; Byte write done....
,,,
,,,; Wait for interrupt flag SSPIF for writem/recive done --
,,,
00000191,0000,wint,wint    NOP                     ; BANKSEL has no address
00000192,1283 1303,,        BANKSEL PIR1            ; Select bank
00000194,118C,,        BCF     PIR1,SSPIF      ; reset interrupt flag
00000195,0000,win,win     NOP
00000196,1D8C,,        BTFSS   PIR1,SSPIF      ; wait for..
00000197,2995,,        GOTO    win             ; ..transmit done
00000198,0008,,        RETURN                  ; done
,,,
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,;----------------------------------------------------------
,,,        END                     ; of source code

⌨️ 快捷键说明

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