PIC18F4550 question VS PIC16F887


Closed Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default PIC18F4550 question VS PIC16F887

    Hello,

    I have a code that works good with the PIC16F887, I want to be able to use it on the 18F4550 chip, the only change I made is to remove the ANSELH = 0 line, It compiles and write to the chip, but nothing is showing on my LCD. The pins are 97% identical between the two chips. This is the first time I am using the 4550 chip or any chip in the 18 series. Can someone tell me why nothing is showing up on the LCD
    thanks


    Code:
    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 PORTD.3    'I2C DATA PIN
                  CPIN    VAR PORTC.3    'I2C CLOCK PIN
    
                  ' -------------- 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
    TempVal var byte
    Temp1 var byte
    Temp2 var byte
    i var byte
    j var word
    sec VAR BYTE : mins VAR BYTE : hr VAR BYTE : day VAR BYTE :date VAR BYTE : mon VAR BYTE : yr VAR BYTE 
    Write_Address    VAR WORD
    Battery_Charge_Counter var byte
    Battery_Charge_Counter = 0
    Write_Address = 0 	
    B0 var byte
    B0 =0
    GOSUB SET_RTC
                 
    Mainloop:
    
    	lcdout $FE,1, "Appuye sur Record"
    	lcdout $FE,$C0, "ou sur Show"
    	pause 100
    	
    	 BUTTON PORTC.6,0,10,5,B0,1,Button_pressed
    		
    
    
    			
    		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
    Button_pressed:
    				GOSUB READ_RTC
    				I2CWRITE DPIN,CPIN,$A0,Write_Address,[sec,mins,hr]
    				PAUSE 10
    				Write_Address = Write_Address +3
    
    Goto Mainloop
    				
    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 = $07
        hr = $06
        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

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


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    What are you using for the OSC and did you change the configs to match?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    This is the exact program that i use for the PIC16F887. except ansel=0.
    using internal osc at 8mhz

    K

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


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    Then change the configs to use the internal...
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    I added a 20Mhz crystal and change the line to DEFINE OSC 20
    works better, I think I will change the capacitor because the text is off.
    Ok now I guess why cant i use the internal oscillator even using this do not work:
    OSCCON = %01110000 '8 Mhz
    DEFINE OSC 8

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


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    Does your configs look like this?
    This is for the internal
    Code:
    @ __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @ __CONFIG    _CONFIG1H, _FOSC_INTOSCIO_EC_1H
    @ __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    @ __CONFIG    _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
    @ __CONFIG    _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L &_XINST_OFF_4L
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    well not really Dave
    here is what I get when I compile:
    Executing: "C:\PBP2.60\PBPMPLAB.BAT" -ampasmwin -k# -p18F4550 "both.bas"
    Executing: "C:\PBP2.60\PBPW.EXE" -ampasmwin -k# -p18F4550 "both.bas"
    PICBASIC PRO(TM) Compiler 2.60A, (c) 1998, 2010 microEngineering Labs, Inc.
    All Rights Reserved.

    ERROR: Unable to execute mpasmwin.Error[118] C:\PBP2.60\BOTH.ASM 184 : Overwriting previous address contents (0000)
    Error[118] C:\PBP2.60\BOTH.ASM 184 : Overwriting previous address contents (0001)
    Skipping link step. Not all sources built successfully.
    BUILD FAILED: Sat Feb 19 14:31:44 2011


    this is the code header I used:
    Code:
    @ __CONFIG    _CONFIG1H, _FOSC_INTOSCIO_EC_1H
    DEFINE OSC 8

  8. #8
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    Dave i tried your code from this thread:
    http://www.picbasic.co.uk/forum/showthread.php?t=13981
    and it wont even compile, gives me then errors..

    ken

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


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    What are the errors?
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    here they are:

    Executing: "C:\PBP2.60\PBPMPLAB.BAT" -ampasmwin -k# -p18F4550 "both.bas"
    Executing: "C:\PBP2.60\PBPW.EXE" -ampasmwin -k# -p18F4550 "both.bas"
    PICBASIC PRO(TM) Compiler 2.60A, (c) 1998, 2010 microEngineering Labs, Inc.
    All Rights Reserved.

    ERROR: Unable to execute mpasmwin.Error[118] C:\PBP2.60\BOTH.ASM 186 : Overwriting previous address contents (0000)
    Error[118] C:\PBP2.60\BOTH.ASM 186 : Overwriting previous address contents (0001)
    Error[118] C:\PBP2.60\BOTH.ASM 195 : Overwriting previous address contents (0000)
    Error[118] C:\PBP2.60\BOTH.ASM 195 : Overwriting previous address contents (0001)
    Error[118] C:\PBP2.60\BOTH.ASM 204 : Overwriting previous address contents (0002)
    Error[118] C:\PBP2.60\BOTH.ASM 204 : Overwriting previous address contents (0003)
    Error[118] C:\PBP2.60\BOTH.ASM 213 : Overwriting previous address contents (0004)
    Error[118] C:\PBP2.60\BOTH.ASM 213 : Overwriting previous address contents (0005)
    Error[118] C:\PBP2.60\BOTH.ASM 222 : Overwriting previous address contents (0006)
    Error[118] C:\PBP2.60\BOTH.ASM 222 : Overwriting previous address contents (0007)
    Skipping link step. Not all sources built successfully.
    BUILD FAILED: Sun Feb 20 01:22:40 2011

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


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    I tried it both ways MPASM and PM, and both of them do not work. I cant even compile.

    I even tried to compile this program:http://melabs.com/samples/LABXUSB-18F4550/USBMOUSE.htm

    I can compile if I just use in the overhead: DEFINE OSC 20 and put an external 20mhz crystal, it is somewhat working, but is not keeping the timer properly and is not showing all the letter on the LCD.

  13. #13
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    Using:
    DEFINE OSC 8
    OSCCON = %01110000

    only as the overhead and compiling:
    Executing: "C:\PBP2.60\PBPMPLAB.BAT" -ampasmwin -k# -p18F4550 "both.bas"
    Executing: "C:\PBP2.60\PBPW.EXE" -ampasmwin -k# -p18F4550 "both.bas"
    PICBASIC PRO(TM) Compiler 2.60A, (c) 1998, 2010 microEngineering Labs, Inc.
    All Rights Reserved.
    Loaded C:\PBP2.60\both.COF.
    BUILD SUCCEEDED: Sun Feb 20 10:22:55 2011

    but the LCD is only showing black squares...

    K

  14. #14
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    Quote Originally Posted by lerameur View Post
    but the LCD is only showing black squares...
    That looks like a timing issue or maybe a problem with the LCD contrast. That would be my guess. To check that the timing is correct I would try to blink an LED with let's say a 1 sec on and off interval. For the contrast issue I would use a pot to see if there are any changes. Are you using the same voltage with the PIC16F887 and with the PIC18F4550?

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  15. #15
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    the pins are the same on both 887 and 4550 chips. The 4550 does work with a 20mhz crystal but the timing is off. It does not record a proper time on the RTC and when I show the time on the LCD and do not pause for 1sec but a bit less then half a second and it always shows me 08:08:08:08. and the first few letters are missing on the lCD on the first line.

    K

  16. #16
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    I change to DEFINE OSC 40 while still using a 20Mhz crystal. The text is good on the LCD , but the timer always read 08:08:08

    K

  17. #17
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    Hey Dave,

    when yo mentioned these settings:
    @ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @ __CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H
    @ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    @ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
    @ __CONFIG _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L &_XINST_OFF_4L


    should they be inside asm... endasm ? or just copy and paste ?

    also in the MPLAB I have the build option: -ampasmwin -k#

    K

  18. #18
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4550 question VS PIC16F887

    I changed the config line in the .INC file and it is now working with the 8mhz internal oscillator.
    The INC file is configure to handle external oscillator by defAULT. I am figuring how to make it work. even with the original INC file, and only user DEFINE OSC 20. the LCD is not showing any text.

    k

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