[PIC18F8722]Light a LED?

Thread Starter

BenjaminD

Joined Jan 5, 2011
4
Hi forum!
This is my first post so I thought, "why not start it off with a question?":
How do you light a LED?
I've bought a demonstration/development board mounted with the 18F8722 PIC, and 8 LEDs.
For a first program I'm going to choose the obvious and attempt to light one of my LEDs.
The problem is that I can't get it working, - it simply won't light any LED.
I'm using the PICKit 3 programmer/debugger to program my PIC. When I program the device, I have the board powered on, and the PICKit 3 programmer connected through a USB cable.
All I get in the Output console under the PICKit 3 tab when I program the device is: "Programming...
Programming/Verify complete". After that I simply unplug the PICKit 3 programmer, and pull the plug to the 9V power supply. After that I replug the power source, but nothing happens..
This is the full source code for this simple program:
Rich (BB code):
 list p=18F8722
 #include p18F8722.inc
 CONFIG    OSC = HSPLL
 CONFIG    FCMEN = OFF
 CONFIG    IESO = OFF
 CONFIG    PWRT = OFF           
 CONFIG    BOREN = OFF
 CONFIG    WDT = OFF 
 CONFIG    MCLRE = ON  
 CONFIG    LVP = OFF  
 CONFIG    XINST = OFF 

 org 0x0000
start:
 banksel TRISB
 clrf TRISB
 banksel PORTB
 movlw 0x00ff
 movwf PORTB
 end
If you need any more information, just tell me and I'll be happy to provide it :).

-Best regards,
Benjamin.
 

R!f@@

Joined Apr 2, 2009
9,918
Hey Welcome

U need to post all the code, we need to see ur IO codes. the hardware assignment details

If tht is all, then you definitely need to learn more using the help feature
 

spinnaker

Joined Oct 29, 2009
7,830
Hey Welcome

U need to post all the code, we need to see ur IO codes. the hardware assignment details

If tht is all, then you definitely need to learn more using the help feature
I think that is all the code.

My question is why the OP is using assember on an 18F PIC?? C or BASIC would be FAR easier.

OP one thhing I see is you need a loop at the end of your code.

You should be setting the latch (LATX) and not the port.

If PORTB is also a analog input then you should set it's corresponding ANSEL to zero.
 

Tahmid

Joined Jul 2, 2008
343
Hi,
Here is the fixed code:
Rich (BB code):
 list p=18F8722

 #include "p18F8722.inc" ; You have to use either "" or <>

 CONFIG    OSC = HSPLL
 CONFIG    FCMEN = OFF
 CONFIG    IESO = OFF
 CONFIG    PWRT = OFF           
 CONFIG    BOREN = OFF
 CONFIG    WDT = OFF 
 CONFIG    MCLRE = ON  
 CONFIG    LVP = OFF  
 CONFIG    XINST = OFF

 org 0x0000

start:

banksel TRISB
clrf     TRISB
banksel LATB
movlw     0xff
movwf     LATB

here
goto    here

end
The mistakes were:
1. When you specify the include file, you have to use "" or <> within which you specify the name.
2. The microcontroller is not kept in the code as it restarts to the beginning once initialisation is done. You prevent this by adding a loop at the end.
3. This is not really an error, but when writing to the PORT write to LAT instead of PORT, so write to LATB instead of PORTB and read from PORTB when required.

Hope this helps.
Tahmid.
 

Tahmid

Joined Jul 2, 2008
343
If PORTB is also a analog input then you should set it's corresponding ANSEL to zero.
PORTB has no analog input for this microcontroller. In fact, I haven't come across any PIC with analog input in PORTB or PORTD. They're usually in PORTA, PORTC(in some) and PORTE.

Hope this helps.
Tahmid.
 
Last edited:

Thread Starter

BenjaminD

Joined Jan 5, 2011
4
Hey :)
Sorry for the long reply time, but I haven't had a chance to reply :(.
Thanks for the code, Tahmid, I'll try it out.
For my future projects though, I think I might want to use the HI-Tech C compiler, - is it compatible with PIC18 MCUs?
I get this error message when I try to compile a project using the HI-Tech compiler: "No valid installed HI-TECH compiler drivers". Where can I get them, and are they available for PIC18 MCUs?

EDIT: I did a complete c/p of your code, but still no lights :(. If i debug it using PICKit 3, it seems to run into a breakpoint at "goto here". - A green arrow in the sidebar of the text editor pointing at a certain line is a breakpoint right? :D
 
Last edited:

Tahmid

Joined Jul 2, 2008
343
Hi,
If you're not bound by any college/job requirements, I recommend you try mikroC. There's a free version available (limited to 2k program word) and the licensed one is cheaper than Hi-Tech C as well ($250 as opposed to I've heard around $850).
Plus, mikroC can work from PIC all the way from PIC12 series to PIC32. That includes PIC12, PIC16, PIC18, PIC24, dsPIC30, dsPIC33 and PIC32. That's all the PIC families there are besides the PIC10 series.

Check out there website at: www.mikroe.com

Hope this helps.
Tahmid.
 

Thread Starter

BenjaminD

Joined Jan 5, 2011
4
Hi,
If you're not bound by any college/job requirements, I recommend you try mikroC. There's a free version available (limited to 2k program word) and the licensed one is cheaper than Hi-Tech C as well ($250 as opposed to I've heard around $850).
Plus, mikroC can work from PIC all the way from PIC12 series to PIC32. That includes PIC12, PIC16, PIC18, PIC24, dsPIC30, dsPIC33 and PIC32. That's all the PIC families there are besides the PIC10 series.

Check out there website at: www.mikroe.com

Hope this helps.
Tahmid.
Thanks a lot :) I did seem to be able to get the new 2011 mikroC pro compiler for free though?
I downloaded this archive from their website: mikroc_pro_pic_2011_v460_setup. It contained a Setup.exe file for installation, and it also allowed me to download their IDE for free? I see that it also has a programmer, can I use that to program my device or do I still have to use the MPLAB programmer?
 

Tahmid

Joined Jul 2, 2008
343
Hi,
Yes, on their site they have the free version, that is more than enough for small to medium codes and enough for anyone learning PIC. I think you can use their programmer but only if you have their hardware. If you have a PICKit2 or something, you need to build your program and load the hex file to your PICKit2 through the PICKit2 software. This applies for all other programmers (hardware) as well.

Hope this helps.
Tahmid.
 

Thread Starter

BenjaminD

Joined Jan 5, 2011
4
Hi,
Yes, on their site they have the free version, that is more than enough for small to medium codes and enough for anyone learning PIC. I think you can use their programmer but only if you have their hardware. If you have a PICKit2 or something, you need to build your program and load the hex file to your PICKit2 through the PICKit2 software. This applies for all other programmers (hardware) as well.

Hope this helps.
Tahmid.
Well, what if I uninstall the drivers for my MPLAB PICKit 3, and choose to install mikroC's USB drivers, instead of the default ones, would that do the trick?
 
I found the C18 compiler better than the HI Tech version.
Hi Tech went into a silly mode of making lots of changes to the compiler and my code stopped working. So I moved across to C18.
You can download free version from www.microchip.com
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
I found the C18 compiler better than the HI Tech version.
Well... both products are now on the legacy listing. Microchip bought Hi Tech and wound up with a mess of code-incompatible compilers where (sometimes major) details changed depending on which PIC product family you were targeting.

To their credit this mess is being replaced with the XC compiler with a common syntax across all lines, though they kept 3 separate compilers for 8, 16, or 32 bit PICs.

To their demerit it is a work in progress, with the now legacy compilers still required to get the sample programs with the library code base to work.

I have a lot of work done with the C18 compiler and I do hope the eventual conversion to XC8 will be minimal.
 
Top