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

    I am looking over you pic pin configuration for the SDA and CLK pins but and you have them on DPIN VAR PORTB.2 'I2C DATA PIN
    CPIN VAR PORTB.1 'I2C CLOCK PIN
    What is the purpose of having SDA, CLK pins on the chip if we can use any port. Unless I am reading another chip besides the PIC18F6680.

    I also how do you make the difference between writing to the RTC and writing to the DS1337 then ?
    K

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


    Did you find this post helpful? Yes | No

    Default

    What is the purpose of having SDA, CLK pins on the chip if we can use any port. Unless I am reading another chip besides the PIC18F6680.
    The hardware ports are good for hardware interrupts and maybe a little speed. But I have not noticed much speed wise myself.

    I also how do you make the difference between writing to the RTC and writing to the DS1337 then ?
    I think you mean writing to the RTC and EEPROM...
    It IS in the Control-Address part of the command as you mentioned earlier from the post Mel did.
    The EEPROM used $A0 for the Control and a value for the location where the data is stored. In my code it is the VAR ADDR.

    The RTC uses %11010000 for the Control and $00 for the Address part. The big thing is the control byte.
    I2CWRITE DPIN,CPIN,$A0,ADDR,[DATO] 'EEPROM
    I2CREAD DPIN, CPIN, RTC, SecReg, [sec,mins,hr,day,date,mon,yr]
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Hi
    thanks you for the hand. I still do not what is wrong with my code. I will work on it tonight. Your code does work on my chip with both RTC and EEPROM chip. thank you again. I corrected a few things with my code, but I cannot getthe full thing working. What is odd is that if I run my program, first thing I do is press PORTC.7 to LCDout, I see the time I put in the RTC, but if I do it again it shows me only 255 255 255 ...

    K

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Ouff, ok I got it narrowed down now to one function, and I really really would like to know why it is not working. Here is the mainloop that is not working, the red part is where the differences are, The output is always FF.
    Code:
    Mainloop:
    	lcdout $FE,1, "Appuye sur Record"
    	lcdout $FE,$C0, "ou sur Show"
    	pause 100
    	
    			 if PORTC.6 =0 then  
    
    			GOSUB READ_RTC
    				I2CWRITE DPIN,CPIN,$A0,Write_Address,[sec]
    				Write_Address = Write_Address +1
    				PAUSE 10
    				I2CWRITE DPIN,CPIN,$A0,Write_Address,[mins]
    				Write_Address = Write_Address +1
    				PAUSE 10
    				I2CWRITE DPIN,CPIN,$A0,Write_Address,[hr]
    				Write_Address = Write_Address +1
    				PAUSE 10
    					Battery_Charge_Counter = Battery_Charge_Counter + 1
    			Endif	
    			
    			if PORTC.7 =0 then 
    			
    			 bat =0
    			 For i=0 to 2
                  I2CREAD DPIN,CPIN,$A0,bat,[sec,mins,hr]
                  PAUSE 10
                  LCDOUT $FE,1," Time  ",DEC3 i+1
                  LCDOUT $FE,$C0,"AD",DEC Write_Address,":", HEX2 hr, ":", HEX2 mins, ":", HEX2 sec
                  PAUSE 1000
    			  bat = bat+3
    			  next i
    		Endif
    			
                GOTO Mainloop
    	End
    and is is the working good, looks similar, but in the none working code I need a loop.
    Code:
     Mainloop:
    	lcdout $FE,1, "Appuye sur Record"
    	lcdout $FE,$C0, "ou sur Show"
    	pause 100
    	
    			 if PORTC.6 =0 then  
    
    			GOSUB READ_RTC
    				I2CWRITE DPIN,CPIN,$A0,Write_Address,[sec]
    				Write_Address = Write_Address +1
    				PAUSE 10
    				I2CWRITE DPIN,CPIN,$A0,Write_Address,[mins]
    				Write_Address = Write_Address +1
    				PAUSE 10
    				I2CWRITE DPIN,CPIN,$A0,Write_Address,[hr]
    				Write_Address = Write_Address +1
    				PAUSE 10
    					Battery_Charge_Counter = Battery_Charge_Counter + 1
    			Endif	
    			
    			if PORTC.7 =0 then 
    		Write_Address = 0 
                  I2CREAD DPIN,CPIN,$A0,Write_Address,[sec,mins,hr]
                  PAUSE 10
                  LCDOUT $FE,1," Time  ",DEC3 1
                  LCDOUT $FE,$C0,"AD",DEC Write_Address," T:", HEX2 hr, ":", HEX2 mins, ":", HEX2 sec
                  PAUSE 1000
    		Endif
    			
                GOTO Mainloop
    			End
    Last edited by lerameur; - 6th December 2010 at 04:12.

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


    Did you find this post helpful? Yes | No

    Default

    If this is for reading the RTC
    DPIN,CPIN,$A0,bat,[sec,mins,hr]
    then $A0 is the problem.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    NO uts reading the EEPROM.
    When PORTC.6 =0 I record from RTC to EEPROM
    And when PORTC.7=0 I show on LCD what has been recorded to EEPROM

    The only time I read RTC is in the first option C.6 using your routine GOSUB READ_RTC, that works fine.
    The program works, but if I add an IF loop it do not work ( red code above)
    I think this has been the problem since the beginning !
    K
    Last edited by lerameur; - 6th December 2010 at 13:17.

  7. #7
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Write byte

    IS it possible to write a byte at a time on the EEPROM. From the document, 2 byte ( a word is written for teh address, but I guess this is at the same place..) and the internal clock is incremented. Maybe after writting, the internal clock did not reset and when reading it keeps incrementing where it left off !?!....
    Just a thought

    .... I think the address has to be a word, not a byte. will try it tonight.

    K
    Last edited by lerameur; - 6th December 2010 at 13:59.

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