PDA

View Full Version : 18F1220 newbie



Hebemabo
- 23rd July 2014, 16:24
Hi All, I am trying to convert a 16F88 program to run on a 18F1220. For starters I tried the attached blink LED program but can't get it to work.
I'm using Pickit2, Microcode Studio and MPASM ver. 5.20.
Please look at my code and tell me what I'm doing wrong. I've spent more than 6 hours searching through the data sheet and PBP manual
but to no avail.
Ta
Hebe
'--------------------------------------------------------------------------
'Blinking LED
'######## SETUP ################################################## ##############

porta=0:portb=0 'set ports to 0 then do trises
trisb= %00001100 'portb.2&3 inputs. The rest are outputs
trisa= %00111100 'porta.2-5 inputs. The rest are outputs
WDTCON = 0 ;WDT off
ADCON0 = %00000000 ;ADC off
ADCON1 = %01111111 ;All pins digital
LVDCON = %00000000 ;LVD off
CCP1CON = %00000000 ;CCP/PWM off
OSCCON = %01110000 ;RUN mode,8MHZ,INT OSC
RCON = %00000000 ;Prioritys off
EECON1 = %00000100 ;Access flash
INTCON2 = %10000000 ;Disable PORTB pullups
INTCON3 = %00000000 ;INT1&2 disabled
PIE1 = %00000000 ;Disable A/D,EUSART,CCP,TMR2,TMR1 overflow ints
PIE2 = %00000000 ;Disable OSC Fail,EEPROM,LVD,TMR3 overflow ints
IPR1 = %00000000 ;A/D,EUSART,CCP,TMR2,TMR1 low priority
IPR2 = %00000000 ;OSC Fail,EEPROM,LVD,TMR3 ints low priority
RCON = %00000000 ;Disable priority levels
T0CON = %00000000 ;TMR0 off
T1CON = %00000000 ;TMR1 off
T2CON = %00000000 ;TMR2 off
T3CON = %00000000 ;TMR3 off
TXSTA = %00000000 ;Transmit disabled
RCSTA = %00000000 ;Receive disabled

@ CONFIG IESO=OFF & FSCM=OFF & INTIO2_OSC_1H
@ CONFIG PWRT=ON & BOR=OFF & BORV=27
@ CONFIG WDT=OFF & WDTPS=32K
@ CONFIG MCLRE=OFF
@ CONFIG DEBUG=OFF & LVP=OFF & STVR=OFF
@ CONFIG CP0=OFF & CP1=OFF
@ CONFIG CPB=OFF & CPD=OFF
@ CONFIG WRT0=OFF & WRT1=OFF
@ CONFIG WRTC=OFF & WRTB=OFF & WRTD=OFF
@ CONFIG EBTR0=OFF & EBTR1=OFF
@ CONFIG EBTRB=OFF

define OSC 8 ;8Mhz clock. osccon and define osc must be set
osccon=%01111000 ;the same for correct program timing + OSTS=1
'define OSC 4 ;4Mhz clock. osccon and define osc must be set
'OSCCON=%01101000 ;the same for correct program timing + OSTS=1
DEFINE NO_CLRWDT 1 ;don’t insert CLRWDTs


Ry1 var porta.1




rpt1:
ry1=1: pause 500: ry1=0: pause 500 ;flash of Ry1+LED
goto rpt1

LinkMTech
- 24th July 2014, 01:09
Without looking much deeper, I would suggest changing your alias to this:

Ry1 VAR LATA.1

Hebemabo
- 24th July 2014, 07:33
Thank you Louie, I changed to LATA.1 then got a syntax error due to incorrect port use which I fixed. Now I get eleven lines of "error [177].......__CONFIG directives cannot be used with CONFIG directives" . And the LED still does not blink.

Hebe

richard
- 24th July 2014, 07:43
your version of pbp is ?
is that the version of mpasm that shipped with pbp ? (looks like the one noah used)

richard
- 24th July 2014, 08:10
the pbp 2.6 inc file for an 18f1220 looks like this

;************************************************* ***************
;* 18F1220.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2006 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 06/05/06 *
;* Version : 2.47 *
;* Notes : *
;************************************************* ***************
NOLIST
ifdef PM_USED
LIST
"Error: PM does not support this device. Use MPASM."
NOLIST
else
LIST
LIST p = 18F1220, r = dec, w = -311, w = -230, f = inhx32
INCLUDE "P18F1220.INC" ; MPASM Header
__CONFIG _CONFIG1H, _XT_OSC_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG4L, _LVP_OFF_4L
NOLIST
endif
LIST
EEPROM_START EQU 0F00000h
BLOCK_SIZE EQU 8


i'm guessing your config should look like this , you need to check the config word for each setting
I you version is older then , I can't help much more



asm
__CONFIG _CONFIG1H, _XT_OSC_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG4L, _LVP_OFF_4L
endasm

Hebemabo
- 24th July 2014, 10:21
your version of pbp is ?
is that the version of mpasm that shipped with pbp ? (looks like the one noah used)

Hi Richard, I'm using PBP 2.6. Not sure if my MPASM shipped with it.

Thank you
Hebe

Hebemabo
- 24th July 2014, 10:28
the pbp 2.6 inc file for an 18f1220 looks like this



i'm guessing your config should look like this , you need to check the config word for each setting
I you version is older then , I can't help much more



asm
__CONFIG _CONFIG1H, _XT_OSC_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG4L, _LVP_OFF_4L
endasm

Hi Richard, my P18F1220.inc does not look anything like that.
I tried your config suggestion with slight mod ( see below) but it still does not work. I also tried with a copy of the .inc from MPLABX - also does not work.

Ta
Hebe
-------------------------------------------------------------------
asm
__CONFIG _CONFIG1H, _INTIO2_OSC_1H;_XT_OSC_1H
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
__CONFIG _CONFIG4L, _LVP_OFF_4L
__CONFIG _CONFIG3H, _MCLRE_OFF_3H
endasm
------------------------------------------------------------------------

richard
- 24th July 2014, 11:39
two osc configs will confuse things try , also note the indentation



asm or it could be #config
__CONFIG _CONFIG1H, _INTIO2_OSC_1H
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
__CONFIG _CONFIG4L, _LVP_OFF_4L
__CONFIG _CONFIG3H, _MCLRE_OFF_3H
endasm or #endconfig

its been ages since I used pbp 2.6
pbp3 is easier

Hebemabo
- 24th July 2014, 11:39
Hi, I have now installed MPLABX , PBP3 and MCSX. Now I get [ASM ERROR] 18F1220 NOVA BX.ASM (30) : Symbol not previously defined (_INTIO2_OSC_1H) .
I've tried a lot of permutations and found that some config statements don't give an error and others give a similar error ( or errors ) as above.
Any ideas?

richard
- 24th July 2014, 11:59
in your pbp 3 directory you should have a folder called DEVICE_REFERENCE
have a look in there for a pic18f1220.info file , all the possible config are listed there
IN A FORMAT like this

#CONFIG
CONFIG WDTEN = OFF
CONFIG PWRTEN = ON
CONFIG BOREN = OFF

CONFIG DEBUG = OFF
CONFIG XINST = OFF
#ENDCONFIG

Hebemabo
- 24th July 2014, 22:43
Hi Richard , thank you for your patience.
I tried all the changes you suggested but could not get it to work. I reverted back to PBP 2.6 and downloaded
MPLAB 8.9 which contains MPASM v5.5. I now get a bit further with seven lines of errors
similar to "overwriting previous address contents (0000)" .

Hebe

Hebemabo
- 24th July 2014, 23:23
Hi Richard , It's blinking now. I changed the config settings in the .inc file that exists in the
PBP 2.6 folder and I have no config statements in my source program.
Thank you very much for guiding me on this problem. Your help has given me confidence to continue migrating to 18F.
Hebe

richard
- 25th July 2014, 00:53
glad you got it going.
I'm not sure where to find the config statement syntax for each pic device for pbp 2.6 ,someone must know . at least pbp3 has the device reference files for you .

I'm sure having to edit the inc files is not really the best solution . in all my old pbp2.6 projects it seems I set the fuses manually with the programmer , its not until I moved to pbp3 that I included fuse settings in my programs (maybe that's why)

HenrikOlsson
- 25th July 2014, 08:24
Hi,
Open the P18F1220.INC file (or the file for whatever device you're working with) in the MPASM directory of the MPLAB installation (ie C:\Program Files\Microchip\MPASM Suite\ for example.) Towards the end you'll find the various CONFIG options and to which CONFIG Word they "belong".

/Henrik.

richard
- 25th July 2014, 10:50
thanks henrik , I knew somebody would know where to find the info.
its worth persisting on getting the config syntax right because editing the inc files will get very messy

Hebemabo
- 25th July 2014, 15:14
Thank you Henrik, I have now removed the config statements from the PBP 2.6 18F1220.inc file
and inserted the required config statements into my program. Works like a dream and no more
interfering with the .inc file.
I realise now that my problem was caused by the inclusion of the following lines in the PBP 2.6
18F1220.inc file:
"
__CONFIG _CONFIG1H, _XT_OSC_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG4L, _LVP_OFF_4L
"
I can't believe that this took thirty hours to resolve. I would most probably
have abandoned this project if I hadn't received such patient and speedy assistance from
you and Richard. And an added bonus - I don't have to go to the pains of buying new
software tools and dealing with their idiosyncrasies.

Hebe

HenrikOlsson
- 25th July 2014, 16:43
Hi,
Yes, dealing with the CONFIG bits has got to be THE single most discussed issue on this very forum and, I'm guessing, on the various support channels to MELABS - which is probably why they changed it - for the better - when releasing PBP3. That change alone is IMHO worth the cost of an upgrade, not to mention the conditional compile feature but of course YMMV.

Now that you've commented the CONFIG out of the .inc file you must remember to always include them in your source file when compiling for that particular device. If you don't they will default to their erased state.

/Henrik.