PDA

View Full Version : PIC18F4550 question VS PIC16F887



lerameur
- 19th February 2011, 17:06
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



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

mackrackit
- 19th February 2011, 18:50
What are you using for the OSC and did you change the configs to match?

lerameur
- 19th February 2011, 18:57
This is the exact program that i use for the PIC16F887. except ansel=0.
using internal osc at 8mhz

K

mackrackit
- 19th February 2011, 19:20
Then change the configs to use the internal...

lerameur
- 19th February 2011, 19:21
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

mackrackit
- 19th February 2011, 19:24
Does your configs look like this?
This is for the internal


@ __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

lerameur
- 19th February 2011, 19:33
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:

@ __CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H
DEFINE OSC 8

lerameur
- 20th February 2011, 02:02
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

mackrackit
- 20th February 2011, 03:18
What are the errors?

lerameur
- 20th February 2011, 06:23
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

mackrackit
- 20th February 2011, 06:59
http://www.picbasic.co.uk/forum/showthread.php?t=543

lerameur
- 20th February 2011, 15:17
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.

lerameur
- 20th February 2011, 15:23
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

rsocor01
- 20th February 2011, 16:11
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

lerameur
- 20th February 2011, 16:28
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

lerameur
- 20th February 2011, 16:34
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

lerameur
- 20th February 2011, 23:14
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

lerameur
- 20th February 2011, 23:54
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