help with pic16f887


Closed Thread
Results 1 to 40 of 61

Hybrid View

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

  2. #2
    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 14:17.

  3. #3
    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 14:59.

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

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

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

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

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