PDA

View Full Version : 18F2550 and Blink Led



nuno106
- 9th August 2012, 15:38
Hello Everyone,

I'm trying to configure a basic program into a 18F2550, but with no luck.

I'm testing the code with a simulator, but nothing happens...

Anyone could help?


DEFINE OSC 8

@ __CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HS_1H
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG2L, _PWRT_OFF_2L & _VREGEN_OFF_2L
@ __CONFIG _CONFIG3H, _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _LVP_ON_4L & _XINST_ON_4L

PORTA = %00000000 ' Turn off all PORTA
PORTB = %00000000 ' Turn off all PORTB
ADCON1 = %01111000
ADCON2 = %10000111
TRISA = %11100111
TRISB = %11000011

loop1:
LATB.2 = 1
pause 100
LATB.2 = 0
PAUSE 100
goto loop1
end


Thanks,
Nuno

mackrackit
- 10th August 2012, 11:04
Try


@ __CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H

nuno106
- 10th August 2012, 15:21
Thanks mackrackit, I try it but the same result, the pins of the Pic doesn't change state. The oscilator is a 8MHz, MCSP 3.0.0.5 Pic Basic Pro 2.60A.

Any idea??

Thanks,
Nuno

mackrackit
- 10th August 2012, 15:47
The below works using the internal OSC for a test.
' PIC18F2550
DEFINE OSC 8
ASM
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L
ENDASM

ADCON1 = %00001111
CMCON = 7
OSCCON = %01110000
TRISB = %00000000
START

LATB.2 = 1
PAUSE 250
LATB.2 = 0
PAUSE 250
GOTO START

nuno106
- 10th August 2012, 16:20
Hello,

Compiling it, gives me some Warnings "Found Directive in column 1.(_CONFIG), but it compile. At the oshon simulator, the same result, the pins of the microcontroller doesn't change at all...

Thanks,
Nuno

mackrackit
- 10th August 2012, 16:24
I do not use simulators, I can not help you there.

For the warning, SPACE the
__CONFIG
over by one.

nuno106
- 10th August 2012, 16:31
Yes, the warning disapears... Thanks

I'll try to program the chip and test it.

Thanks,
Nuno

nuno106
- 13th August 2012, 16:24
Hello,

I've tested with the Pic, but without luck, nothing happens...

Are this configurations correct?

Thanks,
Nuno

66286629

mackrackit
- 13th August 2012, 18:28
The default location for PBP is
c:\pbp

But if it is compiling where it is...
How did PBP get installed inside of MCS?

nuno106
- 17th August 2012, 00:16
Hello mackrackit,

I don't know how pbp intalled there... i've intalled it a long time ago.

I'm looking at the assembler code, and it loops at:

CLRWDT --> Clear WTD
BTFSS PIR1,RCIF,A --> Check if Receiving bits... but i don't have nothing in my code...
BRA-3 --> Goto the CLRWDT again

anyone understand it??

Thanks,
Nuno

nuno106
- 17th August 2012, 11:58
Another thing is in ASM file (after compile), it starts with:

#define CODE_SIZE 8
#define MCS_STEP 73H
#define MCS_DUMP 64H
#define MCS_HANDSHAKE 68H
#define MCS_RESET 72H
#define MCS_WRITE 77H
#define HSER_TXSTA 36
#define HSER_SPBRG

In my program, i don't define nothing of this...

Anyone understand it??

Thanks,
Nuno

mackrackit
- 17th August 2012, 22:19
I think the best thing to do is un-install everything (PBP, MCS, MPLAB) and start over.

Darrel Taylor
- 17th August 2012, 22:44
MCS_STEP, MCS_DUMP, MCS_HANDSHAKE etc. come from the ICD (In-Circuit Debugger) in MicroCode Studio.

They only get added when you click the "ICD Compile Program" button.

When you compile a program for ICD, it will not run unless you are set up to use the ICD. (Serial connection to the PC).

If you use the normal "Compile Program" or just "Compile" buttons, the program will probably run better.

If you do not see a "Compile Program" or "Compile" button, right click on the toolbar and check the "Compile and Program" option.
You can turn off the ICD toolbar so you don't get confused in the future.

nuno106
- 20th August 2012, 11:30
Hello,

What a silly mistake... You are wright Darrel, i'm compiling always with the ICD Compile...

Thanks for your help, it's solved.

Thanks,
Nuno

CuriousOne
- 9th September 2014, 13:00
I'm trying to just compile the code below:



' PIC18F2550
DEFINE OSC 8
ADCON1 = %00001111
CMCON = 7
OSCCON = %01110000
TRISB = %00000000
START

LATB.2 = 1
PAUSE 250
LATB.2 = 0
PAUSE 250
GOTO START


It gives Block overflow for #ENDCONFIG.

MCU is 18F2550

What might be the reason?

Demon
- 9th September 2014, 14:14
START label missing colon?

Robert

CuriousOne
- 9th September 2014, 15:14
It does not helps. Still:

[ERROR] program files (89) : Block overflow for #ENDCONFIG

mackrackit
- 9th September 2014, 15:26
Post your whole cide and PBP version.

CuriousOne
- 9th September 2014, 15:32
Whole code is already posted, PBP is PBP3.

mackrackit
- 9th September 2014, 16:06
Place this at the top of your cade and see what happens.

#CONFIG
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
#ENDCONFIG

CuriousOne
- 9th September 2014, 16:44
Absolutely the same. Does it compiles for you?

mackrackit
- 9th September 2014, 16:56
This is what I tested.
Changed the config to internal though..
Compiles fine.



#CONFIG
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_INTOSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
#ENDCONFIG

DEFINE OSC 8
ADCON1 = %00001111
CMCON = 7
OSCCON = %01110000
TRISB = %00000000

START:
LATB.2 = 1
PAUSE 250
LATB.2 = 0
PAUSE 250
GOTO START

CuriousOne
- 9th September 2014, 17:37
Strange, gives the same error here, might I need to install update or something similar?

mackrackit
- 9th September 2014, 18:12
This is the best I can find that sorta refers to your problem
http://support.melabs.com/threads/54-Limit-to-config-endconfig-length?
but I do not think it applies.

Maybe try re-installing PBP3? Maybe it became corrupt ?

CuriousOne
- 11th September 2014, 08:45
Removed PBP, removed mplab and all associated apps, downloaded fresh copy of PBP, installed, still same error.

CuriousOne
- 11th September 2014, 08:54
Tried to follow this method:

http://melabs.com/support/mplab.htm

This time I get: Whitelist: Processor 18F2550 disabled in this version of PBP.
To obtain additional device support, visit melabs.com.*

Edition is student edition and 18F2550 is definitely included.

CuriousOne
- 11th September 2014, 09:08
Restarted the PC, and now compile trough MPLAB works fine, but it is not handy to do so.

CuriousOne
- 11th September 2014, 17:06
Figured out. Access restriction rules were causing the problems. Disabled UAC and it now works just fine!

n0yox
- 24th February 2018, 03:08
No blinky what am I doing wrong? The below config come from meconfig.exe.


;----[18F2550 Hardware Configuration]-------------------------------------------
#CONFIG
CONFIG PLLDIV = 5 ; Divide by 5 (20 MHz oscillator input)
CONFIG CPUDIV = OSC1_PLL2 ; [Primary Oscillator Src: /1][96 MHz PLL Src: /2]
CONFIG USBDIV = 2 ; USB clock source comes from the 96 MHz PLL divided by 2
CONFIG FOSC = INTOSCIO_EC ; Internal oscillator, port function on RA6, EC used by USB (INTIO)
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Oscillator Switchover mode disabled
CONFIG PWRT = OFF ; PWRT disabled
CONFIG BOR = ON ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
CONFIG BORV = 3 ; Minimum setting
CONFIG VREGEN = ON ; USB voltage regulator enabled
CONFIG WDT = ON ; WDT enabled
CONFIG WDTPS = 512 ; 1:512
CONFIG CCP2MX = OFF ; CCP2 input/output is multiplexed with RB3
CONFIG PBADEN = OFF ; PORTB<4:0> pins are configured as digital I/O on Reset
CONFIG LPT1OSC = OFF ; Timer1 configured for higher power operation
CONFIG MCLRE = OFF ; RE3 input pin enabled; MCLR pin disabled
CONFIG STVREN = ON ; Stack full/underflow will cause Reset
CONFIG LVP = OFF ; Single-Supply ICSP disabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
CONFIG DEBUG = OFF ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) is not code-protected
CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) is not code-protected
CONFIG CP2 = OFF ; Block 2 (004000-005FFFh) is not code-protected
CONFIG CP3 = OFF ; Block 3 (006000-007FFFh) is not code-protected
CONFIG CPB = OFF ; Boot block (000000-0007FFh) is not code-protected
CONFIG CPD = OFF ; Data EEPROM is not code-protected
CONFIG WRT0 = OFF ; Block 0 (000800-001FFFh) is not write-protected
CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) is not write-protected
CONFIG WRT2 = OFF ; Block 2 (004000-005FFFh) is not write-protected
CONFIG WRT3 = OFF ; Block 3 (006000-007FFFh) is not write-protected
CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) are not write-protected
CONFIG WRTB = OFF ; Boot block (000000-0007FFh) is not write-protected
CONFIG WRTD = OFF ; Data EEPROM is not write-protected
CONFIG EBTR0 = OFF ; Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ; Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
CONFIG EBTR2 = OFF ; Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
CONFIG EBTR3 = OFF ; Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
CONFIG EBTRB = OFF ; Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
#ENDCONFIG




ADCON1 = %00001111
CMCON = 7
OSCCON = %01110000
TRISB = %00000000
OVER:

low portb.0
PAUSE 200
high portb.0
PAUSE 200
GOTO OVER

HenrikOlsson
- 24th February 2018, 10:53
The oscillator block on the USB equipped devices are a bit complicated.
It looks to me as if you're trying to run off of the internal oscillator at 8MHz (judging by OSCCON setting INTOSC to 8MHz) yet the two least significant bits of OSCCON selects the primary oscillator - where you may or may not have a x-tal connected (you don't tell us anything about your hardware setup)?

And you have not told the compiler what frequency you're aiming to run at.

So, we need a bit more detail regarding what you're trying to do exactly.

/Henrik.

n0yox
- 24th February 2018, 15:51
Thank you for your reply. You are right I am trying to use the internal oscillator and have no idea how to setup the oscillator section. I do not plan to use any of the special features “usb ” of this processor. I did notice my mistake late last night and fixed these lines,
CONFIG FOSC = INTOSC_XT ; Internal oscillator, XT used by USB (INTXT)
CONFIG MCLRE = OFF ; RE3 input pin enabled; MCLR pin disabled

I am blinking now but have no idea how to set up the rest of the configuration. I am using the 18f2550 in place of a 16f648a to acquire more code space. I need all of my IOs to be digital with int.pullups on the top 4 of PORTB “4-7”. The datasheet is a 426 page fun read to say the least. Any help you offer will be appreciated.
Thank You,

towlerg
- 24th February 2018, 17:23
The config you have seems fine but unless you want to use the watchdog turn WDT off and you can turb VREGEN off as you're not using USB. One question though, if you aren't using USB, why not use a device similar to 2550 but with additional features and more memory eg 18F25K22?

n0yox
- 24th February 2018, 18:13
I was not aware of the 18F25K22. I should have asked for advice before I made the change. Sometimes selecting a new device can be very confusing. I will look at the data sheet for the 18F25K22 , do you have any other suggestions for a 16f648a substitute with more memory. I don’t really need the extra I/O’s just more code space.
Thank you very much!

Dave
- 24th February 2018, 21:04
If you are looking for a direct replacement I would suggest the 16F1847. Faster and twice the memory.

n0yox
- 24th February 2018, 21:13
Thank you, I will make an order on Monday. I should have asked before I started this project.
I have tried to use the pic comparison page with some luck http://www.microchip.com/maps/microcontroller.aspx
Melabs once had a very simple chart that compared many of the most common controller however they deleted that page.

I have one more question about the 18f2550 can anyone tell me how to turn on the weak pullups on the top 4 of PORTB “4-7”.

n0yox
- 24th February 2018, 21:52
Is this close?
INTCON2 = %00000000 ' makes all of portb have WPU ? INTCON2<7> 'page 116
TRISB = %00001111 'B. 0:3 are now outputs WPU is now off?

tumbleweed
- 24th February 2018, 22:30
To enable the pullups on PORTB just clear the RPBU bit in INTCON2 using INTCON2.7 = 0. It's an all or nothing thing on that chip... you can't set them individually.


TRISB = %00001111 'B. 0:3 are now outputs WPU is now off?
The comment doesn't match the setting, but to set PORTB 7:4 to inputs and the others (3:0) to outputs you'd use
TRISB = %11110000

The WPU is only enabled when the pin is set to input mode (TRIS bit = 1). It's disabled when the pin is an output (TRIS bit = 0)

n0yox
- 24th February 2018, 23:10
What I was attempting to say with that comment was that by using TRISB = %00001111 after the line containing INTCON2.7 = 0 you would set the bottom 4 bits to outputs causing those 4 bits to no longer have WPU , Maybe I have this backward and it should be TRISB = %11110000 Is this also wrong? As it turns out I need all 8 ports to have WPU’s so I will not be using that line. However for future use I would like to know the correct usage?
Thank you so much!

AvionicsMaster1
- 24th February 2018, 23:19
Try longer pauses.

richard
- 24th February 2018, 23:19
Is this also wrong?

yes its wrong , if you read the datasheet its wpu for all pins that are inputs or no pins have wpu on that port


Each of the PORTB pins has a weak internal pull-up. A
single control bit can turn on all the pull-ups. This is
performed by clearing bit, RBPU (INTCON2<7>). The
weak pull-up is automatically turned off when the port
pin is configured as an output. The pull-ups are
disabled on a Power-on Reset.

n0yox
- 25th February 2018, 00:07
"The weak pull-up is automatically turned off when the port
pin is configured as an output."

So this means all of the wpu are turned off on portb if any pin is a output on portb? I guess I thought because the data sheet said "The weak pull-up is" not "The weak pull-ups are turned off it meant just that one pin.

Thank you very much for clearing that up.

richard
- 25th February 2018, 00:12
So this means all of the wpu are turned off on portb if any pin is a output on portb?

no it means
if (INTCON2<7>) is set then all portb pull ups are off
if (INTCON2<7>) is clear then all portb pull ups are on and that no pin that is an output can have a pull up

tumbleweed
- 25th February 2018, 00:16
If there's any confusion on how to set the pin direction, I like to think of it this way... the TRIS register is short for TRI-STATE register.
If a pin is tri-state, it's floating, so it must be an input. Setting the TRIS bit = 1 enables the tri-state, so 1=input, 0=output.

CuriousOne
- 20th September 2022, 12:52
Have to get back to this thread :D
still having same issue of Block overflow
but forgot how I've fixed it......

CuriousOne
- 21st September 2022, 07:24
It is interesting - it will compile for some 18F series, but not for others.

For example, it will compile for 18F1220, but not for 18F1320, but will for 18F1520
It will compile for 18F2439 but not for 18F2550.
It will compile for 18F24K50, but won't compile for 18F24K22.

For testing purposes, I took my daughters laptop, where no PBP was ever installed, downloaded the trial version and it is absolutely the same...

HenrikOlsson
- 21st September 2022, 07:54
If you have #CONFIG / #ENDCONFIG block within your code then you'll likely need to adapt that based on which device you're compiling for since CONFIG bits aren't the same on each and every device.

I will try it if you can post the complete code that you're trying to compile.

CuriousOne
- 21st September 2022, 08:50
No, it is not about this.
just selecting MCU type, even with empty code window, and hitting compile, gives that error.

CuriousOne
- 21st September 2022, 09:40
Very interesting find.

Started windows sandbox (virtual machine)
Downloaded latest PBP trial in it, installed.
downloaded 5.45 IDE in it, also installed.
18F2550 compiles just fine!

So what this means, some of installed software, somehow prevents PBP from working correctly?

CuriousOne
- 21st September 2022, 11:46
Solved!
Mplab tools 8.84 were installed and code now compiles fine!

tumbleweed
- 21st September 2022, 12:01
If you're using MPLAB V8 then the last version was v8.92 (https://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB_IDE_8_92.zip)
For MPLABX you want MPLABX v5.35 (https://ww1.microchip.com/downloads/en/DeviceDoc/MPLABX-v5.35-windows-installer.exe)