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

    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.

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

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    OK it is now working.. somewhat, Needed to put a word instaed of a byte for the address. Now its more of a programming issue which I am stuck with. The lcd is showing recoded time, but the time does not seem to follow a normal clocking. I record at 5 sec interval, and the first three times are identical, then the next two are 15sec later but are the same...

    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,mins,hr]
    				Write_Address = Write_Address +3
    
    					Battery_Charge_Counter = Battery_Charge_Counter + 1
    		Endif	
    			
    			if PORTC.7 =0 then 
    			bat = 0
    			j=1			
                  for i =0 to Battery_Charge_Counter/3
    			  I2CREAD DPIN,CPIN,$A0,bat,[sec,mins,hr]
                  PAUSE 10
                  LCDOUT $FE,1," Time  ",DEC3 j
                  LCDOUT $FE,$C0,"WA",DEC Write_Address," T:", HEX2 hr, ":", HEX2 mins, ":", HEX2 sec
                  PAUSE 2500
    			  bat = bat +3
    			  j = j+1
    			  next i
    		Endif
    			
                GOTO Mainloop
    			End
    			
              READ_RTC:
              I2CREAD DPIN, CPIN, $D0, SecReg, [sec,mins,hr,day,date,mon,yr]
              pause 10
              RETURN
    
              SET_RTC:		' Do once at startup
              yr = $3
              mon = $5
              date = $05
              sec = $09
              mins = $05
              hr = $03
              I2CWRITE DPIN, CPIN, $D0, SecReg, [sec,mins,hr,day,date,mon,yr]
              RETURN

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Grrrrrr !!!

    Ok,
    The chips are working but my outputs are erronous. I just want to record time, store it, and then replay it. I am getting all kinds of numbers on the LCD.
    here is my latest code:
    Code:
    '/////////////////////////
    '// DS1337 and test program
    '//	Using the PIC16F887
    '//           From Dave Mackarit     FUNCTIONAL
    '/////////////////////////
    
    '/////////////////////////
    '// Define section //
    '/////////////////////////
    
    '@ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    OSCCON = %01110000 '8 Mhz
    DEFINE OSC 8
    ANSELH = 0
    
    
    '/////////////////////////
    '// LCD configuration //
    '/////////////////////////
    
    DEFINE LCD_DREG PORTB 	' Set LCD Data port
    DEFINE LCD_DBIT 4 		' Set starting Data bit (0 or 4) if 4-bit bus  RB.4, RB.5, RB.6, RB.7
    DEFINE LCD_RSREG PORTB 	' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 		' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB	' Set LCD Enable port
    DEFINE LCD_EBIT 0 		' Set LCD Enable bit
    DEFINE LCD_BITS 4 		' Set LCD bus size (4 or 8 bits) '4 therefore put wire at 4, 5, 6 and 7 of LCD
    DEFINE LCD_LINES 2 		' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 1000
    
                  DPIN    VAR PORTC.4    'I2C DATA PIN
                  CPIN    VAR PORTC.3    'I2C CLOCK PIN
                  Write_Address    VAR WORD
    			  i var byte
    			  j var byte
    			  bat var byte
    			Battery_Charge_Counter var byte
                  ' -------------- RTC definitions -----------------
              RTC CON     %11010000
              SecReg CON $00 ' seconds Write_Addressess (00 - 59) ' MSB of SecReg must be set to a 0 to enable RTC
              ContReg CON $0E ' control register
              cntrl CON %00000000 ' sets the SQW/OUT to 1Hz pulse, logic level low
              I2CWRITE DPIN, CPIN, RTC, ContReg, [cntrl]
              ' The variable below holds the values entered:
              ' entered by the user
              sec VAR BYTE : mins VAR BYTE : hr VAR BYTE : day VAR BYTE :date VAR BYTE : mon VAR BYTE : yr VAR BYTE 
    Battery_Charge_Counter = 0
    		
              PAUSE 1000
              GOSUB SET_RTC
               			Write_Address = 0    
    			  Mainloop:
    	
    	lcdout $FE,1, "Appuye sur Record"
    	lcdout $FE,$C0, "ou sur Show"
    	pause 100
    	
    		if PORTC.6 =0 then  
    			GOSUB READ_RTC
    			Write_Address =0
    				I2CWRITE DPIN,CPIN,$A0,Write_Address,[sec,mins,hr]
    				PAUSE 10
    				Write_Address = Write_Address +7
    					Battery_Charge_Counter = Battery_Charge_Counter + 1
    		Endif	
    			
    		if PORTC.7 =0 then
    					bat = 0
    					j=1
                        for i=0 to Battery_Charge_Counter
    						I2CREAD DPIN,CPIN,$A0,bat,[sec,mins,hr]
    						PAUSE 10
    						LCDOUT $FE,1," Time  ",DEC3 j
    						LCDOUT $FE,$C0,"time ",DEC Battery_Charge_Counter,":", HEX2 hr, ":", HEX2 mins, ":", HEX2 sec
    						PAUSE 2000
    						bat = bat +7
    						j= j + 1
    					next i
    					
    
    		Endif
    		
    GOTO Mainloop
    End
    			
              READ_RTC:
              I2CREAD DPIN, CPIN, $D0, SecReg, [sec,mins,hr,day,date,mon,yr]
              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

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


    Did you find this post helpful? Yes | No

    Default

    Here you are always writing starting at Address 0. The ADD 7 is always being reset.
    Code:
      if PORTC.6 =0 THEN
                            GOSUB READ_RTC
                            Write_Address =0
                                    I2CWRITE DPIN,CPIN,$A0,Write_Address,[sec,mins,hr]
                                    PAUSE 10
                                    Write_Address = Write_Address +7
                                            Battery_Charge_Counter = Battery_Charge_Counter + 1
                    Endif
    Unless I am missing something.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default OOh crap

    Ok that was not my latest one ...sorrryy !!
    here it is:
    Gining me very eronnous time (ie FF)

    Code:
    '/////////////////////////
    '// DS1337 and test program
    '//	Using the PIC16F887
    '//           From Dave Mackarit     FUNCTIONAL
    '/////////////////////////
    
    '/////////////////////////
    '// Define section //
    '/////////////////////////
    
    '@ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    OSCCON = %01110000 '8 Mhz
    DEFINE OSC 8
    ANSELH = 0
    
    
    '/////////////////////////
    '// LCD configuration //
    '/////////////////////////
    
    DEFINE LCD_DREG PORTB 	' Set LCD Data port
    DEFINE LCD_DBIT 4 		' Set starting Data bit (0 or 4) if 4-bit bus  RB.4, RB.5, RB.6, RB.7
    DEFINE LCD_RSREG PORTB 	' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 		' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB	' Set LCD Enable port
    DEFINE LCD_EBIT 0 		' Set LCD Enable bit
    DEFINE LCD_BITS 4 		' Set LCD bus size (4 or 8 bits) '4 therefore put wire at 4, 5, 6 and 7 of LCD
    DEFINE LCD_LINES 2 		' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 1000
    
                  DPIN    VAR PORTC.4    'I2C DATA PIN
                  CPIN    VAR PORTC.3    'I2C CLOCK PIN
                  Write_Address    VAR WORD
    			Battery_Charge_Counter var byte
    			bat var byte
    			i var byte
    			j var byte
                  ' -------------- RTC definitions -----------------
              RTC CON     %11010000
              SecReg CON $00 ' seconds Write_Addressess (00 - 59) ' MSB of SecReg must be set to a 0 to enable RTC
              ContReg CON $0E ' control register
              cntrl CON %00000000 ' sets the SQW/OUT to 1Hz pulse, logic level low
              I2CWRITE DPIN, CPIN, RTC, ContReg, [cntrl]
              ' The variable below holds the values entered:
              ' entered by the user
              sec VAR BYTE : mins VAR BYTE : hr VAR BYTE : day VAR BYTE :date VAR BYTE : mon VAR BYTE : yr VAR BYTE 
    Battery_Charge_Counter = 0
    		
              PAUSE 1000
              GOSUB SET_RTC
               			Write_Address = 0    
    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,mins,hr]
    				PAUSE 10
    				Write_Address = Write_Address +7
    				Battery_Charge_Counter = Battery_Charge_Counter + 1
    			Endif	
    			
    			if PORTC.7 =0 then 
    					bat = 0
    					j = 1
    					for i=0 to Battery_Charge_Counter
    						I2CREAD DPIN,CPIN,$A0,bat,[sec,mins,hr]
    						PAUSE 10
    						LCDOUT $FE,1," Time  ",DEC3 j
    						LCDOUT $FE,$C0,"AD",DEC Write_Address," T:", HEX2 hr, ":", HEX2 mins, ":", HEX2 sec
    						PAUSE 1000
    						bat = bat + 7
    						j = j + 1
    					next i
                Endif
    			
    GOTO Mainloop	
    End
    			
              READ_RTC:
              I2CREAD DPIN, CPIN, $D0, SecReg, [sec,mins,hr,day,date,mon,yr]
              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

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


    Did you find this post helpful? Yes | No

    Default

    I could not see the problem with your code so I made a test myself.
    When the EEPROM address reaches 255 the data read back for Min and Sec is FF.

    Must be crossing the boundary of rolling over because the EEPROM is full?
    It has been a long day and I am getting my bits and bytes and K and k mixed up.
    Anyone wants to clear me up we are using
    http://www.microchip.com/wwwproducts...cName=en024639

    Here is my test
    Code:
    'FL PIC18F6680
    '  18F6680(PIC)  24FC1025(EEPROM)  DS1337C(RTC)
        DEFINE OSC 20
        @ __CONFIG    _CONFIG1H, _OSC_HS_1H
        @ __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
        @ __CONFIG    _CONFIG4L, _LVP_OFF_4L
        DEFINE LCD_DREG     PORTG
        DEFINE LCD_DBIT     0
        DEFINE LCD_RSREG    PORTE
        DEFINE LCD_RSBIT    0
        DEFINE LCD_EREG     PORTE
        DEFINE LCD_EBIT     1
        DEFINE LCD_BITS     4
        DEFINE LCD_LINES    4
        DEFINE LCD_COMMANDUS    3000
        DEFINE LCD_DATAUS   150
    
        DPIN    VAR PORTB.2    'I2C DATA PIN
        CPIN    VAR PORTB.1    'I2C CLOCK PIN
        ADDR    VAR WORD
        DATI    VAR BYTE
        DATO    VAR BYTE
    
        ' -------------- RTC definitions -----------------
    RTC CON     %11010000
    SecReg CON $00 ' seconds address (00 - 59) ' MSB of SecReg must be set to a 0 to enable RTC
    ContReg CON $0E ' control register
    cntrl CON %00000000 ' sets the SQW/OUT to 1Hz pulse, logic level low
    I2CWRITE DPIN, CPIN, RTC, ContReg, [cntrl]
    ' The variable below holds the values entered:
    ' entered by the user
    sec VAR BYTE ' seconds
    mins VAR BYTE ' minutes
    hr VAR BYTE ' hours
    day VAR BYTE ' day
    date VAR BYTE ' date
    mon VAR BYTE ' month
    yr VAR BYTE ' year
    Esec VAR BYTE ' seconds
    Emins VAR BYTE ' minutes
    Ehr VAR BYTE ' hours
    I   VAR BYTE
        PAUSE 1000
    'GOSUB SET_RTC
    
    RUN: 
    ADDR = 0
    'SAVE DATA
    FOR I = 0 TO 100   
    ADDR = ADDR + 3
    I2CREAD DPIN, CPIN, RTC, SecReg, [sec,mins,hr,day,date,mon,yr]
    PAUSE 100
    I2CWRITE DPIN,CPIN,$A0,ADDR,[hr,mins,sec]
    PAUSE 100
    I2CREAD DPIN,CPIN,$A0,ADDR,[Ehr,Emins,Esec]
    PAUSE  100
    LCDOUT $FE,1,"RTC ", HEX2 hr, ":", HEX2 mins, ":", HEX2 sec
    LCDOUT $FE,$C0,"EEP ",HEX2 Ehr, ":", HEX2 Emins, ":", HEX2 Esec
    LCDOUT $FE,$90,"ADDR ", DEC ADDR
    PAUSE 1000
    NEXT I
    'READ SAVED DATA
    ADDR = 0
    FOR I = 0 TO 100
    ADDR = ADDR + 3
    I2CREAD DPIN,CPIN,$A0,ADDR,[Ehr,Emins,Esec]
    PAUSE  100
    LCDOUT $FE,1,"READ SAVED "
    LCDOUT $FE,$C0,"EEP ",HEX2 Ehr, ":", HEX2 Emins, ":", HEX2 Esec
    LCDOUT $FE,$90,"ADDR ", DEC ADDR
    NEXT I
    GOTO RUN
    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