blink.bas for 18f4520 for newbie - HELP


Closed Thread
Results 1 to 5 of 5
  1. #1

    Default blink.bas for 18f4520 for newbie - HELP

    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

  2. #2
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Post

    Try something like this ....
    Code:
    <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:
    <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-
    Last edited by Gusse; - 15th November 2009 at 00:06.

  3. #3


    Did you find this post helpful? Yes | No

    Default There is NO include file for the pic 18f4520

    Is that maybe why nothing is working when I program it ?
    HELP !!!!!!!1

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    What version of MeLabs PICBASIC or PICBASIC PRO do you have?

  5. #5


    Did you find this post helpful? Yes | No

    Default solved!!

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

Similar Threads

  1. Blink.Bas on 18f45k20 Newbie seeks working example.
    By DiscoEd in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th December 2009, 03:36
  2. Replies: 3
    Last Post: - 7th June 2008, 21:17
  3. Blink.bas Program
    By merlinknight in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th March 2007, 17:42
  4. blink.bas help cant make any 18f's work
    By Bonxy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th December 2004, 21:28
  5. POT Controlling Pause in Blink.bas
    By RossW in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 30th July 2004, 22:17

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts