Basic LED question.

Thread Starter

GlassWalker

Joined Oct 29, 2009
3
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.
 

eng1

Joined Oct 25, 2009
13
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.
 

thatoneguy

Joined Feb 19, 2009
6,359
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.
 

BMorse

Joined Sep 26, 2009
2,675
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.

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....
Rich (BB code):
#include<stdlib.h>
  #include<p18f46j50.h>
 #pragma  romdata CONFIG
  _CONFIG_DECL(_CONFIG1H_DEFAULT  & _OSC_HS_1H,\
               _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=0×00; //Port  B set as output port
  PORTB=0×01; //  Turn ON LED 1
  while(1); //Loop  infinitely
  }
plus any code typed after while(1); will not run.......

My .02
 

Thread Starter

GlassWalker

Joined Oct 29, 2009
3
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.
 
Top