PDA

View Full Version : Blink.Bas on 18f45k20 Newbie seeks working example.



DiscoEd
- 28th December 2009, 03:25
Greetings,

I've been experimenting with my newly acquired Pickit3 Debug Express.
So far, I have been very successful in programming the 18f45k20 demo board using the MPLab IDE and the C18 compiler.

Once I was sure that the board was working, I decided to have go at it using PBP. Unfortunately, I can not get the LED blink on PORTD.0 (or any other pin for that matter.) I've been beating my head against this for three days.

I've tried the following...
Compiling and Programming from within MPLAB.
Result: (Seemed to put the code into the program memory, but wouldn't blink the LED)

Compiling in MPLAB and Programming with PK3CMD.exe
Result: (Seemed to put the code into the program memory, but wouldn't blink the LED)

Compiling with PBPW and Programming with PK3CMD.exe
>PBPW -aMPASMWIN -P18f45k20 blink
followed by..
>PK3CMD -P18f45k20 -fblink.hex -m -v3.25
Result: (Seemed to put the code into the program memory, but wouldn't blink the LED)

Everything seems to be working according to all of the documents I've read. Looking at the code in program memory it even seems plausible, but it just won't blink the LED.

If someone has a working snippet of code that has worked for the 18f45k20 to blink and led, I'd be grateful if you could please post it. Maybe then I could figure out what I'm doing wrong.

Thank you,
DiscoEd

Archangel
- 28th December 2009, 03:42
Hi DiscoEd,
I'l betcha your config statements are off <b> OR </b> You have not disabled the analog functions.
Hmmm analog only on ports A & B
Give us a look at your code and let's see.
EDIT:
add this to your code:
TRISE.4 = 0 'Disable PSP

Edit2: I don't know what you do / do not know about PBP, Only commands like High /Low set up tris and ports automatically. You should set port latches first then Tris registers, like so
PortA = %00000000 'binary, easiest for me
PortB = 0 'decimal
PortC = $00 'hex
PortD = %00000000
TrisA = %00000000
TrisB = %00000000
TrisC = %00000000
TrisD = %00000000
TrisE.4 = 0 'disables parallel slave port on port d
If you know all this already I do not mean to offend, trying to help

Dennis
- 29th December 2009, 02:03
Hi Discoed

Try this, I use an 18F4520 as well and this is what I used initially to get an LED blinking.
The code will cause the LED to go high then pause for 1 second and then go low and pause for one second and then loop forever. Be careful of the blink.bas example since the keyword LOOP is used for the label , however this is now reserved in PBP , so I just use the word LOOPY instead for a loop :-)

Good luck

Kind regards

Dennis



'*********************
'PIC18f4520 blink prog
'*********************

'Ocsillator selections here
'DEFINE OSC 8
'OSCCON=%01110000
'or
'DEFINE OSC 4
'OSCCON=%01100000
'OSCTUNE.6 = 0 'PLL Multiplier disabled
'OSCTUNE.6 = 1 'PLL 4x
'Ocsillator selections here
OSCCON = $70 'Int CLK 8MHz
OSCTUNE.6 = 1 'PLL 4x
ADCON1= %00001111 '$0F = disable A/D converter
cmcon = 7
INTCON2.7 = 0 'switch pull-ups ON

'END of oscillator selections
'timer/oscillator defines
DEFINE OSC 32 '4x 8MHz
'END of timer/oscillator defines

'Ports
PORTA=0
PORTB=0
PORTC=0
PORTD=0
PORTE=0
'end of port clear

'Port IO directions and presets for port pins begin here
'TRISX = %76543210 << tris bit order numbering
'TRISA = %11111111 'All pins are inputs
'// Define port pins as inputs and outputs ...
TRISA = %00000000
'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 'inputs,
TRISB = %00000000 'all output
TRISC = %10000000 'C7 is input (RX) the rest are output
TRISD = %00000000 'all output
TRISE.0 = 0 'output
TRISE.1 = 0 'output
TRISE.2 = 0 'output
'End of Port IO directions and presets for port pins begin here


'variable defined here
led var PORTD.0
'end of variables

'Main code begins here - notice it's called loopy 'cos LOOP is a reserved keyword now

loopy:
high LED ' First LED on
Pause 1000 ' Delay for 1 second
low led
Pause 1000 ' Delay for 1 second

Goto loopy ' Go back to loop and blink LED forever
End

DiscoEd
- 29th December 2009, 03:36
Joe, Dennis,

Thank you for the helpful suggestions. As guessed, I screwed up the config file. All worked fine once I set the _CONFIG1H to _FOSC_INTIO67_1H .

I'm not feeling to well this evening, but I'll post the code here tomorrow if i'm feeling better.

Thank you,
DiscoEd