PDA

View Full Version : blink.bas for 18f4520 for newbie - HELP



Dennis
- 14th November 2009, 18:45
Hi there

I am trying to get back into my pic programming hobby again (I had a lot of fun previously but had to stop becuase of other commitments)

Please could someone reply with the correct program to get my pic to blink an LED on PORT D 0

I have been trying for days now and am not having any luck.
I am using a pickit 2 and picbasic pro and MPLAB
I have also tried from Microcode studio and a few others.

I tried using the picbasic pro sample called blink.bas and it seems to compile and program but the led never blinks :-(

I went to a friend who did the same thing using a C complier and we programmed my 18F4520 with the hex from his compiler using MPLAb and it worked !!

Please also include the config bits I should use I think the ones I would like to switch off are watchdog and brown out detection.
I would also like to make us of the internal oscillator ..is it INTIO67 ??

Here is my code ..
Define CONFIG1L = 0x00
Define CONFIG1H = 0x02
Define CONFIG2L = 0x1a
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x03
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
Define CONFIG1L = 0x00
Define CONFIG1H = 0x08
Define CONFIG2L = 0x1a
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x83
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40


Define CLOCK_FREQUENCY = 8
AllDigital


TRISD = 0 'Sets pin 1 on port D to an output
flip:
PORTD.0 = 1 'Turn on LED
Delay 500 'Delay for .5 seconds
PORTD.0 = 0 'Turn off LED
Delay 500
goto flip


Any help would be greatly appeciated

Kind regards

Dennis

Gusse
- 15th November 2009, 00:02
Try something like this ....

<code><font color="#000000">OSCCON = $70 <font color="#000080"><i>'Int CLK 8MHz
</i></font>OSCTUNE.6 = 1 <font color="#000080"><i>'PLL 4x
</i></font>ADCON1= %00001111 <font color="#000080"><i>'$0F = disable A/D converter

</i></font>TRISA = %00000000 <font color="#000080"><i>'All pins are outputs
</i></font>TRISB = %00000000
TRISC = %00000000
TRISD = %00000000
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0

<b>DEFINE </b>OSC 32 <font color="#000080"><i>'4x 8MHz

</i></font>flip:
PORTD.0 = 1 <font color="#000080"><i>'Turn on LED
</i></font><b>PAUSE </b>500 <font color="#000080"><i>'Delay for .5 seconds
</i></font>PORTD.0 = 0 <font color="#000080"><i>'Turn off LED
</i></font><b>PAUSE </b>500
<b>GOTO </b>flip

<b>END</b></code>

and something like this should be in your 18F4520.INC file ...


<code><font color="#000000">__CONFIG _CONFIG1H, _OSC_INTIO67_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L &amp; _BOREN_OFF_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H &amp; _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L &amp; _XINST_OFF_4L</code>

Good luck!

BR,
-Gusse-

Dennis
- 16th November 2009, 11:07
Is that maybe why nothing is working when I program it ?
HELP !!!!!!!1

Melanie
- 16th November 2009, 14:04
What version of MeLabs PICBASIC or PICBASIC PRO do you have?

Dennis
- 17th November 2009, 18:45
Sorry in my rush to get things working I had somehow moved a few .inc files to another directory...
grr @ my human touch !
Thanks to all of you for the responses and help and code checks :-)
you ROCK!!