Tom den Hollander
ScouBrou's Brouwmeester
Beste allemaal,
Ik probeer m'n DS18B20 uit te lezen maar 't lukt niet.
Onderstaand de ASM.
Ik de initialisatie lukt wel, ik zie de presence puls.
Maar ROM uitlezen of temperatuur conversie lukt niet.
Ik krijg in m'n ontvangen byte0 > 1111111 ofwel een blokje op 't display en de andere ontvangen bytes zijn 0.
Wie oh wie helpt me uit de brand?
Ik heb de DS18B20 overigens met voeding aangesloten.
dus met plattekant/opdruk naar je toe. links=GND, midden=Data met 4K7 naar 5Volt, rechts is 5V
Mogelijk dat er ook iets misgaat met de page grootte?
Wie oh wie helpt me op weg?
;**********************************************************************
; *
; Eerste Poging ASM : Tom den Hollander dd. 19-5-2010 *
; *
; Karakter LCD met op regel *
;XTAL = 20 MHz = 200ns per instructie *
; LCD Pin 4 = RS = PORTB,3 = PIC Pin 9
; LCD Pin 6 = E = PORTB,2 = PIC Pin 8
; LCD Pin 11 = DB4 = PORTB,4 = PIC Pin 10
; LCD Pin 12 = DB5 = PORTB,5 = PIC Pin 11
; LCD Pin 13 = DB6 = PORTB,6 = PIC Pin 12
; LCD Pin 14 = DB7 = PORTB,7 = PIC Pin 13
; LED = PORTA,0 = PIC Pin 17
; DS18B20 = PORTA,1 = PIC Pin 18
;
;**********************************************************************
list p=16f628 ; Definitie van PIC type
#include <p16f628.inc> ; processor specific variable definitions
__config _HS_OSC & _LVP_OFF & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _MCLRE_OFF
;**********************************************************************
ORG 0h
MAIN_PROG CODE
;==================================
;== Declaratie
;==================================
CBLOCK H'20'
WaitH ;Voor Wachtroutines
WaitL ;Voor Wachtroutines
R1H
R1L
R2H
R2L
R3H
R3L
R4H
R4L
count
INDEX
TEMP
COUNTDOWN ; GPR for counting execution times in various routines
SHIFT_IN ; GPR for storing data to shift into the DS18B20
SHIFT_OUT ; GPR for storing data shifted out of the DS18B20
SCRATCHPAD_BYTE0 ; GPR for storing SCRATCHPAD Data - Temperature LSD
SCRATCHPAD_BYTE1 ; GPR for storing SCRATCHPAD Data - Temperature MSB
SCRATCHPAD_BYTE2 ; GPR for storing SCRATCHPAD Data - Alarm Trigger High register
SCRATCHPAD_BYTE3 ; GPR for storing SCRATCHPAD Data - Alarm Trigger Low regisier
SCRATCHPAD_BYTE4 ; GPR for storing SCRATCHPAD Data - Configuration Register
SCRATCHPAD_BYTE5 ; GPR for storing SCRATCHPAD Data - Reserved, but needed for CRC Calculation
SCRATCHPAD_BYTE6 ; GPR for storing SCRATCHPAD Data - Reserved, but needed for CRC Calculation
SCRATCHPAD_BYTE7 ; GPR for storing SCRATCHPAD Data - Reserved, but needed for CRC Calculation
SCRATCHPAD_BYTE8 ; GPR for storing SCRATCHPAD Data - CRC (cyclic redundancy check)
HUNS
TENS
ONES
HUNS_ARRANGEMENT
TENS_ARRANGEMENT
ONES_ARRANGEMENT
TENTHS_ARRANGEMENT
TABLE_WHOLE
TEMPHI
TEMPLO
TABLE_TENTHS
ENDC
#define LED PORTA,0
#define RS PORTB,3
#define E PORTB,2
#define DS18B20 PORTA,1
#define TRISDS18B20 TRISA,1
LCD_PORT Equ PORTB
LCD_TRIS Equ TRISB
;===================================
;== Initialisatie
;===================================
Begin: BSF 3h,5h ;kies bank 1
BCF 85h,0h ;Zet PORTA,0 als Uitgang voor LED
CLRF 86h ;Zet PORTB als Uitgang voor LCD
BCF 3h,5h ;kies bank 0
movlw 0x07
movwf CMCON ;Comparatoren uit
; clrf PORTA
; clrf PORTB
;==Blink Led
Start: movlw 0x064 ;Wait 100ms
movwf WaitL
movlw 0x000
movwf WaitH
call Waitms
BSF LED ;Led On
movlw 0x064 ;Wait 100ms
movwf WaitL
movlw 0x000
movwf WaitH
call Waitms
BCF LED ;Led Off;
;=Init LCD
call LCDinit ;Initialize LCD
movlw 0x064 ;Wait 100ms
movwf WaitL
movlw 0x000
movwf WaitH
call Waitms
call Welkom ;Display Welcome screen Line1
call LCD_Line2 ;Move to next line on LCD
call Welkom2 ;Display Welcome screen Line2
movlw 0x0d0 ;Wait 2000ms
movwf WaitL
movlw 0x007
movwf WaitH
call Waitms
BSF LED ;Led On
next: call LCD_Clr ;Clear LCD
call LCD_DS18B20_RESET
call DS18B20_RESET_PRESENCE ;Reset DS18B20 and only return when present
call LCD_Line2
call LCD_DS18B20_PRESENT
call DS18B20_READROM
; movlw 0x08 ;Go to 8th column on display
; call LCD_Line1W
; call DS18B20_SKIPROM ;SKIP ROM
; call LCD_DS18B20_SKIPROM
; call DS18B20_CONVERTT ;CONVERT T
; call DS18B20_RESET_PRESENCE ;Reset DS18B20 and only return when present
;call DS18B20_SKIPROM ;SKIP ROM
call DS18B20_READSCRATCHPAD ;READ SCRATCHPAD
; call REARRANGE_RESULT
call LCD_Clr
movf SCRATCHPAD_BYTE0
call LCDout
movf SCRATCHPAD_BYTE1
call LCDout
movf SCRATCHPAD_BYTE2
call LCDout
movf SCRATCHPAD_BYTE3
call LCDout
movf SCRATCHPAD_BYTE4
call LCDout
movf SCRATCHPAD_BYTE5
call LCDout
movf SCRATCHPAD_BYTE6
call LCDout
movf SCRATCHPAD_BYTE7
call LCDout
movf SCRATCHPAD_BYTE8
call LCDout
movlw 0x0d0 ;Wait 2000ms
movwf WaitL
movlw 0x007
movwf WaitH
call Waitms
BCF LED ;Led Off
call LCD_Clr
movlw 0x0d0 ;Wait 2000ms
movwf WaitL
movlw 0x007
movwf WaitH
call Waitms
BSF LED ;Led Off
goto next
;---------------------------------------------------------------------------
;======== Wacht Routines =======
;WaitMS Routine W001
Waitms: movf WaitL,f ;Zet de low byte van wachttijd in W zonder data uit F weg te halen ; 0,2us
btfsc STATUS,Z ;
goto Waitms002
call Waitms003
decf WaitL,f
nop
nop
nop
nop
nop
goto Waitms
Waitms002: movf WaitH,F
btfsc STATUS,Z
return
call Waitms003
decf WaitH,F
decf WaitL,F
goto Waitms
Waitms003: movlw 0x0c
movwf R2H
Waitms004: decfsz R2H,F
goto Waitms004
nop
nop
movlw 0x62
movwf R1L
Waitms005: decfsz R1L,F
goto Waitms006
call Waitms007
call Waitms007
nop
nop
return
Waitms006: call Waitms007
goto Waitms005
Waitms007: movlw 0x0d
movwf R2L
Waitms008: decfsz R2L,F
goto Waitms008
nop
return
;===== Waitus Routine
; Waitus Routine - Byte Argument
WaitusB: MOVLW 0x02 ;X001
SUBWF R4L,F
BTFSS STATUS,C
RETURN
GOTO WaitusB002
WaitusB002: MOVLW 0x02
SUBWF R4L,F
NOP
NOP
NOP
NOP
BTFSS STATUS,C
RETURN
GOTO WaitusB002
; Waitus Routine - Word Argument
WaitusW: MOVLW 0x04
SUBWF R4L,F
CLRW
BTFSS STATUS,C
ADDLW 0x01
SUBWF R4H,F
BTFSS STATUS,C
RETURN
GOTO WaitusW002
WaitusW002: MOVLW 0x02
SUBWF R4L,F
CLRW
BTFSS STATUS,C
ADDLW 0x01
SUBWF R4H,F
BTFSS STATUS,C
RETURN
GOTO WaitusW002
;========= Einde Wacht Routines
;============================================
;= DS18B20 Routines =
;============================================
DS18B20_RESET_PRESENCE:
call DQ_HIZ ;Low pulse can only come from line high
movlw 0x01 ;Wait 1us
movwf R4L
call WaitusB
call DQ_LL ;Call routines that forces DS18B20 line low
movlw 0xf4 ;Wait 500us (min 480us Reset Pulse)
movwf R4L
movlw 0x01
movwf R4H
call WaitusW
call DQ_HIZ ;Call routines that makes DS18B20 Line an Input
movlw 0x46 ;Wait 70us (Wait for Pullup resistor to pull DS18B20 line high, wait min 60us)
movwf R4L
call WaitusB
BTFSC DS18B20
goto DS18B20_RESET_PRESENCE ;DS18B20 returned a logic 1, not ready, GOTO INITDS18B20
movlw 0xf4 ;DS18B20 returned a logic 0, ready, Wait 500us to let the DS18B20 finish presence puse
movwf R4L
movlw 0x01
movwf R4H
call WaitusW
return
DQ_HIZ: ;This routine forces the DS18B20 line into a high impendance state
BSF STATUS,RP0 ;Bank 1
BSF TRISDS18B20 ;Make DS18B20 pin an input, pullup resistor forces line to a logic 1, unless DS18B20 pulls it low
BCF STATUS,RP0 ;Bank 0
RETURN
DQ_LL: ;This routines forces the DS18B20 line to a logic low
BCF DS18B20 ;CLear output latch
BSF STATUS,RP0 ;Bank 1
BCF TRISDS18B20 ;Make DS18B20 an output
BCF STATUS,RP0 ;Bank 0
RETURN
DS18B20_SKIPROM ; This routine issues a SKIPROM [CCh] COMMAND to address all devices on the '1-Wire bus)
; The master can use this command to address all devices on the bus simultaneously without sending
; out any ROM code information. For example, the master can make all DS18B20s on the bus perform
; simultaneous temperature conversions by issuing a Skip ROM command followed by a Convert T [44h]
; command.
; Note that the Read Scratchpad [BEh] command can follow the Skip ROM command only if there is a
; single slave device on the bus. In this case, time is saved by allowing the master to read from
; the slave without sending the device�s 64-bit ROM code. A Skip ROM command followed by a Read
; Scratchpad command will cause a data collision on the bus if there is more than one slave since
; multiple devices will attempt to transmit data simultaneously.
MOVLW 0x0cc ; ROM COMMAND for SKIPROM
MOVWF SHIFT_IN ; Store COMMAND in GPR
CALL WRITE_DATA ; CALL WRITE_DATA routine to Tx COMMAND to DS18B20
RETURN
DS18B20_READROM ; This routine issues a READROM [33h] COMMAND to address all devices on the '1-Wire bus)
MOVLW 0x033 ; ROM COMMAND for READROM
MOVWF SHIFT_IN ; Store COMMAND in GPR
CALL WRITE_DATA ; CALL WRITE_DATA routine to Tx COMMAND to DS18B20
RETURN
DS18B20_CONVERTT ; This routine issues a CONVERT T [44h] COMMAND to initiate a Temperature Conversion
; This command initiates a single temperature conversion. Following the conversion, the resulting
; thermal data is stored in the 2-byte temperature register in the scratchpad memory and the DS18B20
; returns to its low-power idle state. If the device is being used in parasite power mode, within
; 10�s (max) after this command is issued the master must enable a strong pullup on the 1-Wire bus
; for the duration of the conversion (tCONV) as described in the Powering the DS18B20 section. If
; the DS18B20 is powered by an external supply, the master can issue read time slots after the
; Convert T command and the DS18B20 will respond by transmitting a 0 while the temperature
; conversion is in progress and a 1 when the conversion is done. In parasite power mode this
; notification technique cannot be used since the bus is pulled high by the strong pullup during
; the conversion.
MOVLW 0x044 ; FUNCTION COMMAND for CONVERT T
MOVWF SHIFT_IN ; Store COMMAND in GPR
CALL WRITE_DATA ; CALL WRITE_DATA routine to Tx COMMAND to DS18B20
MOVLW 0x0E8 ; Wait 1000us (minimum 750us for 12-but CONVERT T conversion
MOVWF R4L
MOVLW 0x03
MOVWF R4H
CALL WaitusW
RETURN
DS18B20_READSCRATCHPAD ; This routine issues a READ SCRATCHPAD [BEh] COMMAND to read data from the DS18B20
; This command allows the master to read the contents of the scratchpad. The data transfer starts
; with the least significant bit of byte 0 and continues through the scratchpad until the 9th byte
; (byte 8 � CRC) is read. The master may issue a reset to terminate reading at any time if only part
; of the scratchpad data is needed.
MOVLW H'BE' ; FUNCTION COMMAND for READ SCRATCHPAD
MOVWF SHIFT_IN ; Store COMMAND in GPR
CALL WRITE_DATA ; CALL WRITE_DATA routine to Tx COMMAND to DS18B20
CALL DS18B20_READTIMESLOTS ; CALL DS18B20_READTIMESLOTS to obtain DS18B20 Sratchpad Data
MOVF SHIFT_OUT, W ; Data temporarily stored in SHIFT_OUT GPR
MOVWF SCRATCHPAD_BYTE0 ; MOVE data to separate GPR
CALL DS18B20_READTIMESLOTS ; CALL DS18B20_READTIMESLOTS to obtain DS18B20 Sratchpad Data
MOVF SHIFT_OUT, W ; Data temporarily stored in SHIFT_OUT GPR
MOVWF SCRATCHPAD_BYTE1 ; MOVE data to separate GPR
CALL DS18B20_READTIMESLOTS ; CALL DS18B20_READTIMESLOTS to obtain DS18B20 Sratchpad Data
MOVF SHIFT_OUT, W ; Data temporarily stored in SHIFT_OUT GPR
MOVWF SCRATCHPAD_BYTE2 ; MOVE data to separate GPR
CALL DS18B20_READTIMESLOTS ; CALL DS18B20_READTIMESLOTS to obtain DS18B20 Sratchpad Data
MOVF SHIFT_OUT, W ; Data temporarily stored in SHIFT_OUT GPR
MOVWF SCRATCHPAD_BYTE3 ; MOVE data to separate GPR
CALL DS18B20_READTIMESLOTS ; CALL DS18B20_READTIMESLOTS to obtain DS18B20 Sratchpad Data
MOVF SHIFT_OUT, W ; Data temporarily stored in SHIFT_OUT GPR
MOVWF SCRATCHPAD_BYTE4 ; MOVE data to separate GPR
CALL DS18B20_READTIMESLOTS ; CALL DS18B20_READTIMESLOTS to obtain DS18B20 Sratchpad Data
MOVF SHIFT_OUT, W ; Data temporarily stored in SHIFT_OUT GPR
MOVWF SCRATCHPAD_BYTE5 ; MOVE data to separate GPR
CALL DS18B20_READTIMESLOTS ; CALL DS18B20_READTIMESLOTS to obtain DS18B20 Sratchpad Data
MOVF SHIFT_OUT, W ; Data temporarily stored in SHIFT_OUT GPR
MOVWF SCRATCHPAD_BYTE6 ; MOVE data to separate GPR
CALL DS18B20_READTIMESLOTS ; CALL DS18B20_READTIMESLOTS to obtain DS18B20 Sratchpad Data
MOVF SHIFT_OUT, W ; Data temporarily stored in SHIFT_OUT GPR
MOVWF SCRATCHPAD_BYTE7 ; MOVE data to separate GPR
CALL DS18B20_READTIMESLOTS ; CALL DS18B20_READTIMESLOTS to obtain DS18B20 Sratchpad Data
MOVF SHIFT_OUT, W ; Data temporarily stored in SHIFT_OUT GPR
MOVWF SCRATCHPAD_BYTE8 ; MOVE data to separate GPR
RETURN
DS18B20_READTIMESLOTS ; This routine 'clocks' data out of the DS18B20
; The DS18B20 can only transmit data to the master when the master issues read time slots.
; Therefore, the master must generate read time slots immediately after issuing a Read Scratchpad
; [BEh] or Read Power Supply [B4h] command, so that the DS18B20 can provide the requested data. In
; addition, the master can generate read time slots after issuing Convert T [44h] or Recall E2 [B8h]
; commands to find out the status of the operation as explained in the DS18B20 Function Commands
; section.
; All read time slots must be a minimum of 60�s in duration with a minimum of a 1�s recovery time
; between slots. A read time slot is initiated by the master device pulling the 1-Wire bus low for a
; minimum of 1�s and then releasing the bus (see Figure 14). After the master initiates the read
; time slot, the DS18B20 will begin transmitting a 1 or 0 on bus. The DS18B20 transmits a 1 by
; leaving the bus high and transmits a 0 by pulling the bus low. When transmitting a 0, the DS18B20
; will release the bus by the end of the time slot, and the bus will be pulled back to its high idle
; state by the pullup resister. Output data from the DS18B20 is valid for 15�s after the falling
; edge that initiated the read time slot. Therefore, the master must release the bus and then sample
; the bus state within 15�s from the start of the slot.
MOVLW H'08' ; MOVE 8 into the countdown register
MOVWF COUNTDOWN ; This is how many bits will be shifted out
MOVLW 0x046 ; Delay 70us,"All read time slots must be a minimum of 60�s in duration with a minimum of a 1�s recovery time between slots."
MOVWF R4L
CALL WaitusB
BCF INTCON, GIE ; Disable Global Interrupts
CALL DQ_LL ; Pull DQ Line low for MIN 1uS to initiate a READ TIME SLOT
CALL DQ_HIZ ; Switch to input
BTFSS DS18B20 ; Test DQ Line straight away. "Output data from the DS18B20 is valid for 15�s after the falling edge that initiated the read
; time slot. Therefore, the master must release the bus and then sample the bus state within 15�s from the start of the slot."
GOTO $+3 ; If low, GOTO here + 3
BSF SHIFT_OUT, 0 ; If high, set bit
GOTO $+2 ; Skip clear bit
BCF SHIFT_OUT, 0 ; Clear bit
BSF INTCON, GIE ; Enable Global Interrupts
RRF SHIFT_OUT, F ; Rotate Right File Register to read and write next bit
BCF STATUS, Z ; Clear Zero bit of STATUS register
DECF COUNTDOWN ; Decrement COUNTDOWN register
BTFSS STATUS, Z ; Test Z bit of STATUS register to see if last instruction = 0000 0000
GOTO $-D'16' ; If COUNTDOWN register = >0, not finished, GOTO here - 14 instructions and read then write next bit
RRF SHIFT_OUT, F ; 1 final rotation to rotate valid data out of Carry
RETURN ; If COUNTDOWN register = 0, all 8 bits have been writen to the DS18B20, therefore RETURN
WRITE_DATA ; This routine Transmits Data to the DS18B20
MOVLW H'08' ; Move 8 into the countdown register
MOVWF COUNTDOWN ; This is how many bits will be shifted in
BTFSS SHIFT_IN, 0 ; Test bit 0
GOTO $+9 ; If 0, GOTO here + 5 and write a logic 0 to the DS18B20
;Write 1
BCF INTCON, GIE ; Disable Global Interrupts
CALL DQ_LL ;
movlw 0x0a ; min 1us start of Time Slot
movwf R4L
call WaitusB
CALL DQ_HIZ ; } Write a logic 1 to the DS18B20
MOVLW 0x046 ; Wait 70us
MOVWF R4L
CALL WaitusB ; }
BSF INTCON, GIE ; Enable Global Interrupts
GOTO $+8 ; Logic 1 written, skip next 3 instructions
;Write 0
BCF INTCON, GIE ; Disable Global Interrupts
CALL DQ_LL ; Write a logic 0 to the DS18B20
MOVLW 0x064 ; Wait 100us (min 60us)
MOVWF R4L ;} Write a logic 0 to the DS18B20
CALL WaitusB
CALL DQ_HIZ
MOVLW 0x005 ; min 1us recovery time
MOVWF R4L ;
CALL WaitusB
CALL DQ_HIZ ; Recovery
BSF INTCON, GIE ; Enable Global Interrupts
RRF SHIFT_IN, F ; Rotate SHIFT_IN register ready to test next bit
BCF STATUS, Z ; Clear Zero bit of STATUS register
DECF COUNTDOWN, F ; Decrement COUNTDOWN register
BTFSC STATUS, Z ; Test Z bit of STATUS register to see if last instruction = 0000 0000
RETURN ; If COUNTDOWN register = 0, all 8 bits have been writen to the DS18B20, therefore RETURN
GOTO $-D'22' ; If COUNTDOWN register = >0, not finished, GOTO here - 13 and write next bit
REARRANGE_RESULT ; This routine rearranges the 2 Temperature result bytes into useable data
; After the DS18B20 finishes a Temperature Conversion, the 12-bit result is stored in two 8-bit
; registers. Providing the temperature is a positive number (in Degrees C) the upper nibble of the
; MSbyte (SCRATCHPAD_BYTE1) will always be 0000. (0000xxxx xxxxxxxx)
; As this program/system will display temperature to 1 decimal place, the lower nibble of the LSbyte
; is used for the decimal number, (xxxxxxxx xxxx0000). While the upper nibble of the LSbyte and the
; lower nibble MBbyte are used for the whole number, (xxxx0000 0000xxxx).
; Note that 12-bit resolution gives increments of 0.0625�C per bit
;
; Example, 0000 0011 1001 0001 ; 913 x .0625 = 57.0625�C
; (MS byte) (LS byte)
;
; So, this routine re-arranges the nibbles of both bytes so that tables can be used to obtain
; numbers to display.
; i.e. The MSbyte is used for the 1's and 10's digit (57), and the LSbyte is used for the rounded
; decimal digit (.1)
; Note that the upper nibble of the LSbyte is masked.
;
; Data after rearrangement 0011 1001 0000 0001
; (MS byte) (LS byte)
;
MOVF SCRATCHPAD_BYTE0, W ; MOVE Temperature LSbyte to W
MOVWF TEMPLO ; MOVE W to TEMPLO GPR
MOVF SCRATCHPAD_BYTE1, W ; MOVE Temperature MSbyte to W
MOVWF TEMPHI ; MOVE W to TEMPHI GPR
TEST_IF_NEGATIVE
BTFSS TEMPHI, 7 ; If 1, Temperature is Negative
GOTO $+D'7' ; NOT Negative, skip over next 6 instructions (Don't Invert & + 1)
; Invert & + 1 ; EXAMPLE Negative Temperature TEMPHI = 1111 1110 TEMPLO = 0110 1110 = -25.1250 (see datasheet)
COMF TEMPLO, F ; Invert TEMPLO (when in Negative Temperature, the DS18B20 inverts the output so this inverts the register back so its positive)
COMF TEMPHI, F ; Invert TEMPHI
BCF STATUS, Z ; Clear Zero bit of STATUS register
INCF TEMPLO, F ; Increment TEMPLO to add .0625 (after inverting the register, the positive equivelent is .0625 more so this rectifies the negative value being .0625 short)
BTFSC STATUS, Z ; Test Z bit of STATUS register to see if last instruction = 0000 0000
INCF TEMPHI, F ; IS 0 (if TEMPLO overflowed to 0, increment TEMPHI once, if not, skip)
; EXAMPLE Negative Temperature AFTER Invert & + 1 TEMPHI = 0000 0001 TEMPLO = 1001 0010 = +25.1250
; EXAMPLE, TEMPHI = 0000 0001 TEMPLO = 1001 0010
MOVLW B'11110000' ; W = 1111 0000
ANDWF TEMPLO, W ; F = 1001 0010 W = 1001 0000
IORWF TEMPHI, F ; F = 0000 0001 F = 1001 0001
SWAPF TEMPHI, F ; F = 1001 0001 F = 0001 1001 = New TEMPHI
MOVLW B'00001111' ; W = 0000 1111
ANDWF TEMPLO, F ; W = 1001 0010 F = 0000 0010 = New TEMPLO
BIN_TO_DEC ; This routine converts an 8-bit number to Decimal and store the answer in 3 GPR's; HUNS, TENS & ONES
; HUNS holds amount of hundreds (i.e. 0000 0010 = 2x100), TENS holds amount of tens (i.e. 0000 0010 = 2x10) & ONES holds amount of ones (i.e. 0000 0101 = 5x1)
INCF TEMPHI ; Preload TEMPHI + 1
CLRF HUNS ; HUNS = 0000 0000
MOVLW D'246' ; MOVE Decimal'246' to W
MOVWF TENS ; TENS GPR = 1111 0101
MOVLW D'246' ; MOVE Decimal'246' to W
MOVWF ONES ; ONES GPR = 1111 0101
BCF STATUS, Z ; Clear Zero bit of STATUS register
DECF TEMPHI, F ; DECement TEMPHI register
BTFSC STATUS, Z ; Test Z bit of STATUS register to see if last instruction = 0000 0000
GOTO HOW_MANY_TENS ; IS 0, number less than 10 so GOTO HOW_MANY_TENS to count the tens, then continue to count the ones
BCF STATUS, Z ; NOT 0, Clear Zero bit of STATUS register
INCF ONES, F ; Effects Zero bit, therefore we can test if Zero
BTFSS STATUS, Z ; Test Z bit of STATUS register to see if last instruction = 0000 0000
GOTO $-D'7' ; NOT 0, GOTO here - 7 instructions
BCF STATUS, Z ; IS 0, ONES overflowed, INCrement TENS
INCF TENS, F ; INCrement TENS register which represents 10 per increment. Will use this to CALL table
BTFSS STATUS, Z ; Test Z bit of STATUS register to see if last instruction = 0000 0000
GOTO $-D'13' ; GOTO here - 13 instructions. Reset ONLY ONES
INCF HUNS, F ; TENS overflowed, INCrement HUNS
GOTO $-D'17' ; GOTO here - 17 instructions. GOTO top, reset ONES AND TENS
HOW_MANY_TENS ; This routine counts how many 1's are in the TEMPHI register
MOVLW D'246' ; Because the TENS register is preloaded with D'246' to begin with & then INCremented every time the ONES register overflows, we
SUBWF TENS, F ; can simply SUBtract D'246' from the TENS register to determine how many tens are left over, then use this when calling the table
HOW_MANY_ONES ; This routine counts how many 1's are in the TEMPHI register
MOVLW D'246' ; Because the ONES register is also preloaded with D'246' to begin with & then INCremented every time the TEMPHI register is DECremented,
SUBWF ONES, F ; we can simply SUBtract D'246' from the ONES register to determine how many oens are left over, then use this when calling the table
BLANK_IF_ZERO ; This routine blanks the 10's & 100's column if they display "0", OR if Temperature Negative, puts a Negative sign "-" in the 100's column
BCF STATUS, Z ; Clear Zero bit of STATUS register
INCF HUNS, F ; INCrement then;
DECF HUNS, F ; DECrement to effect Zero bit but put register back in original state
BTFSS STATUS, Z ; Test Z bit of STATUS register to see if last instruction = 0000 0000
GOTO $+D'10' ; NOT 0, skip next 9 instructions. If HUNS is more than zero, we want to skip the next block so the TENS zero will NOT be blanked (i.e. 202.0)
MOVLW B'00001010' ; IS 0 therefore we want to 'blank' the 100's digit
MOVWF HUNS ; F = 0000 1010. This is a jump pointer for the TABLE_WHOLE to blank the display
BCF STATUS, Z ; Clear Zero bit of STATUS register
INCF TENS, F ; INCrement then;
DECF TENS, F ; DECrement to effect Zero bit but put register back in original state
BTFSS STATUS, Z ; Test Z bit of STATUS register to see if last instruction = 0000 0000
GOTO $+3 ; NOT 0, skip next 2 instructions
MOVLW B'00001010' ; IS 0 therefore we want to 'blank' the 10's digit
MOVWF TENS ; F = 0000 1010. This is a jump pointer for the TABLE_WHOLE to blank the display
BTFSS SCRATCHPAD_BYTE1, 7 ; If 1, Temperature is Negative
GOTO $+3 ; NOT 0, skip over next 2 instructions
MOVLW B'00001011' ; IS 0, Temperature Negative, therefore we want to display a "-" in the 100's column.
MOVWF HUNS ; F = 0000 1011. This is the jump pointer for TABLE_WHOLE
return
;LOAD_ARRANGEMENTS ; This routine loads the 7 segment arrangments into GPR's so that CALL's don't have to be used in the interrupt
; MOVF HUNS, W ; MOVE TENS to W
; CALL TABLE_WHOLE ; CALL TABLE_WHOLE to get digit arrangement
; MOVWF HUNS_ARRANGEMENT ; MOVE arrangement to HUNS_ARRANGEMENT to use in ISR
; MOVF TENS, W ; And again for the TENS
; CALL TABLE_WHOLE ;
; MOVWF TENS_ARRANGEMENT ;
; MOVF ONES, W ; And again for the ONES
; CALL TABLE_WHOLE ;
; MOVWF ONES_ARRANGEMENT ;
; MOVF TEMPLO, W ; And again for the TENTHS
; CALL TABLE_TENTHS ;
; MOVWF TENTHS_ARRANGEMENT ;
; GOTO GET_TEMP
;=============================================
;======= LCD Routines
; Lcdout Routine
LCDout: MOVWF R4L
BSF RS
MOVLW 0x0F
ANDWF LCD_PORT,F
MOVF R4L,W
ANDLW 0xF0
IORWF LCD_PORT,F
CALL StrobeE
SWAPF R4L,F
MOVLW 0x0F
ANDWF LCD_PORT,F
MOVF R4L,W
ANDLW 0xF0
IORWF LCD_PORT,F
CALL StrobeE
MOVLW 0x32
MOVWF R4L
CALL WaitusB
RETURN
StrobeE: BSF E
NOP
NOP
NOP
NOP
NOP
BCF E
NOP
NOP
NOP
NOP
NOP
RETURN
; Lcdcmdout Routine
LCDcmdout: MOVWF R4L
BCF RS
MOVLW 0x0F
ANDWF LCD_PORT,F
MOVF R4L,W
ANDLW 0xF0
IORWF LCD_PORT,F
CALL StrobeE
SWAPF R4L,F
MOVLW 0x0F
ANDWF LCD_PORT,F
MOVF R4L,W
ANDLW 0xF0
IORWF LCD_PORT,F
CALL StrobeE
MOVLW 0xB8
MOVWF R4L
MOVLW 0x0B
MOVWF R4H
CALL WaitusW
RETURN
;LCD Init
LCDinit: BCF E
BCF RS
BSF STATUS,RP0
BCF E
BCF RS
MOVLW 0x0F
ANDWF LCD_PORT,F
BCF STATUS,RP0
MOVLW 0x64
MOVWF WaitL
MOVLW 0x00
MOVWF WaitH
CALL Waitms
MOVLW 0x33
CALL LCDcmdout
MOVLW 0x33
CALL LCDcmdout
MOVLW 0x33
CALL LCDcmdout
MOVLW 0x22
CALL LCDcmdout
MOVLW 0x28
CALL LCDcmdout
MOVLW 0x0C
CALL LCDcmdout
MOVLW 0x01
CALL LCDcmdout
return
LCD_Line1 movlw 0x80 ;move to 1st row, first column
call LCDcmdout
retlw 0x00
LCD_Line2 movlw 0xc0 ;move to 2nd row, first column
call LCDcmdout
retlw 0x00
LCD_Line1W addlw 0x80 ;move to 1st row, column W
call LCDcmdout
retlw 0x00
LCD_Line2W addlw 0xc0 ;move to 2nd row, column W
call LCDcmdout
retlw 0x00
LCD_CurOn movlw 0x0d ;Set display on/off and cursor command
call LCDcmdout
retlw 0x00
LCD_CurOff movlw 0x0c ;Set display on/off and cursor command
call LCDcmdout
retlw 0x00
LCD_Clr movlw 0x01 ;Clear display
call LCDcmdout
retlw 0x00
;=== Einde LCD Routines
;=== Welkomst Scherm
Welkom: clrf count
Wk1: movlw LOW Text1 ;Laad tabel low address byte
addwf count,w ;Add offset
movlw HIGH Text1 ;
btfsc STATUS,C ;Roll-over? (carry is set)
addlw 1 ;Ja, increment hi address byte
movwf PCLATH ;Save hi byte in PCLATH
movf count,w
call Text1
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
return
call LCDout
incf count, f
goto Wk1
return
Text1: addwf PCL, f
retlw ' '
retlw ' '
retlw ' '
retlw 'W'
retlw 'e'
retlw 'l'
retlw 'c'
retlw 'o'
retlw 'm'
retlw 'e'
retlw ' '
retlw 't'
retlw 'o'
retlw 0x00
return
Welkom2: clrf count
Wk2: movlw LOW Text2 ;Laad tabel low address byte
addwf count,w ;Add offset
movlw HIGH Text2 ;
btfsc STATUS,C ;Roll-over? (carry is set)
addlw 1 ;Ja, increment hi address byte
movwf PCLATH ;Save hi byte in PCLATH
movf count,w
call Text2
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
return
call LCDout
incf count, f
goto Wk2
return
Text2: addwf PCL, f
retlw ' '
retlw ' '
retlw 'B'
retlw 'R'
retlw 'E'
retlw 'W'
retlw '-'
retlw 'O'
retlw '-'
retlw 'M'
retlw 'A'
retlw 'T'
retlw 'I'
retlw 'C'
retlw 0x00
LCD_DS18B20_PRESENT: clrf count
Wk3: movlw LOW Text3 ;Laad tabel low address byte
addwf count,w ;Add offset
movlw HIGH Text3 ;
btfsc STATUS,C ;Roll-over? (carry is set)
addlw 1 ;Ja, increment hi address byte
movwf PCLATH ;Save hi byte in PCLATH
movf count,w
call Text3
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
return
call LCDout
incf count, f
goto Wk3
return
Text3: addwf PCL, f
retlw '='
retlw 'P'
retlw 'R'
retlw 'E'
retlw 'S'
retlw 'E'
retlw 'N'
retlw 'T'
retlw 0x00
LCD_DS18B20_RESET: clrf count
Wk4: movlw LOW Text4 ;Laad tabel low address byte
addwf count,w ;Add offset
movlw HIGH Text4 ;
btfsc STATUS,C ;Roll-over? (carry is set)
addlw 1 ;Ja, increment hi address byte
movwf PCLATH ;Save hi byte in PCLATH
movf count,w
call Text4
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
return
call LCDout
incf count, f
goto Wk4
return
Text4: addwf PCL, f
retlw 'D'
retlw 'S'
retlw '1'
retlw '8'
retlw 'B'
retlw '2'
retlw '0'
retlw ' '
retlw 'R'
retlw 'E'
retlw 'S'
retlw 'E'
retlw 'T'
retlw 0x00
LCD_DS18B20_SKIPROM: clrf count
Wk5: movlw LOW Text5 ;Laad tabel low address byte
addwf count,w ;Add offset
movlw HIGH Text5 ;
btfsc STATUS,C ;Roll-over? (carry is set)
addlw 1 ;Ja, increment hi address byte
movwf PCLATH ;Save hi byte in PCLATH
movf count,w
call Text5
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
return
call LCDout
incf count, f
goto Wk5
return
Text5: addwf PCL, f
retlw 'S'
retlw 'K'
retlw 'I'
retlw 'P'
retlw 'R'
retlw 'O'
retlw 'M'
retlw 0x00
END