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

📄 2.txt

📁 DS1302应用,PDF
💻 TXT
📖 第 1 页 / 共 3 页
字号:
        call    wbyte
        movf    indf,W
        call    wbyte
        incf    fsr
        incf    count4
        incf    count4
        decfsz  timer3
        goto    wc
        bcf     CLKRST          ;assert RST
        return

;
; Read calendar clock
;


rclock  bcf     SCLK            ;negate clock
        nop
        nop
        nop
        nop
        bcf     CLKDATA         ;negate I/O
        bsf     CLKRST          ;negate RST
        bsf     status,rp0      ;I/O dataq line set to output
        bcf     trisa,dataq
        bcf     status,rp0
        movlw   0xBF            ;burst read clock registers
        call    wbyte
        bsf     status,rp0      ;I/O dataq line set to input
        bsf     trisa,dataq
        bcf     status,rp0
        movlw   second
        movwf   fsr
        call    rbyte
        call    rbyte
        call    rbyte
        call    rbyte
        call    rbyte
        call    rbyte
        call    rbyte
        bcf     CLKRST          ;assert RST
        return

wbyte   movwf   timer2
        movlw   8
        movwf   timer1
wbit    bcf     SCLK
        btfss   timer2,0
        bcf     CLKDATA
        btfsc   timer2,0
        bsf     CLKDATA
        nop
        nop                     ;data to clock setup
        nop
        bsf     SCLK
        rrf     timer2
        decfsz  timer1
        goto    wbit
        return

rbyte   movlw   8
        movwf   timer1
rbit    bcf     SCLK
        nop
        nop                     ;clock to data delay
        rrf     indf
        bcf     indf,7
        btfsc   CLKDATA
        bsf     indf,7
        bsf     SCLK
        nop
        nop
        decfsz  timer1
        goto    rbit
        incf    fsr
        return
;********************************************specific rtc ds1302 routines end

;********************************************specific adc mc14433 routines start
read_adc        ;capture adc data, bcd digits ds1..ds4
                        bsf     status,rp0
                        bsf     trisb,eoc       ;ensure eoc is an INPUT
                        bcf     status,rp0             sp;                                
read_adc1               btfss   EOC
                        goto    read_adc1       ;loop till eoc HI

                bsf     status,rp0      ;closed ie end-of-test TRIP condition
                bcf     trisb,eoc       ;make eoc an output
                bcf     status,rp0
                bcf     EOC             ;and pull it LO, ie freeze dro

                        call    delay_200us     ;read ds1 only in middle
                        call    delay_200us     ;read ds1 only in middle
                        call    delay_200us     ;read ds1 only in middle
                        movf    portb,w
                        movwf   ds1             ;most sig. digit sp;                      
                        call    delay_200us     ;read in middle of valid
                        call    delay_200us
                        movf    portb,w
                        movwf   ds2             ;next sig. digit sp;                      
                        call    delay_200us     ;read in middle of valid
                        call    delay_200us     ;read in middle of valid
                        call    delay_200us
                        movf    portb,w
                        movwf   ds3             ;next sig. digit sp;                      
                        call    delay_200us     ;read in middle of valid
                        call    delay_200us
                        call    delay_200us     ;read in middle of valid
                        movf    portb,w
                        movwf   ds4             ;least sig. digit&nbspbsp;                     
                ;now massage each of these
                        btfss   ds1,4           ;check the Q3 bit as `raw'
                        goto    $+4             ;ms digit only reres
                        movlw   0x30            ; ascii 0 
                        movwf   ds1
                        goto    $+3
                        movlw   0x31            ; or ascii 1
                        movwf   ds1
                        movlw   00001111b
                        rrf     ds2,same
                        andwf   ds2,same        ;to 0000 xxxx  in bcd
                        movlw   0x30
                        addwf   ds2,same        ;bcd to ascii numeral    &n;      
                        movlw   00001111b
                        rrf     ds3,same
                        andwf   ds3,same        ;to 0000 xxxx  in bcd
                        movlw   0x30
                        addwf   ds3,same        ;bcd to ascii numeral    &n;      
                        movlw   00001111b
                        rrf     ds4,same
                        andwf   ds4,same        ;to 0000 xxxx  in bcd
                        movlw   0x30
                        addwf   ds4,same        ;bcd to ascii numeral    &n;      
                return
;********************************************specific adc mc14433 routines end

;********************************************specific rs232 routines start

;TXBYTE: sends 1 byte @9600 baud, rs232
;uses 1ram, 15(16) rom, 1043 cycles, enters with data in w, exits with w trashed
;pic xtal clock at 4mhz. The routine sets the data format a 8N1 = 8 data, no
;parity, 1 start, 1 stop bits.
;increase the .10 (=10 dec)value after `movwf temp' if you need more stop bits.
;this will affect the cycle times mentioned.
;note that w is used as the delay counter.
;the output data is `inverted' ie a mark is LO and space is HI
;this can be reversed to `correct logic' by swopping the bcf/bsf instructions.
;- in the txloop ONLY, stupoid, JS
;copyright (C) 1995 Dwayne Reid. May be freely used so long as this copyright
;notice is retained.
txbyte                  ;send byte in w at 9600 baud (4mhz osc), 8N1
                movwf   tx_buff
                movlw   0x0A            ;reid's setting=0x0A=10dec =8data+1start+1 stop (incr for more stop bits)
                bcf     status,c        ;initial `0' (=HI) for start bit.
txloop                                  ;bit time=104.167 uSec  
                btfsc   status,c
                bcf     SERTX           ;nb-js, there is no mirror here! reid's = bsf
                btfss   status,c        ;let's suck it & see, maybe no need
                bsf     SERTX           ;reid's = bcf
dloop                                   ;95 clk cycle delay
                goto    $+1             ;2-cycle NOP in 1 instruction!
                addlw   00010000b       ;increment upper nibble
                btfss   status,c        ;delay=6n-1(1 less when falls thru)
                goto    dloop           ;loop 16 times
                addlw   -1              ;dec w,valid z,c=1 if w>=0 after decrement
                rrf     tx_buff,same    ;carry will be set-shifted in as stop bit
                btfss   status,z
                goto    txloop          ;txloop is 104 cycles
        return

powerup_dump    ;dumps startup initial lines to printer
                call    cr_lf           ;set head to newline, left
                clrf    pr01            ;reset pointer offset to 0
                call    hole_space      ;10 spaces right
powerup_dump1
                movf    pr01,w
                call    powerup_table1
                call    txbyte
                incf    pr01,same
                movlw   40              ;decimal 40, lets try decimal today
                xorwf   pr01,w
                btfss   status,z
                goto    powerup_dump1
                call    cr_lf   
                call    cr_lf           ;send a blank line
                call    crush_dump      ;send out date, index etc
        return

crush_dump              ;dumps data line to printer
                call    rclock          ;fetch rtc up-to-date regs
                call    read_eeprom     ;fetch the current non-vol index
                call    hole_space      ;put 10 chars
                movlw   0x90
                subwf   year,w
                btfss   status,c        ;c cleared if we're in 19xx years
                goto    crush_dump1
                movlw   0x31            ;=1 in ascii
                call    txbyte          ;       char1
                movlw   0x39            ;=9 in ascii
                call    txbyte          ;       char2
                goto    crush_dump2
crush_dump1                             ;or...  year 2000+
                movlw   0x32            ;=2 in ascii
                call    txbyte          ;       char1
                movlw   0x30            ;=0 in ascii
                call    txbyte          ;       char2
crush_dump2
                movf    year,w          
                call    packBCD_to_ascii        ;char3...char4
                movlw   0x2F            ; /
                call    txbyte          ;       char5
                movf    month,w
                call    packBCD_to_ascii        ;char6...char7
                movlw   0x2F            ; /
                call    txbyte          ;       char8
                movf    date,w
                call    packBCD_to_ascii        ;char9...char10
                movlw   0x20            ; sp
                call    txbyte          ;       char11
                movlw   0x20            ; sp
                call    txbyte          ;       char12
                movf    hour,w
                call    packBCD_to_ascii        ;char13...char14
                movlw   0x3A            ;
                call    txbyte          ; :     char15
                movf    minute,w
                call    packBCD_to_ascii        ;char16...char17
                movlw   0x3A            ; 
                call    txbyte          ; :     char18
                movf    second,w
                call    packBCD_to_ascii        ;char19...char20           sp;    
                movlw   0x20            ; sp
                call    txbyte          ;       char21
                movlw   0x20            ; sp
                call    txbyte          ;       char22
                clrf    buff_4          ;fetch eeprom index regs
                movf    samp_index3,w   ;most sig eeprom
                movwf   buff_3          ;load input buffers for binary to bcd
                movf    samp_index2,w   ;next sig eeprom
                movwf   buff_2          ;load input buffers for binary to bcd
                movf    samp_index1,w   ;least sig eeprom
                movwf   buff_1          ;load input buffers for binary to bcd
                call    bin2bcd         
                movf    temp_c,w        
                call    packBCD_to_ascii        ;char23...char24           sp;    
                movf    temp_d,w
                call    packBCD_to_ascii        ;char25...char26        
                movf    temp_e,w
                call    packBCD_to_ascii        ;char27...char28        
                movlw   0x20            ; sp
                call    txbyte          ;       char29
                movlw   0x20            ; sp
                call    txbyte          ;       char30
        movf    ds1,w           ;most sig. adc ascii numeral
        call    txbyte          ;       char31
        movf    ds2,w
        call    txbyte          ;       char32          
        movf    ds3,w
        call    txbyte          ;       char33          
        movf    ds4,w
        call    txbyte          ;       char34              sp;   
                movlw   0x20            ; sp
                call    txbyte          ;       char35
                movlw   0x6B            ; k
                call    txbyte          ;       char36
                movlw   0x4E            ; N
                call    txbyte          ;       char37
                movlw   0x20            ; sp
                call    txbyte          ;       char38
                movlw   0x20            ; sp
                call    txbyte          ;       char39
                movlw   0x20            ; sp
                call    txbyte          ;       char40
                call    cr_lf           ;end of line,  
        return

packBCD_to_ascii        ;takes packed bcd byte in w -> ascii ->tx rs232 HI nibble first
                movwf   scratch         ;eg w=98 scratch=98 for years, say
                movwf   scratch1
                swapf   scratch,same    ;eg scratch=89
                movlw   0x0F            ;mask nibble for years 10s
                andwf   scratch,same    ;eg scratch=09
                movlw   0x30            ;convert to ascii
                addwf   scratch,w       ;eg scratch=39 , produces years 10s , in ascii, in w
                call    txbyte          ;       char out  HI nibble
                movf    scratch1,w      ;eg year=98
                movwf   scratch         ;eg scratch=98
                movlw   0x0F            ;mask nibble for years units       &nbspbsp;                   
                andwf   scratch,same    ;eg scratch=08
                movlw   0x30            ;convert to ascii
                addwf   scratch,w       ;eg scratch=38          ="8"
                call    txbyte          ;       char out LO nibble
        return          

cr_lf           ;carriage return + line feed to rs232 port
                        movlw   0x0D            ;CR
                        call    txbyte
                        movlw   0x0A            ;LF
                        call    txbyte
                return          

hole_space      ;space print 10 chars from left of page
                movlw   0x0A
                movwf   scratch
                movlw   0x20    ;ascii `space'  
                call    txbyte
                decfsz  scratch,same
                goto    $-3
        return  
;********************************************specific rs232 routines end

;*********************************************specific bcd handling routines start

;Date:    Mon, 16 Mar 1998 14:18:12 -0600
;From:    Bob Fehrenbach 
;Subject: Re: 32 bits binary to BCD convert?
;>Does anyone know how to convert 32 bits binary to BCD format?
;There probably faster routines but this should do the job.
    ;Binary - BCD   32 bits
    ;Input in buff_4|buff_3|buff_2|buff_1,
    ;
    ;Converts to *packed* bcd in temp_a, temp_b, temp_c, temp_d and temp_e
    ;with the MSD temp_a.
    ;Handles full range:  ff ff ff ff -> 4,294,967,296
    ;Also uses temp_f and count.
    ;2940 cycles including call and return.

bin2bcd:
   bcf     status, c
   movlw   32
   movwf   count5
   clrf    temp_a
   clrf    temp_b
   clrf    temp_c
   clrf    temp_d
   clrf    temp_e
bin2bcd_loop:
   rlf     buff_1, same
   rlf     buff_2, same
   rlf     buff_3, same

⌨️ 快捷键说明

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