help with pic16f887


Closed Thread
Results 1 to 40 of 61

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Write_address is for recording, bat is for reading.
    Lets say there are 3 reading:
    first reading:
    Read RTC then write at eeprom at 0
    second reading:
    Read RTC then write at eeprom at 7
    third reading:
    Read RTC then write at eeprom at 14
    ....
    Then a show is made by putting C.7 to 0
    Bat reads at 0
    then bat reads at 7
    then reads at 14.
    ...
    A write is made again it is written at Write_address = 21
    ...

    I am only using the first three anyway.
    This is not the problem, the seconds for the first three reading are the same !!!!
    eXAMPLE:
    If I take 8 readings at 5 seconds interval, My results are that the first 3 are have the same time ie: 02:04:11 , the following 3 are: 02:04:27. last two are 02:04:38
    Last edited by lerameur; - 7th December 2010 at 18:30.

  2. #2
    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.

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    OK, I found it, changed the if then for BUTTON action with a 255 debounce cycle. works great now )
    Thanks Dave for all the time you spent with me on this.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I am glad to help. Good to see you got it.
    Dave
    Always wear safety glasses while programming.

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