So I've taken the bait! Trying to migrate from pic16f887 to pic18f4431

Thread Starter

techristian

Joined Aug 27, 2013
53
Nothing works, even on old code that worked before. BUT WAIT A MINUTE ! NOW I HAVE TO RE-INDEX ALL OF MY TABLES BECAUSE THEY ARE 2X AS LONG ! ALSO I MAY NOT HAVE TRANSLATED ALL OF THE CHIP SETTINGS PROPERLY OVER TO THE 4431. ALL OF MY TABLES NOW USE 2X AS MUCH MEMORY! 2 BYTES FOR EVERY ELEMENT IN MY TABLES. Is the TABLE command any better?

Ok I'll calm down now.

__CONFIG _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_ON & _FCMEN_ON & _LVP_OFF
__CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF

my new config below

CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG BOREN = OFF
CONFIG STVREN = ON
CONFIG LVP = OFF
CONFIG DEBUG = OFF

18f hasn't proven itself to me yet. So far a big memory hog. ...and why did MPLAB generate a MAKE FILE?
 

joeyd999

Joined Jun 6, 2011
6,204
Last edited:

Thread Starter

techristian

Joined Aug 27, 2013
53
Once again THANKS joeyd999
Do I have enough new configs to replace the old configs?

16887 config below

__CONFIG _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_ON & _FCMEN_ON & _LVP_OFF
__CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF

my new config below
18f4431 config

CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG BOREN = OFF
CONFIG STVREN = ON
CONFIG LVP = OFF
CONFIG DEBUG = OFF

the assembler didn't allow all of the old configs with the 4431

As far as GOTO's are concerned. All of mine are to LABELS so I shouldn't need to worry about where they will end up.
Yes i see a difference with the Branches. It is very similar to my experience with the MOS 6502. Anything more than +-127 has to be continued with a GOTO

example
BNZ zippoJMP
GOTO OTHERROUTINE
zippoJMP GOTO zippo

several lines of code follow

zippo do something

I needed to add the "JMP" to the end of some labels and transferred to a GOTO next

Dan
 

geekoftheweek

Joined Oct 6, 2013
1,429
18f hasn't proven itself to me yet. So far a big memory hog.
Please explain this. You only use as much memory as you program it to use. Sure there are generally more SFRs defined, but that has nothing to do with physical memory.

Edit...

I think I found where this is coming from. The 16F887 goto is only 14 bits where the 18f4431 is 32. In time you'll find simply using the access registers instead of switching banks every time to access a SFR you'll same more instruction memory than a few goto lines will eat up.
 
Last edited:

joeyd999

Joined Jun 6, 2011
6,204
Do I have enough new configs...
What I do:

Find the .inc file for your processor (ex. p18f4431.inc) in the assembler installation directory tree, and copy out the tail end of the file where the config bits are specified into a local project file called config.inc.

Modify the file so it looks like this (this example is from one of my projects using a PIC18F6xK90), and then uncomment the settings you require:

config.inc:
#ifdef __DEBUG
#define ICD
#ifndef NOCODEPROTECT
#define NOCODEPROTECT
#endif
#endif

#ifdef CPU_PIC18F65K90
    processor    18f65k90
    include     "p18f65k90.inc"
#endif

#ifdef CPU_PIC18F66K90
    processor    18f66k90
    include     "p18f66k90.inc"
#endif

#ifdef CPU_PIC18F67K90
    processor    18f67k90
    include     "p18f67k90.inc"
#endif


fosc    equ    8000000            ;8 mhz clock

;==========================================================================
;
;   IMPORTANT: For the PIC18 devices, the __CONFIG directive has been
;              superseded by the CONFIG directive.  The following settings
;              are available for this device.
;
;   VREG Sleep Enable bit:
    config    RETEN = OFF          ;Disabled - Controlled by SRETEN bit
;    config    RETEN = ON           ;Enabled
;
;   LF-INTOSC Low-power Enable bit:
    config    INTOSCSEL = LOW      ;LF-INTOSC in Low-power mode during Sleep
;    config    INTOSCSEL = HIGH     ;LF-INTOSC in High-power mode during Sleep
;
;   SOSC Power Selection and mode Configuration bits:
;    config    SOSCSEL = LOW        ;Low Power SOSC circuit selected
    config    SOSCSEL = DIG        ;Digital (SCLKI) mode
;    config    SOSCSEL = HIGH       ;High Power SOSC circuit selected
;
;   Extended Instruction Set:
    config    XINST = OFF          ;Disabled
;    config    XINST = ON           ;Enabled
;
;   Oscillator:
;    config    FOSC = LP            ;LP oscillator
;    config    FOSC = XT            ;XT oscillator
;    config    FOSC = HS2           ;HS oscillator (High power, 16 MHz - 25 MHz)
;    config    FOSC = HS1           ;HS oscillator (Medium power, 4 MHz - 16 MHz)
;    config    FOSC = EC3IO         ;EC oscillator, CLKOUT function on OSC2 (High power, 16 MHz - 64 MHz)
;    config    FOSC = EC3           ;EC oscillator (High power, 16 MHz - 64 MHz)
;    config    FOSC = RC            ;External RC oscillator, CLKOUT function on OSC2
;    config    FOSC = RCIO          ;External RC oscillator
    config    FOSC = INTIO2        ;Internal RC oscillator
;    config    FOSC = INTIO1        ;Internal RC oscillator, CLKOUT function on OSC2
;    config    FOSC = EC2IO         ;EC oscillator, CLKOUT function on OSC2 (Medium power, 160 kHz - 4 MHz)
;    config    FOSC = EC2           ;EC oscillator (Medium power, 160 kHz - 4 MHz)
;    config    FOSC = EC1IO         ;EC oscillator, CLKOUT function on OSC2 (Low power, DC - 160 kHz)
;    config    FOSC = EC1           ;EC oscillator (Low power, DC - 160 kHz)
;
;   PLL x4 Enable bit:
    config    PLLCFG = OFF         ;Disabled
;    config    PLLCFG = ON          ;Enabled
;
;   Fail-Safe Clock Monitor:
    config    FCMEN = OFF          ;Disabled
;    config    FCMEN = ON           ;Enabled
;
;   Internal External Oscillator Switch Over Mode:
    config    IESO = OFF           ;Disabled
;    config    IESO = ON            ;Enabled
;
;   Brown Out Detect:
    config    BOREN = OFF          ;Disabled in hardware, SBOREN disabled
;    config    BOREN = ON           ;Controlled with SBOREN bit
;    config    BOREN = NOSLP        ;Enabled while active, disabled in SLEEP, SBOREN disabled
;    config    BOREN = SBORDIS      ;Enabled in hardware, SBOREN disabled
;
;   Brown-out Reset Voltage bits:
;    config    BORV = 0             ;3.0V
;    config    BORV = 1             ;2.7V
;    config    BORV = 2             ;2.0V
    config    BORV = 3             ;1.8V
;
;   BORMV Power level:
    config    BORPWR = LOW         ;BORMV set to low power level
;    config    BORPWR = MEDIUM      ;BORMV set to medium power level
;    config    BORPWR = HIGH        ;BORMV set to high power level
;    config    BORPWR = ZPBORMV     ;ZPBORMV instead of BORMV is selected
;
;   Watchdog Timer:
    config    WDTEN = OFF          ;WDT disabled in hardware; SWDTEN bit disabled
;    config    WDTEN = NOSLP        ;WDT enabled only while device is active and disabled in Sleep mode; SWDTEN bit disabled
;    config    WDTEN = ON           ;WDT controlled by SWDTEN bit setting
;    config    WDTEN = SWDTDIS      ;WDT enabled in hardware; SWDTEN bit disabled
;
;   Watchdog Postscaler:
    config    WDTPS = 1            ;1:1
;    config    WDTPS = 2            ;1:2
;    config    WDTPS = 4            ;1:4
;    config    WDTPS = 8            ;1:8
;    config    WDTPS = 16           ;1:16
;    config    WDTPS = 32           ;1:32
;    config    WDTPS = 64           ;1:64
;    config    WDTPS = 128          ;1:128
;    config    WDTPS = 256          ;1:256
;    config    WDTPS = 512          ;1:512
;    config    WDTPS = 1024         ;1:1024
;    config    WDTPS = 2048         ;1:2048
;    config    WDTPS = 4096         ;1:4096
;    config    WDTPS = 8192         ;1:8192
;    config    WDTPS = 16384        ;1:16384
;    config    WDTPS = 32768        ;1:32768
;    config    WDTPS = 65536        ;1:65536
;    config    WDTPS = 131072       ;1:131072
;    config    WDTPS = 262144       ;1:262144
;    config    WDTPS = 524288       ;1:524288
;    config    WDTPS = 1048576      ;1:1048576
;
;   RTCC Clock Select:
    config    RTCOSC = INTOSCREF   ;RTCC uses INTRC
;    config    RTCOSC = SOSCREF     ;RTCC uses SOSC
;
;   CCP2 Mux:
;    config    CCP2MX = PORTBE      ;RE7-Microcontroller Mode/RB3-All other modes
    config    CCP2MX = PORTC       ;RC1
;
;   MSSP address masking:
    config    MSSPMSK = MSK5       ;5 bit address masking mode
;    config    MSSPMSK = MSK7       ;7 Bit address masking mode
;
;   Master Clear Enable:
    config    MCLRE = OFF          ;MCLR Disabled, RG5 Enabled
;    config    MCLRE = ON           ;MCLR Enabled, RG5 Disabled
;
;   Stack Overflow Reset:
    config    STVREN = OFF         ;Disabled
;    config    STVREN = ON          ;Enabled
;
;   Boot Block Size:
    config    BBSIZ = BB1K         ;1K word Boot Block size
;    config    BBSIZ = BB2K         ;2K word Boot Block size
;

#ifdef ICD

;   Power Up Timer:
;    config    PWRTEN = ON          ;Enabled
    config    PWRTEN = OFF         ;Disabled
;
;   Background Debug:
    config    DEBUG = ON           ;Enabled
;    config    DEBUG = OFF          ;Disabled

#else

;   Power Up Timer:
    config    PWRTEN = ON          ;Enabled
;    config    PWRTEN = OFF         ;Disabled
;
;   Background Debug:
;    config    DEBUG = ON           ;Enabled
    config    DEBUG = OFF          ;Disabled
;

#endif

#ifdef NOCODEPROTECT

;
;   Code Protect 00800-01FFF:
;    config    CP0 = ON             ;Enabled
    config    CP0 = OFF            ;Disabled
;
;   Code Protect 02000-03FFF:
;    config    CP1 = ON             ;Enabled
    config    CP1 = OFF            ;Disabled
;
;   Code Protect 04000-05FFF:
;    config    CP2 = ON             ;Enabled
    config    CP2 = OFF            ;Disabled
;
;   Code Protect 06000-07FFF:
;    config    CP3 = ON             ;Enabled
    config    CP3 = OFF            ;Disabled
;
;   Code Protect Boot:
;    config    CPB = ON             ;Enabled
    config    CPB = OFF            ;Disabled
;
;   Data EE Read Protect:
;    config    CPD = ON             ;Enabled
    config    CPD = OFF            ;Disabled
;
;   Table Write Protect 00800-017FF:
;    config    WRT0 = ON            ;Enabled
    config    WRT0 = OFF           ;Disabled
;
;   Table Write Protect 01800-03FFF:
;    config    WRT1 = ON            ;Enabled
    config    WRT1 = OFF           ;Disabled
;
;   Table Write Protect 04000-05FFF:
;    config    WRT2 = ON            ;Enabled
    config    WRT2 = OFF           ;Disabled
;
;   Table Write Protect 06000-07FFF:
;    config    WRT3 = ON            ;Enabled
    config    WRT3 = OFF           ;Disabled
;
;   Config. Write Protect:
;    config    WRTC = ON            ;Enabled
    config    WRTC = OFF           ;Disabled
;
;   Table Write Protect Boot:
;    config    WRTB = ON            ;Enabled
    config    WRTB = OFF           ;Disabled
;
;   Data EE Write Protect:
;    config    WRTD = ON            ;Enabled
    config    WRTD = OFF           ;Disabled
;
;   Table Read Protect 00800-017FF:
;    config    EBRT0 = ON           ;Enabled
    config    EBRT0 = OFF          ;Disabled
;
;   Table Read Protect 01800-03FFF:
;    config    EBRT1 = ON           ;Enabled
    config    EBRT1 = OFF          ;Disabled
;
;   Table Read Protect 04000-05FFF:
;    config    EBRT2 = ON           ;Enabled
    config    EBRT2 = OFF          ;Disabled
;
;   Table Read Protect 06000-07FFF:
;    config    EBRT3 = ON           ;Enabled
    config    EBRT3 = OFF          ;Disabled
;
;   Table Read Protect Boot:
;    config    EBRTB = ON           ;Enabled
    config    EBRTB = OFF          ;Disabled

#else

;   Code Protect 00800-01FFF:
    config    CP0 = ON             ;Enabled
;    config    CP0 = OFF            ;Disabled
;
;   Code Protect 02000-03FFF:
    config    CP1 = ON             ;Enabled
;    config    CP1 = OFF            ;Disabled
;
;   Code Protect 04000-05FFF:
    config    CP2 = ON             ;Enabled
;    config    CP2 = OFF            ;Disabled
;
;   Code Protect 06000-07FFF:
    config    CP3 = ON             ;Enabled
;    config    CP3 = OFF            ;Disabled
;
;   Code Protect Boot:
    config    CPB = ON             ;Enabled
;    config    CPB = OFF            ;Disabled
;
;   Data EE Read Protect:
;    config    CPD = ON             ;Enabled
    config    CPD = OFF            ;Disabled
;
;   Table Write Protect 00800-017FF:
    config    WRT0 = ON            ;Enabled
;    config    WRT0 = OFF           ;Disabled
;
;   Table Write Protect 01800-03FFF:
    config    WRT1 = ON            ;Enabled
;    config    WRT1 = OFF           ;Disabled
;
;   Table Write Protect 04000-05FFF:
    config    WRT2 = ON            ;Enabled
;    config    WRT2 = OFF           ;Disabled
;
;   Table Write Protect 06000-07FFF:
    config    WRT3 = ON            ;Enabled
;    config    WRT3 = OFF           ;Disabled
;
;   Config. Write Protect:
    config    WRTC = ON            ;Enabled
;    config    WRTC = OFF           ;Disabled
;
;   Table Write Protect Boot:
    config    WRTB = ON            ;Enabled
;    config    WRTB = OFF           ;Disabled
;
;   Data EE Write Protect:
;    config    WRTD = ON            ;Enabled
    config    WRTD = OFF           ;Disabled
;
;   Table Read Protect 00800-017FF:
;    config    EBRT0 = ON           ;Enabled
    config    EBRT0 = OFF          ;Disabled
;
;   Table Read Protect 01800-03FFF:
;    config    EBRT1 = ON           ;Enabled
    config    EBRT1 = OFF          ;Disabled
;
;   Table Read Protect 04000-05FFF:
;    config    EBRT2 = ON           ;Enabled
    config    EBRT2 = OFF          ;Disabled
;
;   Table Read Protect 06000-07FFF:
;    config    EBRT3 = ON           ;Enabled
    config    EBRT3 = OFF          ;Disabled
;
;   Table Read Protect Boot:
;    config    EBRTB = ON           ;Enabled
    config    EBRTB = OFF          ;Disabled

#endif
 

Ian0

Joined Aug 7, 2020
13,097
You surprise me: I expected the first such comment to be something like "Hey stupid head, why don't you migrate to C like us smart people?"
ARM assembler is a great language to write. I found it to be very natural progression from Atmega.
 

Thread Starter

techristian

Joined Aug 27, 2013
53
WHAT'S THIS "ACCESS" Iin my assembled code??

access?:
018A  EC8E     CALL 0x11C, 0                      371:           CALL TinyDelay
018C  F000     NOP
018E  502F     MOVF 0x2F, W, ACCESS               372:           movf RegAdress,0
0190  6E81     MOVWF PORTB, ACCESS                373:           MOVWF PORTB
0192  EC8E     CALL 0x11C, 0                      374:           CALL TinyDelay
0194  F000     NOP
0196  EC82     CALL 0x104, 0                      375:           Call inactive
0198  F000     NOP
019A  5042     MOVF 0x42, W, ACCESS               376:            MOVF MixerPointer,0;POINTER FOR TABLE
019C  90D8     BCF STATUS, 0, ACCESS              377:           BCF STATUS,0 ;CLEAR CARRY FLAG
019E  2439     ADDWF 0x39, W, ACCESS              378:           addwf Trigger777,0 ;to get proper patch table
01A0  244B     ADDWF 0x4B, W, ACCESS              379:           addwf countUpM,0 ;to get proper patch table
01A2  6E42     MOVWF 0x42, ACCESS                 380:           movwf MixerPointer;POINTER
01A4  EC8B     CALL 0x116, 0                      381:                        Call read
01A6  F000     NOP
01A8  0E0C     MOVLW 0xC                          382:           movlw HIGH MixTable
01AA  6EFA     MOVWF PCLATH, ACCESS               383:           movwf PCLATH
01AC  5042     MOVF 0x42, W, ACCESS               384:           MOVF MixerPointer,0
01AE  90D8     BCF STATUS, 0, ACCESS              385:           BCF STATUS,0 ;CLEAR CARRY FLAG
01B0  EC00     CALL 0xC00, 0                      386:            call MixTable ;GET RegData FROM TABLE
01B2  F006     NOP
01B4  6E30     MOVWF 0x30, ACCESS                 387:           MOVWF RegData
01B6  6E81     MOVWF PORTB, ACCESS                388:           movwf PORTB
01B8  EC8E     CALL 0x11C, 0                      389:           CALL TinyDelay
 

joeyd999

Joined Jun 6, 2011
6,204
WHAT'S THIS "ACCESS" Iin my assembled code??

access?:
018A  EC8E     CALL 0x11C, 0                      371:           CALL TinyDelay
018C  F000     NOP
018E  502F     MOVF 0x2F, W, ACCESS               372:           movf RegAdress,0
0190  6E81     MOVWF PORTB, ACCESS                373:           MOVWF PORTB
0192  EC8E     CALL 0x11C, 0                      374:           CALL TinyDelay
0194  F000     NOP
0196  EC82     CALL 0x104, 0                      375:           Call inactive
0198  F000     NOP
019A  5042     MOVF 0x42, W, ACCESS               376:            MOVF MixerPointer,0;POINTER FOR TABLE
019C  90D8     BCF STATUS, 0, ACCESS              377:           BCF STATUS,0 ;CLEAR CARRY FLAG
019E  2439     ADDWF 0x39, W, ACCESS              378:           addwf Trigger777,0 ;to get proper patch table
01A0  244B     ADDWF 0x4B, W, ACCESS              379:           addwf countUpM,0 ;to get proper patch table
01A2  6E42     MOVWF 0x42, ACCESS                 380:           movwf MixerPointer;POINTER
01A4  EC8B     CALL 0x116, 0                      381:                        Call read
01A6  F000     NOP
01A8  0E0C     MOVLW 0xC                          382:           movlw HIGH MixTable
01AA  6EFA     MOVWF PCLATH, ACCESS               383:           movwf PCLATH
01AC  5042     MOVF 0x42, W, ACCESS               384:           MOVF MixerPointer,0
01AE  90D8     BCF STATUS, 0, ACCESS              385:           BCF STATUS,0 ;CLEAR CARRY FLAG
01B0  EC00     CALL 0xC00, 0                      386:            call MixTable ;GET RegData FROM TABLE
01B2  F006     NOP
01B4  6E30     MOVWF 0x30, ACCESS                 387:           MOVWF RegData
01B6  6E81     MOVWF PORTB, ACCESS                388:           movwf PORTB
01B8  EC8E     CALL 0x11C, 0                      389:           CALL TinyDelay
Don't be lazy. You are going to have to spend a little bit of time perusing the datasheet to learn the differences between 16F and 18F.

Selection_042.png
 

Thread Starter

techristian

Joined Aug 27, 2013
53
With the 6502 I was allowed to create tables IN MY LINES OF CODE easily.
Here would be an example.

Table1 .byte 0,3,23,35,3,2,1,9,18

Or could I REPLACE all of my RETLW's with a BYTE or similar command ?

I have 1/2 k of tables now and this may be a game changer. Also the structure of my program is such that these DOUBLE BYTE tables mess a lot of things up, not only the Rotate Left an extra time but tables that count down (or up) until they are finished.

Dan
 

Thread Starter

techristian

Joined Aug 27, 2013
53
I'm not lazy. I can't find a command that will do this properly. I'm not having the chip write tables. Some of the tables are already written.

There is no .BYTE command or such. I could create a file and force it onto the PIC.

Dan
 

joeyd999

Joined Jun 6, 2011
6,204
db = define byte (same as your .BYTE directive)
dw = define word

tab1 db 1,2,3,4,5, ...
tab2 dw 0x1234, 0xffff, ...
tab3 db "Each character is a byte in the table\n"

Just fyi, each line of data gets word aligned in memory.

Again, don't be lazy. Pull up the docs on the assembler directives. It's a pretty powerful macro assembler.

RTFM, as they say.
 

Thread Starter

techristian

Joined Aug 27, 2013
53
"Just fyi, each line of data gets word aligned in memory."

Yes I see the disassembled code mashed up the order a bit ....first byte second , second byte first . I tried idata but couldn't find an end tag.
 
Top