DS1820 Thermometer schematics
;=====lcd digital thermometer with ds18s20 Version 2.1======14/11/03== ; iic lcd driver: PCF2103 ; ra0,ra1 iic sclock, sdata ; ra2,ra3 pwm, ds1820 data I/O ; internal clock ; standard crystal 4.194 MHz XT - .95us pe instructiune ; Program realizat de Ing. Bergthaller Iulian-Alexandru ;------------------------------------------------------------ list p=16f84;f=inhx8m #INCLUDE P16F84.INC _CP_OFF equ H'3FFF' ;code protect off _PwRTE_ON equ H'3FFF' ;Power on timer on _wDT_OFF equ H'3FFB' ;watch dog timer off _XT_OSC equ H'3FFD' ;crystal oscillator __CONFIG _CP_OFF & _PwRTE_ON & _wDT_OFF & _XT_OSC ;------------------------------------------------------------ ; cpu init count1 equ 0C count2 equ 0D count3 equ 0E transo equ 0F ratb equ 10 dig1 equ 11 dig2 equ 12 dig3 equ 13 semn equ 14 #DEFINE sclk PORTA,0 #DEFINE sdta PORTA,1 #DEFINE osc PORTA,2 #DEFINE grad PORTA,3 ;------------------------------------------------------------ ;------------------------------------------------------------ ; cpu init org 0x00 goto init org 0x04 ; ;------------------------------------------------------------ init call usaex call usbex movlw 0x00 movwf PORTA movwf PORTB clrf semn ;*************************************************** ;*************************************************** ;* Lcd init commands * ;*************************************************** lcd_ini call iict ; i2c start movlw 0x74 ; device write address (75h for read) call act ; i2c send subroutine movlw 0x00 ; Co,RS=0, set instruction register for multiple next command bytes call act movlw 0x31 ; extended instruction set call act movlw 0x02 ; set screen configuration left to right call act movlw 0x05 ; set display configuration call act movlw 0x08 ; set icon mode, full mode, icon blink disable call act movlw 0x30 ; normal instruction set call act movlw 0x0C ; set display on call act movlw 0x06 ; set cursor move direction call act movlw 0x02 ; set DDRAM address 0 in address counter call act call iicp ; i2c stop ;*************************************************** ;* Lcd icon sets off * ;*************************************************** call iict movlw 0x74 call act movlw 0x80 ; Co=1, RS=0 just one next command byte call act movlw 0x4C ; set CGRAM for icons call act movlw 0x40 ; Co=0, RS=1, set instruction register for multiple next data bytes call act movlw 0x00 ; erase icons sequence call act movlw 0x18 call act movlw 0x00 call act movlw 0x00 call act movlw 0x00 call act movlw 0x00 call act movlw 0x00 call act movlw 0x00 call act movlw 0x00 call act movlw 0x00 call act movlw 0x00 call act movlw 0x00 call act movlw 0x0F call act movlw 0x10 call act call iicp ; i2c stop ;*************************************************** ;* Lcd cursor subroutine * ;*************************************************** call iict movlw 0x74 call act movlw 0x00 call act movlw 0x30 call act movlw 0x01 ; clears entire display and sets DDRAM address to 0 in address counter call act movlw 0x0C ; display on, cursor off, cursor blink off call act call iicp ;*************************************************** ;* Lcd data subroutine * ;*************************************************** nou call iict movlw 0x74 call act movlw 0x80 ; Co=1, RS=0 just one next command byte call act movlw 0x8C ; set CGRAM for characters call act movlw 0x40 ; Co=0, RS=1, set instruction register for multiple next data bytes call act movlw 0xD4 ; T call act movlw 0xE5 ; e call act movlw 0xED ; m call act movlw 0xF0 ; p call act movlw 0xBA ; : call act movlw 0xAB ; btfsc semn,0 addlw 0x02 call act scrie call rset movlw 0xCC ;skip rom call schtx movlw 0x44 ;convert call schtx call halta call rset movlw 0xCC ;skip rom call schtx movlw 0xBE ;read scratchpad call schtx call schrx call mux movf dig2,0 addlw 0xB0 call act movf dig1,0 addlw 0xB0 call act movlw 0xAC call act movf dig3,0 addlw 0xB0 call act movlw 0x20 ; call act movlw 0xC3 ; call act call iicp goto nou ;*************************************************** rset bcf grad call halte ; 510 us bsf grad call usain call haltd ; 61 us btfsc grad bsf PORTB,0 btfss grad bcf PORTB,0 call halte ; 510us call usaex retlw 00 ;*************************************************** schtx movwf ratb ; movlw 0x08 movwf count3 ;*************************************************** gbit btfsc ratb,0 ; data reverse flow call unu btfss ratb,0 call nul rrf ratb,F decfsz count3,F goto gbit retlw 00 ;*************************************************** schrx movlw 0x08 movwf count3 samp rrf ratb,F bcf grad call usain call haltcc ; 11us btfsc grad ; data reverse flow bsf ratb,7 btfss grad bcf ratb,7 call haltd ; 61 us call usaex decfsz count3,F goto samp bcf grad call usain call haltc ; 11us btfsc grad ; data bit flow bsf semn,0 btfss grad bcf semn,0 call haltd ; 61 us call usaex btfsc semn,0 call negativ movlw 0x00 btfsc ratb,0 addlw 0x05 movwf dig3 rrf ratb,0 andlw 0x7F movwf ratb return ;*************************************************** negativ movf ratb,0 xorlw 0xFF addlw 0x01 movwf ratb return ;*************************************************** ;*************************************************** unu bcf grad call haltc ; 11 us bsf grad call haltd ; 65 us retlw 00 ;*************************************************** nul bcf grad call haltc ; 11 us call haltd ; 65 us bsf grad retlw 00 ;*************************************************** act movwf transo ; iic data transmission movlw 0x08 movwf count3 vbit bcf sclk call haltb btfsc transo,7 bsf sdta btfss transo,7 bcf sdta call haltb bsf sclk call haltb bcf sclk call haltb rlf transo,F decfsz count3,F goto vbit call ackp retlw 00 ;*************************************************** iicp bcf sdta ; stop condition module call haltb bsf sclk call haltb bsf sdta ; stop command call haltb bcf sclk call haltb retlw 00 ;*************************************************** iict bsf sdta ; start condition module bsf sclk call haltb bcf sdta ; start command call haltb bcf sclk call haltb retlw 00 ;*************************************************** ackp bsf sclk ; one clock step for acknowledge (not read) call haltb bcf sclk call haltb retlw 00 ;*************************************************** halta movlw 0x90 ; cca. 800ms delay movwf count3 r3 movlw 0xFF movwf count2 r2 call pwmm decfsz count2,F goto r2 decfsz count3,F goto r3 retlw 00 ;*************************************************** haltb movlw 0x10 movwf count2 d1 call pwmm decfsz count2,F goto d1 retlw 00 ;*************************************************** haltc movlw 0x02 ; 11us movwf count1 w1 decfsz count1,F goto w1 retlw 00 ;*************************************************** haltcc movlw 0x01 ; 9us movwf count1 ww1 decfsz count1,F goto ww1 nop retlw 00 ;*************************************************** haltd call pwmm call pwmm call haltc retlw 00 ;*************************************************** ;*************************************************** halte movlw 0x14 ; 510 us movwf count2 w3 call pwmm decfsz count2,F goto w3 retlw 00 ;*************************************************** ;------------------------------------------------------------ pwmm bsf osc call haltc bcf osc call haltc retlw 00 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: usaex bsf STATUS,RP0 ;switch to bank 1 movlw 0x00 ; PORTA set to out/inputs movwf TRISA bcf STATUS,RP0 ;switch back to bank 0 return ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: usain bsf STATUS,RP0 ;switch to bank 1 movlw 0x08 ; sdta set to input movwf TRISA bcf STATUS,RP0 ;switch back to bank 0 return ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: usbex bsf STATUS,RP0 ;switch to bank 1 movlw 0x00 ; PORTB set to out/inputs movwf TRISB bcf STATUS,RP0 ;switch back to bank 0 return ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;*************************************************** mux clrf dig1 clrf dig2 movf ratb,F ; zero bit test if dig=dig=0 btfss STATUS,2 goto calc goto gatam calc call digi decfsz ratb,F goto calc gatam return ;*************************************************** digi incf dig1,F movlw 0x0A subwf dig1,W btfss STATUS,2 ;test zero bit goto gatas clrf dig1 incf dig2,F movlw 0x0A subwf dig2,W btfss STATUS,2 ;test zero bit goto gatas clrf dig2 gatas retlw 00 ;*************************************************** end ;============================================================
The code can be download from here.
Back to my home page