; Big LedClock Project ; ; ; Written by:Steven Easley ; Email: seasley@robotdungeon.com ; Webpage: www.robotdungeon.com ; ; ; ; ; Flags register layout ; flags b'00000000' ; ||||||| Set for display in F, clear for C ; |||||| Set for temp sensor 1, clear for sensor 2 ; ||||| ; |||| ; ||| ; || ; | ; ; LIST p=16F628 include "P16F628.inc" __CONFIG _CP_OFF &_BODEN_OFF &_PWRTE_OFF &_WDT_OFF &_LVP_OFF &_MCLRE_OFF &_INTRC_OSC_NOCLKOUT ; The defines #DEFINE clock PORTA, 0 #DEFINE datout PORTA, 1 #DEFINE latch PORTA, 2 #DEFINE set_t PORTB, 7 ;Used to enter config(1) mode for clock(0) #DEFINE mode PORTB, 6 ;Used to select between clock(0) and temp(1) #DEFINE rotate PORTB, 5 ;used to select between ferenhiet(0) and celcius(1) #DEFINE dance PORTB, 4 ;Used to select indoor(0) or outdoor(1) temperature #DEFINE set_h PORTB, 3 ;Used to set the hour #DEFINE set_m PORTB, 2 ;Used to set the minitues #DEFINE i2c_c PORTB, 1 #DEFINE i2c_d PORTB, 0 CONSTANT I2C_D=0 CONSTANT I2C_C=1 CONSTANT DATA_PIN_0 = 3 CONSTANT DATA_PIN_1 = 4 cblock 0x20 D1 ;Segment 4 D2 ;Segment 3 D3 ;Segment 2 D4 ;Segment 1 D5 ;X,I,O,F,C,P,A and dots t0 ;Temps for delay routines t1 t2 t3 temp ;Holds value to be put on the SPI and 1-wire bytes flags ;flags to control control counter hundreds ;Holds hundreds after conversion tens_and_ones ;Holds tens and ones after conversion bin ;Holds value for conversion temp_lsb temp_msb ;1-wire varibles index ;Loop contorl register o_byte ;Address of output byte i_byte ;Address of input byte ;I2C variables loop IOBYTE H0 ; HOUR 1 H1 ; HOUR 10 M0 ; MINUTE 1 M1 ; MINUTE 10 temp_01 ; Data read from DS1337 temp_02 ; Data read from DS1337 endc ;Define ram locations org 0x00 goto init ;-------------------------------------------------------------------- ;**************************** SUBROUTINES *************************** ;******************************* B2L ******************************** ; This table is used to convert BCD to LED values for the display B2L: addwf PCL,F ; b'abcdefgX' retlw b'11111100' ; 0 retlw b'01100000' ; 1 retlw b'11011010' ; 2 retlw b'11110010' ; 3 retlw b'01100110' ; 4 retlw b'10110110' ; 5 retlw b'10111110' ; 6 retlw b'11100000' ; 7 retlw b'11111110' ; 8 retlw b'11110110' ; 9 retlw b'10011100' ; C = 10 retlw b'10001110' ; F = 11 retlw b'11000110' ; "Degree sign" = 12 retlw b'00000010' ; - = 13 retlw b'00000000' ; nothing ;**************************** End B2L ******************************* ;**************************** F_conv ******************************** ;Jump table for ferenhiht conversion F_conv: addwf PCL, F ; b'nnnnnnnd' retlw b'00110010' ;0 50f 10c retlw b'00110011' ;1 51f 10.5c retlw b'00110100' ;2 52f 11c retlw b'00110101' ;3 53f 11.5c retlw b'00110110' ;4 54f 12c retlw b'00110111' ;5 55f 12.5c retlw b'00110111' ;6 55f 13c retlw b'00111000' ;7 56f 13.5c retlw b'00111001' ;8 57f 14c retlw b'00111010' ;9 58f 14.5c retlw b'00111011' ;10 59f 15c retlw b'00111100' ;11 60f 15.5c retlw b'00111101' ;12 61f 16c retlw b'00111110' ;13 62f 16.5c retlw b'00111111' ;14 63f 17c retlw b'01000000' ;15 64f 17.5c retlw b'01000000' ;16 64f 18c retlw b'01000001' ;17 65f 18.5c retlw b'01000010' ;18 66f 19c retlw b'01000011' ;19 67f 19.5c retlw b'01000100' ;20 68f 20c retlw b'01000101' ;21 69f 20.5c retlw b'01000110' ;22 70f 21c retlw b'01000110' ;23 70f 21.5c retlw b'01000111' ;24 71f 22c retlw b'01001000' ;25 72f 22.5c retlw b'01001001' ;26 73f 23c retlw b'01001010' ;27 74f 23.5c retlw b'01001011' ;28 75f 24c retlw b'01001100' ;29 76f 24.5c retlw b'01001101' ;30 77f 25c retlw b'01001110' ;31 78f 25.5c retlw b'01001111' ;32 79f 26c retlw b'01010000' ;33 80f 26.5c retlw b'01010000' ;34 80f 27c retlw b'01010001' ;35 81f 27.5c retlw b'01010010' ;36 82f 28c retlw b'01010011' ;37 83f 28.5c retlw b'01010100' ;38 84f 29c retlw b'01010101' ;39 85f 29.5c retlw b'01010110' ;40 86f 30c retlw b'01010111' ;41 87f 30.5c retlw b'01011000' ;42 88f 31c retlw b'01011001' ;43 89f 31.5c retlw b'01011010' ;44 90f 32c retlw b'01011011' ;45 91f 32.5c retlw b'01011011' ;46 91f 33c retlw b'01011100' ;47 92f 33.5c retlw b'01011101' ;48 93f 34c retlw b'01011110' ;49 94f 34.5c retlw b'01011111' ;50 95f 35c retlw b'01100000' ;51 96f 35.5c retlw b'01100001' ;52 97f 36c retlw b'01100010' ;53 98f 36.5c retlw b'01100011' ;54 99f 37c retlw b'01100100' ;55 100f 37.5c retlw b'01100100' ;56 100f 38c retlw b'01100101' ;57 101f 38.5c retlw b'01100110' ;58 102f 39c retlw b'01100111' ;59 103f 39.5c retlw b'01101000' ;60 104f 40c ; retlw b'10001000' ;0x44 68f 20c ; retlw b'10001010' ;69f 20.5c ; retlw b'10001100' ;70f 21c ; retlw b'10001101' ;70.5f 21.5c ; retlw b'10001111' ;71.5f 22c ; retlw b'10010001' ;72.5f 22.5c ; retlw b'10010011' ;73.5f 23c ; retlw b'10010100' ;74f 23.5c ; retlw b'10010110' ;75f 24c ; retlw b'10011000' ;76f 24.5c ; retlw b'10011010' ;77f 25c ; retlw b'10011100' ;78f 25.5c ; retlw b'10011110' ;79f 26c ; retlw b'10100000' ;80f 26.5c ; retlw b'10100001' ;80.5f 27c ; retlw b'10100011' ;81.5f 27.5c ; retlw b'10100101' ;82.5f 28c ; retlw b'10100111' ;83.5f 28.5c ; retlw b'10101000' ;84f 29c ; retlw b'10101010' ;85f 29.5c ; retlw b'10101100' ;86f 30c ; retlw b'10101110' ;87f 30.5c ; retlw b'10110000' ;88f 31c ; retlw b'10110010' ;89f 31.5c ; retlw b'10110100' ;90f 32c ;************************ End F_conv ******************************** ;***************************** latch_it ***************************** ; Used to latch the output line ofthe serial led driver latch_it bcf latch nop bsf latch nop bcf latch return ;*************************** End latch_it *************************** ;******************************* Disp ******************************* ; Subroutine will push the data in the digits to the serial latch ; that drive the segmented displays ; Data to be pushed is in D1,D2,D3 and D4 Disp movf D5, w call ser_out movf D1, w call ser_out movf D2, w call ser_out movf D3, w call ser_out movf D4, w call ser_out call latch_it return ;***************************** End Disp ***************************** ;***************************** ser_out ****************************** ; This routine outputs single bytes on the SPI bus ; w holds value to be pushed out ser_out movwf temp movlw d'8' ;Load counter for one byte output movwf counter movlw d'0' nextbit movf temp, w ;Load value to shift out btfsc temp, 0 ;Is current output a one? goto output_1 ;Yes output 1 goto output_0 ;No output 0 output_0 bcf datout nop nop bsf clock nop bcf clock goto rest output_1 bsf datout ;clock output line nop nop bsf clock nop bcf clock bcf datout rest rrf temp, w ;Rotate Right movwf temp decfsz counter,f ;Are we done yet goto nextbit return ;************************** End ser_out ***************************** ;******************************************************************** ;*** I2C Communcation Subroutines ;******************************************************************** ;*** OUTPUT 1 ON I2C BUS (PIN = INPUT) I2C1: bsf STATUS, RP0 ;switch to page 1 bsf PORTB, I2C_D ;set data pin to input (high impedence 1) bcf STATUS, RP0 ;switch to page 0 return ;*** OUTPUT 0 ON I2CBUS I2C0: bcf PORTB, I2C_D ;set the data output to zero bsf STATUS, RP0 ;switch to page 1 bcf PORTB, I2C_D ;set data pin to output (low impedence 0) bcf STATUS, RP0 ;switch to page 0 bcf PORTB, I2C_D ;pull data line low again return ;*** SEND I2C START CONDITION I2CSTA: call I2C1 ;output a 1 on the bus call D60us ;wait 60us bsf PORTB,I2C_C ;set the clock high call D500us ;wait 500us call I2C0 ;output a 0 on the bus call D60us ;wait 60us bcf PORTB,I2C_C ;set the clock low return ;*** SEND I2C STOP CONDITION I2CSTO: call I2C0 ;output a 0 on the bus call D60us ;wait 60us bsf PORTB,I2C_C ;set the clock high call D60us ;wait 60us call I2C1 ;output a 1 on the bus return ;*** WRITE BYTE TO I2C BUS I2CWB: movwf IOBYTE movlw .8 movwf loop I2CWB1: rlf IOBYTE, F btfss STATUS, C goto I2CWB3 goto I2CWB4 I2CWB2: decfsz loop, F goto I2CWB1 call I2C1 ; read ACK bit... call D60us bsf PORTB,I2C_C call D60us bcf PORTB,I2C_C call D60us return I2CWB3: call I2C0 ; bring DATA_PIN low call D60us bsf PORTB,I2C_C call D60us bcf PORTB,I2C_C goto I2CWB2 I2CWB4: call I2C1 call D60us bsf PORTB,I2C_C call D60us bcf PORTB,I2C_C goto I2CWB2 ;*** READ BYTE FROM I2C BUS I2CRB: call I2C1 movlw .8 movwf loop clrf IOBYTE I2CRB1: bsf PORTB,I2C_C call D60us bsf STATUS,C btfss PORTB,I2C_D bcf STATUS,C RLF IOBYTE,F bcf PORTB,I2C_C call D60us decfsz loop, F goto I2CRB1 call I2C0 call D60us bsf PORTB,I2C_C ; ACK-bit call D60us bcf PORTB,I2C_C call D60us call I2C1 call D60us movfw IOBYTE ; return the result in W return ;*** READ LAST BYTE FROM I2C BUS (NO ACK) I2CRL: call I2C1 movlw .8 movwf loop clrf IOBYTE I2CRL1: bsf PORTB,I2C_C call D60us bsf STATUS,C btfss PORTB,I2C_D bcf STATUS,C RLF IOBYTE,F bcf PORTB,I2C_C call D60us decfsz loop, F goto I2CRL1 call I2C0 call D60us bsf PORTB,I2C_C ; ACK-bit call D60us call I2C1 movfw IOBYTE ; return the result in W return ;************************* end i2c routines ************************* ;************************* binary_to_bcd **************************** ; Do the binary to BCD conversion ; Valued to be converted are in bin and are returned in hundreds ; and tens_and_ones binary_to_bcd: clrf hundreds swapf bin, W addwf bin, W andlw B'00001111' skpndc addlw 0x16 skpndc addlw 0x06 addlw 0x06 skpdc addlw -0x06 btfsc bin, 4 addlw 0x16 - 1 + 0x6 skpdc addlw -0x06 btfsc bin, 5 addlw 0x30 btfsc bin, 6 addlw 0x60 btfsc bin, 7 addlw 0x20 addlw 0x60 rlf hundreds, f btfss hundreds, 0 addlw -0x60 movwf tens_and_ones btfsc bin, 7 incf hundreds, f return ;********************** End binary_to_bcd *************************** ;******************************************************************* ;***** Delay Routines ; 500 us delay @ 4MHz D500us movlw 0xA6 ;499 cycles movwf t0 D500u decfsz t0, f goto D500u nop ;1 cycle return ; 60 us delay @ 4MHz D60us movlw 0x13 ;58 cycles movwf t0 D60 decfsz t0, f goto D60 goto $+1 ;2 cycles return ;*** 1 ms delay @ 4MHz D1ms movlw 0xC7 ;998 cycles movwf t0 movlw 0x01 movwf t1 D1m decfsz t0, f goto $+2 decfsz t1, f goto D1m goto $+1 ;2 cycles return ;"Normal" Delay 500ms @ 4MHz D500ms movlw 0x03 ;499994 cycles movwf t0 movlw 0x18 movwf t1 movlw 0x02 movwf t2 D500 decfsz t0, f goto $+2 decfsz t1, f goto $+2 decfsz t2, f goto D500 goto $+1 ;6 cycles goto $+1 goto $+1 return ;Delay for 4 seconds D4secs call D500ms call D500ms ;1 second call D500ms call D500ms ;2 second call D500ms call D500ms ;3 second call D500ms call D500ms ;4 second return ;************************** End Delay Routines ********************** ;******************************************************************** ;*** DS COMMUNICATION ;The following are standerd 1-wire routines. ;THIS IS FOR THE SENSOR ON DATA_PIN_0 ;Initilize the DS1820 initds1820_0: call pin_hi_0 call pin_lo_0 call D500us call pin_hi_0 call D500us return ;Check if the DS1820 is done converting test_0: call in_byte_0 movlw h'FF' subwf i_byte, W return ;Recieve a byte in_byte_0: movlw d'8' movwf index clrf i_byte in_byte_1_0: call pin_lo_0 nop ;Wait 1us call pin_hi_0 nop nop nop nop nop nop nop ;Wait 7us movf PORTA, W movwf temp btfss temp, DATA_PIN_0 bcf STATUS, C btfsc temp, DATA_PIN_0 bsf STATUS, C rrf i_byte, f call D60us decfsz index, f goto in_byte_1_0 movfw i_byte return ;Output a byte on the one wire out_byte_0: movlw d'8' movwf index out_byte_1_0: rrf o_byte, f btfss STATUS, C goto out_0_0 goto out_1_0 out_byte_2_0: decfsz index, f goto out_byte_1_0 return out_0_0: call pin_lo_0 call D60us call pin_hi_0 goto out_byte_2_0 out_1_0: call pin_lo_0 call pin_hi_0 call D60us goto out_byte_2_0 ;Set the 1-wire bus high pin_hi_0: bsf STATUS, RP0 bsf TRISA, DATA_PIN_0 bcf STATUS, RP0 return ;Set the 1-wire bus low pin_lo_0: bcf PORTA, DATA_PIN_0 bsf STATUS, RP0 bcf TRISA, DATA_PIN_0 bcf STATUS, RP0 return ;******************************************************************** ;THIS IS FOR THE SENSOR ON DATA_PIN_1 ;Initilize the DS1820 initds1820_1: call pin_hi_1 call pin_lo_1 call D500us call pin_hi_1 call D500us return ;Check if the DS1820 is done converting test_1: call in_byte_1 movlw h'FF' subwf i_byte, W return ;Recieve a byte in_byte_1: movlw d'8' movwf index clrf i_byte in_byte_1_1: call pin_lo_1 nop ;Wait 1us call pin_hi_1 nop nop nop nop nop nop nop ;Wait 7us movf PORTA, W movwf temp btfss temp, DATA_PIN_1 bcf STATUS, C btfsc temp, DATA_PIN_1 bsf STATUS, C rrf i_byte, f call D60us decfsz index, f goto in_byte_1_1 movfw i_byte return ;Output a byte on the one wire out_byte_1: movlw d'8' movwf index out_byte_1_1: rrf o_byte, f btfss STATUS, C goto out_0_1 goto out_1_1 out_byte_2_1: decfsz index, f goto out_byte_1_1 return out_0_1: call pin_lo_1 call D60us call pin_hi_1 goto out_byte_2_1 out_1_1: call pin_lo_1 call pin_hi_1 call D60us goto out_byte_2_1 ;Set the 1-wire bus high pin_hi_1: bsf STATUS, RP0 bsf TRISA, DATA_PIN_1 bcf STATUS, RP0 return ;Set the 1-wire bus low pin_lo_1: bcf PORTA, DATA_PIN_1 bsf STATUS, RP0 bcf TRISA, DATA_PIN_1 bcf STATUS, RP0 return ;******************************************************************** ;**************************** Disp_temp ***************************** ; Subroutine will display temp on the display Disp_temp: movwf flags clrf temp_lsb clrf temp_msb clrf temp clrf i_byte clrf o_byte btfss flags, 1 ;test to see which temp sensor to read goto Geta goto Getb Geta movlw 0x00 call Get_tempa ;Read the tempurateure sensor goto Next Getb movlw 0x00 call Get_tempb Next btfss flags, 0 goto Cel Fer movf temp_lsb, w ;Load temp_lsb sublw d'20' ;Subtract 40 to create jump (40-lsb) subwf 0, W ;Invert value to be -(40-lsb) call F_conv ;Call conversion table movwf temp_lsb ;Store tempurature in ferheinght bcf STATUS, C rlf temp_lsb, f Cel movf temp_lsb, w rrf temp_lsb, w movwf bin call binary_to_bcd movlw .14 call B2L movwf D4 btfss hundreds, 0 goto temp_rest movlw .1 call B2L movwf D4 temp_rest movf tens_and_ones, W swapf tens_and_ones, W andlw 0x0F call B2L movwf D3 movf tens_and_ones, W andlw B'00001111' call B2L movwf D2 ; btfss flags, 0 ; goto Celcius ;Ferehnit ; movlw .11 ;F ; call B2L ; movwf D1 ; goto Degree ;Celcius ; movlw .10 ;C ; call B2L ; movwf D1 ; goto Degree Degree movlw .12 ;degree symbol call B2L movwf D1 call Disp return ;************************** End Disp_temp *************************** ;****************************** Get_tempa *************************** ; This will read the temp from the DS1820 on DATA_PIN_0 Get_tempa: clrf temp_lsb clrf temp_msb clrf temp clrf i_byte clrf o_byte call initds1820_0 ;Initilize the ds1820 movlw h'CC' ;Send skip ROM command movwf o_byte call out_byte_0 movlw h'44' ;Send start conversion command movwf o_byte call out_byte_0 Wait_0: call test_0 btfss STATUS, Z goto Wait_0 call initds1820_0 ;Reinitilize the DS1820 movlw h'CC' ;Send skip ROM command movwf o_byte call out_byte_0 movlw h'BE' ;Send command movwf o_byte call out_byte_0 call in_byte_0 ;Read in tempurature LSB movwf temp_lsb call in_byte_0 ;Read in tempurature MSB movwf temp_msb return ;************************** End Get_tempa *************************** ;****************************** Get_tempa *************************** ; This will read the temp from the DS1820 on DATA_PIN_0 Get_tempb: clrf temp_lsb clrf temp_msb clrf temp clrf i_byte clrf o_byte call initds1820_1 ;Initilize the ds1820 movlw h'CC' ;Send skip ROM command movwf o_byte call out_byte_1 movlw h'44' ;Send start conversion command movwf o_byte call out_byte_1 Wait_1: call test_1 btfss STATUS, Z goto Wait_1 call initds1820_1 ;Reinitilize the DS1820 movlw h'CC' ;Send skip ROM command movwf o_byte call out_byte_1 movlw h'BE' ;Send command movwf o_byte call out_byte_1 call in_byte_1 ;Read in tempurature LSB movwf temp_lsb call in_byte_1 ;Read in tempurature MSB movwf temp_msb return ;************************** End Get_tempb *************************** ;******************************* Hello ****************************** ; SCROLL "HELLO" HELLO: MOVLW b'00000000' ; " " MOVWF D5 MOVWF D4 MOVWF D3 MOVWF D2 MOVWF D1 CALL Disp CALL D500ms MOVLW b'01101110' ; " H" MOVWF D1 CALL Disp CALL D500ms MOVF D1,W ; " HE" MOVWF D2 MOVLW b'10011110' MOVWF D1 CALL Disp CALL D500ms MOVF D2,W ; " HEL" MOVWF D3 MOVF D1,W MOVWF D2 MOVLW b'00011100' MOVWF D1 CALL Disp CALL D500ms MOVF D3,W ; "HELL" MOVWF D4 MOVF D2,W MOVWF D3 MOVF D1,W MOVWF D2 MOVLW b'00011100' MOVWF D1 CALL Disp CALL D500ms MOVF D3,W ; "ELLO" MOVWF D4 MOVF D2,W MOVWF D3 MOVF D1,W MOVWF D2 MOVLW b'11111100' MOVWF D1 CALL Disp CALL D500ms MOVF D3,W ; "LLO " MOVWF D4 MOVF D2,W MOVWF D3 MOVF D1,W MOVWF D2 MOVLW b'00000000' MOVWF D1 CALL Disp CALL D500ms MOVF D3,W ; "LO " MOVWF D4 MOVF D2,W MOVWF D3 MOVF D1,W MOVWF D2 MOVLW b'00000000' MOVWF D1 CALL Disp CALL D500ms MOVF D3,W ; "O " MOVWF D4 MOVF D2,W MOVWF D3 MOVF D1,W MOVWF D2 MOVLW b'00000000' MOVWF D1 CALL Disp CALL D500ms MOVF D3,W ; " " MOVWF D4 MOVF D2,W MOVWF D3 MOVF D1,W MOVWF D2 MOVLW b'00000000' MOVWF D1 CALL Disp CALL D500ms RETURN ;************************** End Hello ******************************* ;************************** setclock ******************************** setclock call get_time set_clk btfsc set_h goto check_m ;If not pressed goto check_m btfss H1, 0 goto check_H0 ;if not equal to 1 check ones digit movf H0, w ;check if it is 10 0'clock sublw d'0' btfsc STATUS, Z goto inc_H0 movf H0, w ;check if it is 11 0'clock sublw d'1' btfsc STATUS, Z goto inc_H0 movf H0, w ;check if it is 12 0'clock sublw d'2' btfss STATUS, Z goto inc_H0 bcf H1, 0 movlw d'1' movwf H0 btfsc H1, 1 goto Set_PM bsf H1, 1 goto check_m Set_PM bcf H1, 1 goto check_m check_H0 ;Increment the hours and check if number is out of range movf H0,w ;load the ones hours sublw d'9' ;check if equal to 9 btfss STATUS, Z goto inc_H0 clrf H0 ;clear the ones and increment the tens goto inc_H1 inc_H0 movf H0, w incf H0, w movwf H0 goto check_conf inc_H1 movf H1, w incf H1, w movwf H1 goto check_conf check_m btfsc set_m goto check_conf movf M0, w sublw .9 btfss STATUS, Z goto inc_M0 movf M1, w sublw .5 btfss STATUS, Z goto inc_M1 clrf M0 clrf M1 goto check_conf inc_M0 movf M0, w incf M0, w movwf M0 goto check_conf inc_M1 clrf M0 movf M1, w incf M1, w movwf M1 goto check_conf check_conf call D500ms call Disp_time btfss set_t goto set_clk call write_time return ;************************** End setclock **************************** ;**************************** Disp_time ***************************** Disp_time ; IOFCDPAx movlw b'00001010' ;Default to AM movwf D5 btfss H1, 1 goto Disp_next ; IOFCDPAx movlw b'00001100' ;Show PM movwf D5 Disp_next movlw .14 call B2L movwf D4 btfss H1, 0 goto Disp_hours movlw .1 call B2L movwf D4 Disp_hours movf H0, w call B2L movwf D3 movf M1, w call B2L movwf D2 movf M0, w call B2L movwf D1 call Disp return ;************************** End Disp_time *************************** ;**************************** get_time ****************************** get_time call I2CSTA movlw 0xD0 ; address + write cmnd call I2CWB movlw b'00000001' ; start at address 01h call I2CWB call I2CSTO ; stop address send call I2CSTA movlw 0xD1 ; address + read cmnd call I2CWB call I2CRB ; read info from addr. 01h movwf temp_01 call I2CRL ; read info from addr. 02h movwf temp_02 ;In theory current time is in temp_01 and temp_02 movf temp_01, w andlw 0x0F ; Isolate the minutes ones movwf M0 swapf temp_01, w ; Isolate the minutes tens andlw 0x07 movwf M1 movf temp_02, w andlw 0x0F ; Isolate the hours ones movwf H0 swapf temp_02, w ;Isolate the hours tens andlw 0x03 movwf H1 return ;************************** End get_time **************************** ;*************************** write_time ***************************** write_time ; First we prepare the time to be written movf H1, w ;load the hours tens btfsc H1, 0 ;check if hours is 10,11 or 12 goto go_one goto go_zero go_one bsf temp_02, 4 goto ck_H0 go_zero bcf temp_02, 4 movf H1, w ;load the hours tens btfss H1, 1 ;check if AM/PM goto go_am goto go_pm go_am bcf temp_02, 5 goto ck_H0 go_pm bsf temp_02, 5 ck_H0 movf temp_02, w andlw 0xF0 movwf temp_02 movf H0, w ; load the hours ones andlw 0x0F ; isolate the important bits addwf temp_02, w ; add with the hours tens movwf temp_02 ck_M1 clrf temp_01 swapf M1, w ; load the minutes tens andlw 0xF0 ; isolate movwf temp_01 ck_M0 movf M0, w andlw 0x0F addwf temp_01, w movwf temp_01 ; save the result bsf temp_02, 6 call I2CSTA ; movlw b'11010000' ; address + write cmnd call I2CWB movlw 0x00 ; send register address call I2CWB movlw 0x00 ;write seconds to the rtc call I2CWB movf temp_01, w ;write hours to the rtc call I2CWB movf temp_02, w ;write min to the rtc call I2CWB call I2CSTO return ;************************* END SUBROUTINES ************************** ;******************************************************************** ;Setup stuff init movlw 0x07 ;Turn off the analog comparators movwf CMCON bsf STATUS, RP0 ;Goto page 1 movlw b'00011000' ;Make port A4,3 input all others output movwf TRISA movlw b'11111101' movwf TRISB ;Setup Port B bcf STATUS, RP0 ;Goto page 0 bcf clock ;clear output pins bcf datout bcf latch ;Make damn sure that the display is clear clrf D5 clrf D4 clrf D3 clrf D2 clrf D1 call Disp call I2CSTO ;send stop condition call D500ms ;wait 500ms for circuit to settle call I2CSTA ; set DS1337 code word to 00h movlw b'11010000' ; address + write cmnd call I2CWB movlw 0x0E ; send register address call I2CWB movlw 0x00 ; clear all the bits call I2CWB call I2CSTO call get_time movf temp_02, w bsf temp_02, 6 movwf temp_02 call I2CSTA ; movlw b'11010000' ; address + write cmnd call I2CWB movlw 0x02 ; send register address call I2CWB movf temp_02,w ;set to 12 hour mode call I2CWB call I2CSTO call D500ms ;Wait 1 secs for things to settle call D500ms call HELLO ;********************* Begin the main Program HERE******************* ;This is the main program main btfss dance goto lets_dance btfss mode ;What should we display goto temp_sel goto clk_sel temp_sel ; IOFCDPAx movlw b'10010000' ;Indoor - Celcius movwf D5 movlw b'00000000' ;Call with 0 in w for celcius call Disp_temp ;1 for ferenhight call D4secs ; IOFCDPAx movlw b'10100000' ;Indoor - Ferenheit movwf D5 movlw b'00000001' ;Call with 0 in w for celcius call Disp_temp ;1 for ferenhight call D4secs ; IOFCDPAx movlw b'01010000' ;Outdoor - Celcius movwf D5 movlw b'00000010' ;Call with 0 in w for celcius call Disp_temp ;1 for ferenhight call D4secs ; IOFCDPAx movlw b'01100000' ;Outdoor - Ferenheit movwf D5 movlw b'00000011' ;Call with 0 in w for celcius call Disp_temp ;1 for ferenhight call D4secs goto main clk_sel btfss set_t call setclock call get_time call Disp_time call D4secs btfsc rotate goto main ; IOFCDPAx movlw b'10010000' ;Indoor - Celcius movwf D5 movlw b'00000000' ;Call with 0 in w for celcius call Disp_temp ;1 for ferenhight call D4secs ; IOFCDPAx movlw b'10100000' ;Indoor - Ferenheit movwf D5 movlw b'00000001' ;Call with 0 in w for celcius call Disp_temp ;1 for ferenhight call D4secs ; IOFCDPAx movlw b'01010000' ;Outdoor - Celcius movwf D5 movlw b'00000010' ;Call with 0 in w for celcius call Disp_temp ;1 for ferenhight call D4secs ; IOFCDPAx movlw b'01100000' ;Outdoor - Ferenheit movwf D5 movlw b'00000011' ;Call with 0 in w for celcius call Disp_temp ;1 for ferenhight call D4secs goto main ;Goto main and start next conversion lets_dance call HELLO goto main end