Blink PortB on a 18F2620

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Blink PortB on a 18F2620

Post by CharlieM » Sat Jul 01, 2023 12:04 pm

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
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

janni
Posts: 51
Joined: Wed Aug 24, 2022 2:30 pm

Re: Blink PortB on a 18F2620

Post by janni » Sat Jul 01, 2023 2:01 pm

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.

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Blink PortB on a 18F2620

Post by Jerry Messina » Sat Jul 01, 2023 2:19 pm

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

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Blink PortB on a 18F2620

Post by Jerry Messina » Sat Jul 01, 2023 2:31 pm

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.

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Re: Blink PortB on a 18F2620

Post by CharlieM » Sat Jul 01, 2023 7:50 pm

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?
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Re: Blink PortB on a 18F2620

Post by octal » Sat Jul 01, 2023 9:19 pm

Are you sure that your EasyPIC7 dip switches (those that controls the LED rows and those controlling the pullups/pulldown) are correctly configured?

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Re: Blink PortB on a 18F2620

Post by CharlieM » Sat Jul 01, 2023 9:29 pm

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.
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Blink PortB on a 18F2620

Post by Jerry Messina » Sat Jul 01, 2023 9:57 pm

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...

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Re: Blink PortB on a 18F2620

Post by CharlieM » Sat Jul 01, 2023 11:20 pm

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.
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

Post Reply