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

    Hi, which picchip are you using ? would you mind posting a short code with the chip you are using. I have a few different chip (F88, F84a, F628.. ) and would like to replicate it at my home.
    The WP port is set gnd... tried both configuration anyway and still would not work, always showing zeros
    Last edited by lerameur; - 3rd December 2010 at 21:05.

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    oH MY !! it is working now, Added pull up resistors on SDA , CLK ports.. .
    I think my memory management is not good.
    It recods the first time. But all the time it shows on the LCD is 255, all for seconds, minutes hours,.....
    Can somebody tell me why so ??


    Code:
    '/////////////////////////
    '// EEPROM and test program
    '//	Using the PIC16F887
    '//
    '/////////////////////////
    
    '/////////////////////////
    '// Define section //
    '/////////////////////////
    
    '@ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    OSCCON = %01110000 '8 Mhz
    DEFINE OSC 8
    ANSELH = 0
    
    '///////////////////////////
    '// Interrupt section //
    '///////////////////////////
    
    
    '/////////////////////////
    '// 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
    
    '/////////////////////////
    '// PIN configuration //
    '/////////////////////////
    
    TRISB = %00000000 ' Set PORTB to all output
    TRISA = %11111111 ' Set PORTA to all input
    TRISC = %11000000 ' Set PORTC to all output
    
    
    '///////////////////////////////////////////////
    '// Variable Declaration and initialization //
    '///////////////////////////////////////////////
    
    Battery_Switch var byte
    i var byte
    j var byte
    Battery_Charge_Counter var byte
    
    
    SDApin var PORTC.4                     ' RTC data 
    SCLpin var PORTC.3                     ' RTC clock
    bat var byte
    Write_Address var byte
    
    RTCSec var byte :RTCMin var byte :RTCHour var byte :RTCWDay var byte :RTCDay var byte :RTCMonth var byte :RTCYear var byte :RTCCtrl var byte 
    
    
    lcdout $FE,1, "Bienvenue"
    lcdout $FE,$C0, "Welcome" 
    pause 4000
    
    I2CWRITE SDA,SCL,$D0,$00,[$00,$00,$19,$7,$14,$2,$10,$80] ' Write to DS1307
    pause 10
    
    Battery_Charge_Counter = 0 
     Write_Address = 0
    '////////////////////////////////////////////////////
    '////////////////// PROGRAM /////////////////////////
    '////////////////////////////////////////////////////
    
    Mainloop:
    
    	lcdout $FE,1, "Appuye sur Record"
    	lcdout $FE,$C0, "ou sur Show"
    	pause 200
    	
    if PORTC.6 =0 then    'always 5v, push button to gnd
    
    		I2CRead SDApin,SCLpin,$D1,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]  'read clock on DS1337
    
    		I2CWRITE SDApin,SCLpin,$A0,Write_Address,[RTCSec] ' Write to External EEPROM
    		Write_Address= Write_Address + 1
    		I2CWRITE SDApin,SCLpin,$A0,Write_Address,[RTCMin] ' Write to External EEPROM
    		Write_Address= Write_Address + 1
    		I2CWRITE SDApin,SCLpin,$A0,Write_Address,[RTCHour] ' Write to External EEPROM
    		Write_Address= Write_Address + 1
    		I2CWRITE SDApin,SCLpin,$A0,Write_Address,[RTCDay] ' Write to External EEPROM
    		Write_Address= Write_Address + 1	
    		
    		Battery_Charge_Counter = Battery_Charge_Counter + 1
    Endif
     
    if PORTC.7 =0 then      'always 5v, push button to gnd
    			j=1
    			bat = 0
    			For i=0 to Battery_Charge_Counter/4
    			I2CRead SDApin,SCLpin,$A1,bat,[RTCSec,RTCMin,RTCHour,RTCDay]
    			lcdout $FE,1, "  Time ", dec j
    			lcdout $FE,$C0, dec RTCDay,"  ", dec RTCHour,":", dec RTCMin,":", dec RTCSec
    			pause 3000
    			j = j + 1
    			i = i + 1
    			bat = bat + 4
    			next i
    Endif
    			
    goto Mainloop
    End

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


    Did you find this post helpful? Yes | No

    Default

    Is it a typo or are you trying to use the RTC and EEPROM on the same PIC pins?
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    HI,

    yes they have to be on the same picchip pins, they are one pissibility for the chip, I will try some pauses in betwwen read and wrire, but I doubt it will do any thing.

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


    Did you find this post helpful? Yes | No

    Default

    yes they have to be on the same picchip pins, they are one pissibility for the chip
    Have you used all of the other pins for something else?
    I do not think you can share a RTC and EEPROM on the same bus. Two EEROMS yes.
    Free up some pins or move to a chip that has more.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Are you saying that SDA and SCL can be used on almost any ports?? I thought they where dedicated to a specific port each..

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


    Did you find this post helpful? Yes | No

    Default

    Are you saying that SDA and SCL can be used on almost any ports?? I thought they where dedicated to a specific port each..
    Yup, I2C is a bit-banging solution, sorta like SHIFTIN/SHIFTOUT. Remember the wiki post I linked you to.

    Just be sure to have the analog turned off on the PIN you choose. MCLR does not work either. Other than that you should be good.
    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