Blink.Bas on 18f45k20 Newbie seeks working example.


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2009
    Posts
    2

    Question Blink.Bas on 18f45k20 Newbie seeks working example.

    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

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by Archangel; - 28th December 2009 at 04:22.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3


    Did you find this post helpful? Yes | No

    Default Try this

    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

    Code:
    '*********************
    '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
    Last edited by Dennis; - 29th December 2009 at 02:06.

  4. #4
    Join Date
    Dec 2009
    Posts
    2


    Did you find this post helpful? Yes | No

    Smile Problem Solved...

    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

Similar Threads

  1. blink.bas for 18f4520 for newbie - HELP
    By Dennis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th November 2009, 18:45
  2. Replies: 2
    Last Post: - 13th September 2005, 18:23

Members who have read this thread : 1

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