help with pic16f887


Results 1 to 40 of 61

Threaded View

  1. #38
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Hola Dave,
    I finally got the program to work like I wanted to, well almost. Its showing the same value twice. If I hit the record button. Then I hit the show button, then it will loop twice the show with the same time.. weird... it seems its doing the loop in red twice.. always.

    Code:
    Mainloop:
    
    		if PORTC.6 =0 then  
    				GOSUB READ_RTC
    				I2CWRITE DPIN,CPIN,$A0,Write_Address,[sec,mins,hr]
    				PAUSE 10
    				Write_Address = Write_Address +3				
    		Endif	
    			
    		if PORTC.7 =0 then 
    			if Write_Address = 0 then goto Mainloop
    			j = 0
    			For i=0 to (Write_Address / 3) -1	
                  I2CREAD DPIN,CPIN,$A0,j,[sec,mins,hr]
                  PAUSE 10
                  LCDOUT $FE,1," Time  ",DEC2 i
                  LCDOUT $FE,$C0,"WA ",DEC j," T:", dec2 hr, ":", dec2 mins, ":", dec2 sec
                  PAUSE 1000
                   j =j + 3
                  next i
    		Endif
    			
    GOTO Mainloop
    End
    			
    READ_RTC:
         I2CREAD DPIN, CPIN, $D0, SecReg, [sec,mins,hr,day,date,mon,yr]
    	 pause 10
    	 			TempVal=hr
    				GoSub BCD_TO_BIN
    				hr=TempVal
    				
                    TempVal=sec
    				GoSub BCD_TO_BIN
    				sec=TempVal
    
    				TempVal=mins
    				GoSub BCD_TO_BIN
    				mins=TempVal
    RETURN
    
    SET_RTC:		' Do once at startup
        yr = $3
        mon = $5
        date = $05
        sec = $09
        mins = $04
        hr = $02
        I2CWRITE DPIN, CPIN, $D0, SecReg, [sec,mins,hr,day,date,mon,yr]
     RETURN
     
     BCD_TO_BIN:                                    ' Convert the BCD values into BIN
    
         Temp1 = $0F & TempVal                     ' Clear off the top four bits
         Temp1 = Temp1 Dig 0
         Temp2 = TempVal >> 4                       ' Shift down four to read 2 BCD value
         Temp2 = Temp2 Dig 0
         TempVal = Temp2 * 10 + Temp1
    
    Return
    Last edited by lerameur; - 11th December 2010 at 16:54.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts