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

📄 f84 232 temperture.txt

📁 pic系列单片机得控制程序 主要进行温度采集和转换控制
💻 TXT
📖 第 1 页 / 共 2 页
字号:

;Temperatur       RS232 / 9600 8N1       

                      list p=16F84A
                      include <p16f84a.inc>

                      __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC


loops                 EQU 0x0C
loops2                EQU 0x0D
LCD_DATEN             EQU 0x0E
LCD_STATUS            EQU 0x0F
KEY                   EQU 0x10
count                 EQU 0x11
delay                 EQU 0x12
txreg                 EQU 0x13
rcreg                 EQU 0x14
ds1820                EQU 0x15
temp1                 EQU 0x16
temp2                 EQU 0x17
rest                  EQU 0x18                

d1                    EQU 0x19
d2                    EQU 0x1A
d3                    EQU 0x1B
bin                   EQU 0x1C
huns                  EQU 0x1D
tens                  EQU 0x1E
ones                  EQU 0x1F


clockrate             EQU .4000000           
fclk                  EQU clockrate/4
baudrate              EQU ((fclk/.9600)/3-2)  ;9600 Baud


                      org 0x000
                      clrf PCLATH
                      goto main
                      
                      
send_temp             movlw 'T'               ; "Temperatur" 
                      movwf txreg
                      call send
                      movlw 'e'
                      movwf txreg
                      call send
                      movlw 'm'
                      movwf txreg
                      call send
                      movlw 'p'
                      movwf txreg
                      call send
                      movlw 'e'
                      movwf txreg
                      call send
                      movlw 'r'
                      movwf txreg
                      call send
                      movlw 'a'
                      movwf txreg
                      call send
                      movlw 't'
                      movwf txreg
                      call send
                      movlw 'u'
                      movwf txreg
                      call send
                      movlw 'r'
                      movwf txreg
                      call send
                      movlw ':'
                      movwf txreg
                      call send
                      movlw ' '
                      movwf txreg
                      call send
                      
                      return
                      
                      
bin2bcd               movlw 8                  
                      movwf count             ;  
                      clrf huns               ; 
                      clrf tens
                      clrf ones

bcdadd3               movlw 5
                      subwf huns, 0
                      btfsc STATUS, C
                      call add3huns

                      movlw 5
                      subwf tens, 0
                      btfsc STATUS, C
                      call add3tens

                      movlw 5
                      subwf ones, 0
                      btfsc STATUS, C
                      call add3ones

                      decf count, 1
                      bcf STATUS, C
                      rlf bin, 1
                      rlf ones, 1
                      btfsc ones,4
                      call carryones
                      rlf tens, 1

                      btfsc tens,4
                      call carrytens
                      rlf huns,1
                      bcf STATUS, C

                      movf count, 0
                      btfss STATUS, Z
                      goto bcdadd3


                      movf huns, 0
                      addlw h'30'
                      movwf huns

                      movf tens, 0
                      addlw h'30'
                      movwf tens

                      movf ones, 0
                      addlw h'30'
                      movwf ones

                      return

add3huns              movlw 3
                      addwf huns,1

                      return

add3tens              movlw 3
                      addwf tens,1

                      return

add3ones              movlw 3
                      addwf ones,1

                      return

carryones             bcf ones, 4
                      bsf STATUS, C

                      return

carrytens             bcf tens, 4
                      bsf STATUS, C
                      return
                      
                      
delay_600us           movlw 0xC6              ; 600 us Pause
                      movwf d1
delay_600us_loop      decfsz d1, f
                      goto delay_600us_loop
	              nop
	              
                      return
                      
                      
delay_50us            movlw 0x0F              ; 50 us Pause
                      movwf d1
delay_50us_loop       decfsz d1, f
                      goto delay_50us_loop
                      
                      return
                      
                      
delay_15ms            movlw 0xB6              ; 15 ms Pause
                      movwf d1
                      movlw 0x0C
                      movwf d2
delay_15ms_loop       decfsz d1, f
                      goto $+2
                      decfsz d2, f
                      goto delay_15ms_loop
                      goto $+1
                      nop
                      
                      return
                      
                      
delay_7us             goto $+1                ; 7 us Pause
                      nop
                      
                      return
                      
                      
delay_80us            movlw 0x19              ; 80 us warten
                      movwf d1
delay_80us_loop       decfsz d1, f
                      goto delay_80us_loop
                      
                      return
                      
                      
delay_1s              movlw 0x07              ; 1 s warten
                      movwf d1
                      movlw 0x2F
                      movwf d2
                      movlw 0x03
                      movwf d3
delay_1s_loop         decfsz d1, f
                      goto $+2
                      decfsz d2, f
                      goto $+2
                      decfsz d3, f
                      goto delay_1s_loop
                      goto $+1
                      goto $+1
                      goto $+1
                      
                      return


;发送
send                  movwf   txreg
                      bcf     PORTA, 1             ;send start bit
                      movlw   baudrate
                      movwf   delay
                      movlw   .9
                      movwf   count
txbaudwait            decfsz  delay
                      goto    txbaudwait
                      movlw   baudrate
                      movwf   delay
                      decfsz  count
                      goto    sendnextbit
                      movlw   .9
                      movwf   count
                      bsf     PORTA, 1             ;send stop bit
                      
                      movlw baudrate
                      movf delay
                      decfsz delay, f
                      goto $-1
                      
                      movlw baudrate
                      movf delay
                      decfsz delay, f
                      goto $-1
                      
                      retlw   0
sendnextbit           rrf     txreg
                      btfss   STATUS, C            ;check next bit to tx
                      goto    setlo
                      bsf     PORTA, 1             ;send a high bit
                      goto    txbaudwait
setlo                 bcf     PORTA, 1             ;send a low bit
                      goto    txbaudwait

⌨️ 快捷键说明

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