Page 1 of 1

Blink PortB on a 18F2620

Posted: Sat Jul 01, 2023 12:04 pm
by CharlieM
Hello all,

I am trying to just blink a led to get a feel for this device. I can't seem to do that.
Here is the code I have. I am using internal OSC at 8 mhz and testing on a easypic7 dev board.
It works in Pic18 SIM IDE , but does not on hardware. Looking at the datasheet there is no OSCCON, just OSCTUNE.
Any ideas? Thanks.

Code: Select all

Device = 18F2620
Clock = 8

Config
    OSC = INTIO67,           // HS oscillator
    FCMEN = OFF,        // Fail-Safe Clock Monitor disabled
    IESO = ON,          // Oscillator Switchover mode enabled
    PWRT = ON,          // PWRT enabled
    BOREN = SBORDIS,    // Brown-out Reset enabled in hardware only (SBOREN is disabled)
    BORV = 3,           // Minimum setting
    WDT = OFF,          // WDT disabled (control is placed on the SWDTEN bit)
    WDTPS = 32768,      // 1:32768
    CCP2MX = PORTC,     // CCP2 input/output is multiplexed with RC1
    PBADEN = OFF,       // PORTB<4:0> pins are configured as digital I/O on Reset
    LPT1OSC = OFF,      // Timer1 configured for higher power operation
    MCLRE = ON,         // MCLR pin enabled; RE3 input pin disabled
    STVREN = ON,        // Stack full/underflow will cause Reset
    LVP = ON,           // Single-Supply ICSP enabled
    XINST = OFF,        // Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    DEBUG = OFF,        // Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    CP0 = OFF,          // Block 0 (000800-003FFFh) not code-protected
    CP1 = OFF,          // Block 1 (004000-007FFFh) not code-protected
    CP2 = OFF,          // Block 2 (008000-00BFFFh) not code-protected
    CP3 = OFF,          // Block 3 (00C000-00FFFFh) not code-protected
    CPB = OFF,          // Boot block (000000-0007FFh) not code-protected
    CPD = OFF,          // Data EEPROM not code-protected
    WRT0 = OFF,         // Block 0 (000800-003FFFh) not write-protected
    WRT1 = OFF,         // Block 1 (004000-007FFFh) not write-protected
    WRT2 = OFF,         // Block 2 (008000-00BFFFh) not write-protected
    WRT3 = OFF,         // Block 3 (00C000-00FFFFh) not write-protected
    WRTC = OFF,         // Configuration registers (300000-3000FFh) not write-protected
    WRTB = OFF,         // Boot Block (000000-0007FFh) not write-protected
    WRTD = OFF,         // Data EEPROM not write-protected
    EBTR0 = OFF,        // Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
    EBTR1 = OFF,        // Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
    EBTR2 = OFF,        // Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
    EBTR3 = OFF,        // Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
    EBTRB = OFF         // Boot Block (000000-0007FFh) not protected from table reads executed in other blocks


    TRISB = 0    'set PortB as output
    CMCON = 7   'Disable Comparator
    ADCON1 = 7   ' Set analog port to Digital  
    osctune.6 = 0  'Disable PLL 
    LATB = 0    ' Set LATB register to 0
    
    ' Code below blinks PortB
    While true
    
    LATB = 255
    DelayMS (500)
    LATB = 0
    DelayMS (500)
    
    Wend

Re: Blink PortB on a 18F2620

Posted: Sat Jul 01, 2023 2:01 pm
by janni
CharlieM wrote:
Sat Jul 01, 2023 12:04 pm
Looking at the datasheet there is no OSCCON, just OSCTUNE.
OSCCON register is certainly present and its setting required. See chapter 2.7.1 OSCILLATOR CONTROL REGISTER of the datasheet.
It's safer to clear whole OSCTUNE register, not just the PLL bit. And if you want to switch all analog inputs off, ADCON1 should equal 0F.

Re: Blink PortB on a 18F2620

Posted: Sat Jul 01, 2023 2:19 pm
by Jerry Messina
If you add the following :

Code: Select all

include "intosc.bas"
#option DIGITALIO_INIT = true		// automatically call SetAllDigital at startup
include "setdigitalio.bas"
it will automatically set it to use the intosc at the 'clock=' freq you've specified, and set all IO pins to digital mode when the program starts

In this case you have to add it after the config statement so that it will override any osc setting you made there (the last CONFIG seen wins).

Code: Select all

Device = 18F2620
Clock = 8

Config
    OSC = INTIO67,           // HS oscillator
    FCMEN = OFF,        // Fail-Safe Clock Monitor disabled
    IESO = ON,          // Oscillator Switchover mode enabled
    PWRT = ON,          // PWRT enabled
    BOREN = SBORDIS,    // Brown-out Reset enabled in hardware only (SBOREN is disabled)
    BORV = 3,           // Minimum setting
    WDT = OFF,          // WDT disabled (control is placed on the SWDTEN bit)
    WDTPS = 32768,      // 1:32768
    CCP2MX = PORTC,     // CCP2 input/output is multiplexed with RC1
    PBADEN = OFF,       // PORTB<4:0> pins are configured as digital I/O on Reset
    LPT1OSC = OFF,      // Timer1 configured for higher power operation
    MCLRE = ON,         // MCLR pin enabled; RE3 input pin disabled
    STVREN = ON,        // Stack full/underflow will cause Reset
    LVP = ON,           // Single-Supply ICSP enabled
    XINST = OFF,        // Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    DEBUG = OFF,        // Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    CP0 = OFF,          // Block 0 (000800-003FFFh) not code-protected
    CP1 = OFF,          // Block 1 (004000-007FFFh) not code-protected
    CP2 = OFF,          // Block 2 (008000-00BFFFh) not code-protected
    CP3 = OFF,          // Block 3 (00C000-00FFFFh) not code-protected
    CPB = OFF,          // Boot block (000000-0007FFh) not code-protected
    CPD = OFF,          // Data EEPROM not code-protected
    WRT0 = OFF,         // Block 0 (000800-003FFFh) not write-protected
    WRT1 = OFF,         // Block 1 (004000-007FFFh) not write-protected
    WRT2 = OFF,         // Block 2 (008000-00BFFFh) not write-protected
    WRT3 = OFF,         // Block 3 (00C000-00FFFFh) not write-protected
    WRTC = OFF,         // Configuration registers (300000-3000FFh) not write-protected
    WRTB = OFF,         // Boot Block (000000-0007FFh) not write-protected
    WRTD = OFF,         // Data EEPROM not write-protected
    EBTR0 = OFF,        // Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
    EBTR1 = OFF,        // Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
    EBTR2 = OFF,        // Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
    EBTR3 = OFF,        // Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
    EBTRB = OFF         // Boot Block (000000-0007FFh) not protected from table reads executed in other blocks

include "intosc.bas"
#option DIGITALIO_INIT = true		// automatically call SetAllDigital at startup
include "setdigitalio.bas"

    LATB = 0    ' Set LATB register to 0
    TRISB = 0    'set PortB as output
    
    ' Code below blinks PortB
    While true
		LATB = 255
		DelayMS (500)
		LATB = 0
		DelayMS (500)
    Wend

Re: Blink PortB on a 18F2620

Posted: Sat Jul 01, 2023 2:31 pm
by Jerry Messina
Also, on that old chip you should probably set config 'LVP = OFF' unless you specifically know you want it on.

Chips of that vintage have a PGM pin (RB5/KBI1/PGM) that gets enabled with LVP=ON, so if you don't add a pulldown on RB5 it can drop into Program mode.

Re: Blink PortB on a 18F2620

Posted: Sat Jul 01, 2023 7:50 pm
by CharlieM
Thanks for the relies.
I tried what was mentioned and I still dont any signs of life. What Im doing is I have a Serial GLCD and I don't have the user manual and it is not on the web so I thought I would write my own firmware. I have a 18F2620 in a dip package and a sop. I thought I would do the development with the dip package in a EasyPic7 and move the code to a sop( then solder it to the GLCD backpack). Well that is turning out to be harder then I thought. I am having a issue with the MikroProg suit not displaying the correct fuses when I load the hex file to program the device. This may have something to do with my issue, Thanks for the help.

PS can someone suggest a 18F device that is easier to work with?

Re: Blink PortB on a 18F2620

Posted: Sat Jul 01, 2023 9:19 pm
by octal
Are you sure that your EasyPIC7 dip switches (those that controls the LED rows and those controlling the pullups/pulldown) are correctly configured?

Re: Blink PortB on a 18F2620

Posted: Sat Jul 01, 2023 9:29 pm
by CharlieM
Hi Octal,
Hope your doing well. Yea I'm getting somewhere now. I I connected a pickit2 to the EP7 via the ISCP connector and programmed the pic and I now have a flashing portB. The fuse settings were not showing correctly in the EPprogramming software So I updated to 2.90 and now I can't connect the EP7 to the MikroProgSuite software.

Re: Blink PortB on a 18F2620

Posted: Sat Jul 01, 2023 9:57 pm
by Jerry Messina
PS can someone suggest a 18F device that is easier to work with?
The 2620 is a pretty basic one, but since you already have them it ought to work.
I wouldn't go out and buy new ones... you'd be paying a premium for older chips.

What kind of serial interface were you going to make?

Can't help much with the MikroE stuff...

Re: Blink PortB on a 18F2620

Posted: Sat Jul 01, 2023 11:20 pm
by CharlieM
HI Jerry,
I was thinking on just a Basic GLCD serial interface. I looked on SparkFun and found one they sell and found a datasheet of commands. I was was going to doing something that. I plan on having 2 different fonts big numbers and smaller letters. Thanks for the help with this.