Basic LED question.

Discussion in 'Embedded Systems and Microcontrollers' started by GlassWalker, Oct 29, 2009.

  1. GlassWalker

    Thread Starter New Member

    Oct 29, 2009
    3
    0
    Hello everyone. I'm new to using PICs and I'm trying to get a basic program to work that just turns on one of the LEDs. The program builds fine but when I run it, nothing happens. I'm using a pic18f46j50 and the PICit 2 to program it. Here it is, any help would be greatly appreciated.

    #include<p18f46j50.h>
    #include "HardwareProfile.h"
    #include <stdlib.h>

    #pragma config XINST = OFF
    #pragma romdata CONFIG
    //_CONFIG_DECL(_CONFIG1H_DEFAULT &_OSC_HS_1H.\ program won't work with this for some reason
    _CONFIG2L_DEFAULT.\
    _CONFIG2H_DEFAULT &_WDT_OFF_2H.\
    _CONFIG3H_Default.\
    _CONFIG4L_DEFAULT & _LVP_OFF_4L.\
    _CONFIG5L_Default.\
    _CONFIG5H_Default.\
    _CONFIG6L_Default.\
    _CONFIG6H_Default.\
    _CONFIG7L_Default.\
    _CONFIG7H_Default.);
    #pragma romdata

    void main (void){
    TRISB=0x00;
    PORTB=0x01;
    while(1);
    // mInitAllLEDs(); Failed attempts.
    // mLED_1_Toggle();
    // PORTB = 0x5a;

    }
    Thanks in advance.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Your program is simple. Why not use MPLAB and simulate your code?
     
  3. GlassWalker

    Thread Starter New Member

    Oct 29, 2009
    3
    0
    Last edited: Oct 29, 2009
  4. eng1

    New Member

    Oct 25, 2009
    13
    0
    I would double-check the config settings. Which oscillator are you using?
    In the 'Help' menu of MPLAB IDE you will find an useful section (Help->Topics...->Language Tools->PIC18 Config Settings) where the configuration settings are listed for each PIC18.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Download the 44 Pin Demo Board software/source code. It is for an 18F45k20, but the 18F series are very similar. The 44 pin demo board has a button, a potentiometer, and 8 LEDs, so the code is relatively simple to work with as an intro to the 18Fxxxxx series.
     
  6. russ_hensel

    Well-Known Member

    Jan 11, 2009
    818
    47
    Your main loop is commented out so the program does nothing at high speed.
     
  7. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234

    Well for one thing, c code is case sensitive, once it is declared one way, you HAVE to type it in exactly every time you make any reference to it..are you sure it compiles right without errors where it says certain variables where not defined???..
    your code should look more like this....
    Code ( (Unknown Language)):
    1.  
    2. #include<stdlib.h>
    3.   #include<p18f46j50.h>
    4.  #pragma  romdata CONFIG
    5.   _CONFIG_DECL(_CONFIG1H_DEFAULT  & _OSC_HS_1H,\
    6.                _CONFIG2L_DEFAULT,\
    7.                _CONFIG2H_DEFAULT &  _WDT_OFF_2H,\
    8.                _CONFIG3H_DEFAULT,\
    9.                _CONFIG4L_DEFAULT &  _LVP_OFF_4L,\
    10.                _CONFIG5L_DEFAULT,\
    11.                _CONFIG5H_DEFAULT,\
    12.                _CONFIG6L_DEFAULT,\
    13.                _CONFIG6H_DEFAULT,\
    14.                _CONFIG7L_DEFAULT,\
    15.                _CONFIG7H_DEFAULT);
    16.   #pragma  romdata
    17.  void  main(void)
    18.   {
    19.   TRISB=0×00; //Port  B set as output port
    20.   PORTB=0×01; //  Turn ON LED 1
    21.   while(1); //Loop  infinitely
    22.   }
    23.  
    plus any code typed after while(1); will not run.......

    My .02
     
  8. GlassWalker

    Thread Starter New Member

    Oct 29, 2009
    3
    0
    Sorry to bring back such an old topic, but I've been out of town/work has been holding me up a lot.

    eng1:
    I don't really know anything about the oscillator. If you have anything I could read about it handy, I'd be happy to get the link. Here's what the Help file said about it:
    Oscillator:


    OSC = INTOSC
    INTOSC
    OSC = INTOSCO
    INTOSCO (CLKO-RA6)
    OSC = INTOSCPLL
    INTOSCPLL
    OSC = INTOSCPLLO
    INTOSCPLLO (CLKO-RA6)
    OSC = HS
    HS, USB-HS
    OSC = HSPLL
    HS+PLL, USB-HS+PLL
    OSC = EC
    EC (CLKO-RA6), USB-EC
    OSC = ECPLL
    EC+PLL (CLKO-RA6), USB-EC+PLL

    BMorse:

    I attempted to compile your code but I get the error:
    Executing: "C:\MCC18\bin\mcc18.exe" -p=18F46J50 "main.c" -fo="main.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
    C:\Documents and Settings\BrokenShots\Desktop\New Folder (4)\main.c:4:Error: syntax error
    Halting build on first failure as requested.

    Thanks again everyone for your time and help.
     
Loading...