Getting 18F458 to blink


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2008
    Posts
    15

    Default Getting 18F458 to blink

    Hey fellow PICers

    After a few projects with PIC 16F series, I try to move on to the more advanced PIC 18F series. But already at the very beginning I got stuck. I tried already to solve it for days, but I have no more clue…

    The hardware setup: PIC 18F458, 20Mhz Xtal on pins OSC1 and OSC2, two 15p caps for the Xtal, an LED with resistor on PORTD.2 (pin 21)

    The program:
    Code:
    define OSC 20                ' Quarz = 20 MHz
    clear
    
    ADCON1 = 15 ' all digital
    
    LED        var    portd.2
    
    RxTx       var    portc.5
    RS485Rx    var    portc.7
    RS485Tx    var    portc.6
    
    loop:
       toggle led
       pause 500
       low led
    goto loop
    I had to change the __CONFIG lines in the .inc file in order to work with MPLAB like this:
    Code:
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F458, r = dec, w = -311, w = -230, f = inhx32
            INCLUDE "P18F458.INC"   ; MPASM  Header
            ;__CONFIG    _CONFIG1H, _OSCS_OFF_1H & _HS_OSC
            ;__CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
            ;__CONFIG    _CONFIG4L, _LVP_OFF_4L
        CONFIG OSCS=OFF,OSC=HS,WDT=ON,WDTPS=128,LVP=OFF
            NOLIST
        endif
            LIST
    EEPROM_START    EQU    0F00000h
    BLOCK_SIZE    EQU    8
    It compiles and burns into the PIC with no errors.
    What happens when I turn on power is that the LED is always lit. No blinkin’, nothin’

    How can I check if the Xtal works? Or any other hints what to do anyone?

    Thanx & keep on PICin’

    Helloo

  2. #2
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Getting 18F458 to blink

    Try adding CMCON=7 to your code to disable the comparator

    EDIT: ADCON1=6 would be all digital, ADCON1=15 makes AN0 analog with AN3 VREF+ and AN2 VREF-
    Last edited by spcw1234; - 31st January 2012 at 01:40.
    Shawn

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: Getting 18F458 to blink

    And you can remove LOW LED at the bottom. Toggle will change the state for you; if it was ON, it will turn OFF, and vice versa.

    Do you really need the watchdog timer?

    Can you put the CONFIG statement in the include like that?
    (never saw that before, usually it's at the top of your program, but I don't use MPLAB).

    Robert

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Getting 18F458 to blink

    It may be working just perfect. In your loop the first thing you do is toggle the led. Then you pause for half a second. Then you set the output low and instantly go back to the top of the loop, where you will toggle again turning on the led. As was suggested, remove the low led command. Or you could add another pause after it so you will have time to see it go low.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Feb 2008
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Re: Getting 18F458 to blink

    All three of you where right. Thank you all. Deleted the "LED low" command (wich I added after nothing happened). Added "CMCON = 7" as Shawn suggested. Now it works. Grrrmmm three lousy bits, many days no sleep...

    @Demon: Both ways work. But if the CONFIG is in the include file, it mustn't be in the program and vice versa.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Getting 18F458 to blink

    Quote Originally Posted by Demon View Post
    Can you put the CONFIG statement in the include like that?
    (never saw that before, usually it's at the top of your program, but I don't use MPLAB).
    Until PBP 3 that is the default way, configs in the *.inc
    MPLAB has nothing to do with it.
    Dave
    Always wear safety glasses while programming.

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