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

📄 2313temp8.asm

📁 temp cont with assmbly code
💻 ASM
📖 第 1 页 / 共 3 页
字号:
        dec    BReg
        brne   ShiftB
        ret

;**********************************************
;* Search for devices on DS bus               *
;* Based on Dallas Semiconductor's ML6805     *
;* code.                                      *
;**********************************************
ROM1st:
        ldi    AReg,$41        ;Point Rom Search to top (1st part).
        mov    LastDis,AReg
        rcall  ROMSrch
        ret

ROMSrch:
        push   XL
        push   XH

        rcall  DSReset         ;Reset 1-wire bus.
        brcs   r_look
        rjmp   NoDev
r_look:
        ldi    AReg,$40        ;Prepare to find 64 bits of ROM data.
        mov    BitNum,AReg
        ldi    Count8,8        ;Initial value for eight counter.
        mov    LasDisCpy, LastDis ;Save copy of last dis. from last search.
        ldi    XL,low(romdta)
        ldi    XH,high(romdta) ;point to 1st byte of ROM data
        sts    romoff,XL       ;buffer in rombuff.
        sts    romoff+1,XH
        ldi    AReg,SearchROM  ;Get ROM search command in AReg.
        rcall  PutByte         ;Send ROM search command to DOW bus.

NxtRBit:
        clr    AReg
        clr    BReg
        rcall  GetBit          ;1st read time slot.
        rol    BReg            ;reg BReg, bit0 has first result
        rcall  GetBit          ;2nd read time slot.
        rol    AReg
        cpi    BReg,1          ;Was the first bit received 1?
        brne   no_or           ;Branch if it wasn't
        ori    AReg,2          ;Set bit 1 in AReg

no_or:
        cpi    AReg,3          ;See if error condition occurred.
        breq   NoDev           ;Abort if error.
        cpi    AReg,0          ;Was there a disagreement on bus.
        brne   nosave          ;Branch if there wasn't.
        cp     LasDisCpy,BitNum ;Compare last dis to current position.        
        brne   lwhere          ;If its not equal look some more.
        ldi    AReg,1          ;We've been on this path and sent a 0.
        rjmp   wrtBit          ;now lets send a 1.

lwhere:
        brcs   sLstBit         ;Stay on previous path.
        clr    AReg            ;Past last dis. fall to the right.
        rjmp   savedis         ;Send 0 to bus.
sLstBit:
        lds    XL,romoff       ;Get offset of ROM data buffer in
        lds    XH,romoff+1  
        ld     AReg,X          ;index register, and byte in AReg.
        andi   AReg,1          ;Isolate lsb of AReg.
        cpi    AReg,1          ;See if it was a 1.
        breq   wrtBit          ;Don't save as dis position if so.
savedis: 
        mov    LastDis,BitNum  ;Get current position in x register.
                               ;Save current last disagreement pos.
        rjmp   wrtBit          ;Send the write bit time slot.
nosave:
        ldi    BReg,1
        eor    AReg,BReg       ;Flip lsb of AReg.
wrtBit:
        andi   AReg,1          ;Isolate lsb of AReg
        mov    BReg,AReg
        lsr    BReg
        rcall  PutBit          ;Send lsb of AReg to 1-wire bus.
        lds    XL,romoff 
        lds    XH,romoff+1     ;Get offset into ROM data buffer.
        ld     AReg,X          ;Get previous val of rombyte.
        ror    AReg            ;Get ROM bit in MSB of rombyte.
        st     X,AReg          ;Store new byte value & point to next byte 
        dec    Count8          ;Decrement byte counter.
        brne   bnfull          ;Branch if we don't have full byte.
        adiw   XH:XL,1         ;increment x
        sts    romoff,XL       ;buffer in rombuff.
        sts    romoff+1,XH
        ldi    Count8,8        ;reload the eight counter.
bnfull:
        dec    BitNum          ;Decrement 64 bit counter.
        brne   NxtRBit         ;Go get next rom bit.
        cp     LasDisCpy,LastDis ;Compare to last dis. copy
        brne   MoDows          ;If not equal clear AReg.
        ldi    AReg,$41        ;Point ROM search algorithm back
        mov    LastDis,AReg    ;to first part.
        ldi    AReg,1          ;Indicate this was last part on bus.
        rjmp   lastdow         ;Skip the clra statement and leave.
MoDows:
        clr    AReg            ;Indicate that more parts are on bus.        
lastdow:
        sec                    ;Indicate success.
        rjmp   DevFnd          ;Skip clear carry stuff.
NoDev:
        clc                    ;Indicate failure.
DevFnd:
        pop    XH
        pop    XL
        ret

;********************************************** 
;* GetROMS                                    *
;* Looks for up to 8 DS1820s, reads their     *
;* 64 bit ROM codes and saves them in memory  *
;**********************************************
GetROMS:
        clr    AReg
        clr    ROMCount        ;clear out ROMCount
        clr    Done            ;clear Done flag
        ldi    YH,high(romdta)
        ldi    YL,low(romdta)  ;Y points to romdta buffer
ClrOut:
        st     Y+,AReg         ;clear out the ROM ID storage area
        cpi    YL,low(Sensor7+8)
        brcs   ClrOut
LookROM:
        rcall  DSReset         ;Reset 1-wire bus
;*** to send out the list of ROMs found, uncomment the line below
        brcc   SetExit         ;Abort if no presence detect
;*** to NOT send out the list of ROMs found, uncomment the line below
;        brcc   SetExit2       ;Abort if no presence detect 

        rcall  ROM1st          ;look for the first ROM
        mov    ScratchL,AReg
        brcc   SetExit         ;if AReg = 0 then there are more devices
        ldi    XH,high(Sensor0)
        ldi    XL,low(Sensor0) ;X points to first device ID  
        rjmp   MR0             ;process them & exit
LR1:
        rcall  ROMSrch         ;look for other devices
        mov    ScratchL,AReg
        breq   MR0             ;if AReg = 0 then there are more devices
        inc    Done
MR0:
        ldi    YH,high(romdta+8)
        ldi    YL,low(romdta+8) ;Y points to ROM just read
MoveROM:
        ld     AReg,-Y         ;move byte from romdta
        st     X+,AReg         ;to SensorX
        cpi    YL,low(romdta)  ;move all 8 bytes
        brne   MoveROM         ;of the ROM ID
        inc    ROMCount        ;increment the ROM counter
        tst    ScratchL        ;repeat until the last device found
        breq   MR2
        inc    Done
MR2:
        tst    Done
        brne   SetExit
        cpi    XL,low(Sensor7+8) ;or until the end of the ROM
        brcs   LR1             ;storage area is reached                     
SetExit:
        rcall  ShowROM         ;then Display the ROM IDs
SetExit2:
        ret

;********************************************** 
;* ShowROM                                    *
;* Converts data in the Sensor area to ASCII  *
;* hex and send them out the serial port.     *
;**********************************************
ShowROM:
        ldi    XL,low(Sensor0) ;X points to Sensor ID area
        ldi    XH,high(Sensor0)
SRLoop:
        ldi    YL,low(Buffer)  ;Y points to ASCII data buffer
        ldi    YH,high(Buffer)
        ldi    ByteCount,8
ROMHex:
        ld     AReg,X+         ;convert 8 bytes to 16 ASCII Hex
        rcall  Put1Hex         ;characters. Y is incremented
        dec    ByteCount
        brne   ROMHex       

        ldi    YL,low(Buffer) 
        ldi    YH,high(Buffer)
ROMOut:
        ld     AReg,Y+         ;send characters in the buffer     
        rcall  SerOut          ;to the serial port

        cpi    YL,low(Buffer+16)
        brcs   ROMOut
        clr    AReg
        st     Y,AReg
 
        rcall  OutCRLF        
        cpi    XL,low(Sensor7+8) ;repeat for all eight ID locations
        brcs   SRLoop               
SRBye:
        rcall  OutCRLF
        ret

;********************************************** 
;* ShowData                                   *
;* Converts data in the register area to ASCII*
;* hex and send them out the serial port.     *
;**********************************************
ShowData:
        ldi    XL,low(TempLSB) ;X points to data area
        ldi    XH,high(TempLSB)
SDLoop:
        ldi    YL,low(Buffer)  ;Y points to ASCII data buffer
        ldi    YH,high(Buffer)
        ldi    ByteCount,8
DatHex:
        ld     AReg,X+         ;convert 8 bytes to 16 ASCII Hex
        rcall  Put1Hex         ;characters. Y is incremented
        dec    ByteCount
        brne   DatHex       

        ldi    YL,low(Buffer) 
        ldi    YH,high(Buffer)
DatOut:
        ld     AReg,Y+         ;send characters in the buffer     
        rcall  SerOut          ;to the serial port

        cpi    YL,low(Buffer+16)
        brcs   DatOut
		                       ;not enough RAM to display 18 bytes
							   ;so we display the 2 ASCII bytes for the CRC
							   ;in a separate operation 

        lds    AReg,CRC        ;AReg=CRC
        ldi    YL,low(Buffer)  ;Y points to ASCII data buffer
        ldi    YH,high(Buffer)
        rcall  Put1Hex         ;convert to hex 
        lds    AReg,Buffer     ;send characters in the buffer     
        rcall  SerOut          ;to the serial port
        lds    AReg,Buffer+1    
        rcall  SerOut
				           
        rcall  OutCRLF
        ret

;********************************************** 
;* ROMatch                                    *
;* Sends the MatchROM command, followed by    *
;* the 8 byte ROM ID                          * 
;**********************************************
ROMatch:
        lds    XL,romoff       ;point to device ROM
        lds    XH,romoff+1
        adiw   XH:XL,8         ;point to MSB                             
        ldi    Count8,8
        ldi    AReg,MatchROM   ;Match ROM command
        rcall  PutByte         ;send it
SndROM:
        ld     AReg,-X         ;send the ROM ID
        rcall  PutByte
        dec    Count8
        brne   SndROM 
        ret     

;**********************************************
;* Serial I/O and misc routines               *
;**********************************************

;**********************************************
;* Timer0 overflow interrupt handler          *
;**********************************************
Tim0int:
        cli                    ;disable interrupts
        set                    ;Set T flag
        ldi     ScratchH,TSTOP ;Stop Timer 0
        out     TCCR0,ScratchH
        sei                    ;re-enable interrupts
        reti                    

;**********************************************
;* Delay   time in us based on CLK value      *
;* DelayVal holds the delay value.            *
;* ScratchH has the prescaler value           *
;**********************************************
Delay:
        in      SaveSREG,SREG  ;Save status register
        out     TCNT0,DelayVal
        clt                    ;Clear T
        out     TCCR0,ScratchH ;Run timer
Dwait:  
        brtc    Dwait          ;Wait for timer 0 interrupt to set T
        out     SREG,SaveSREG
        ret

;**********************************************
;* SerOut  Data in AReg sent out the serial   *
;* port                                       *
;**********************************************
SerOut: 
        sbis    USR,UDRE       ;wait till register is cleared 
        rjmp    SerOut         ;not skipped, loop back and wait
        out     UDR,AReg       ;send the recived value 
        ret
 
;**********************************************
;* SerIn  Returns serial port input in AReg  *
;**********************************************
SerIn:
        sbis    USR,RXC        ;wait for a character
        rjmp    SerIn   
        in      AReg,UDR       ;read value
        ret

;**********************************************
;* OutCRLF Sends a CRLF out the serial port   *
;**********************************************
OutCRLF:
        ldi    AReg,$0d        ;CR
        rcall  SerOut
        ldi    AReg,$0a        ;LF
        rcall  SerOut
        ret

;********************************************** 
;* GetRegs                                    *
;* Reads the registers of the DS1820/18S20    *
;* device selected in A.                      * 
;* Result stored in the AReg storage area     *
;**********************************************
GetRegs:
        sei
        rcall  DSReset
        ldi    XL,low(Sensor0)
        ldi    XH,high(Sensor0)
        
GR0:
        mov    BReg,AReg       ;copy device # to BReg
        lsl    BReg            ;BReg x 2
        lsl    BReg            ;BReg x 4
        lsl    BReg            ;BReg x 8

⌨️ 快捷键说明

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