[PIC18F8722]Light a LED?

Discussion in 'Embedded Systems and Microcontrollers' started by BenjaminD, Jan 5, 2011.

  1. BenjaminD

    Thread Starter New Member

    Jan 5, 2011
    4
    0
    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:
    Code ( (Unknown Language)):
    1.  
    2.  list p=18F8722
    3.  #include p18F8722.inc
    4.  CONFIG    OSC = HSPLL
    5.  CONFIG    FCMEN = OFF
    6.  CONFIG    IESO = OFF
    7.  CONFIG    PWRT = OFF          
    8.  CONFIG    BOREN = OFF
    9.  CONFIG    WDT = OFF
    10.  CONFIG    MCLRE = ON  
    11.  CONFIG    LVP = OFF  
    12.  CONFIG    XINST = OFF
    13.  
    14.  org 0x0000
    15. start:
    16.  banksel TRISB
    17.  clrf TRISB
    18.  banksel PORTB
    19.  movlw 0x00ff
    20.  movwf PORTB
    21.  end
    22.  
    If you need any more information, just tell me and I'll be happy to provide it :).

    -Best regards,
    Benjamin.
     
  2. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    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
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,015
    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.
     
  4. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi,
    Here is the fixed code:
    Code ( (Unknown Language)):
    1.  list p=18F8722
    2.  
    3.  #include "p18F8722.inc" ; You have to use either "" or <>
    4.  
    5.  CONFIG    OSC = HSPLL
    6.  CONFIG    FCMEN = OFF
    7.  CONFIG    IESO = OFF
    8.  CONFIG    PWRT = OFF          
    9.  CONFIG    BOREN = OFF
    10.  CONFIG    WDT = OFF
    11.  CONFIG    MCLRE = ON  
    12.  CONFIG    LVP = OFF  
    13.  CONFIG    XINST = OFF
    14.  
    15.  org 0x0000
    16.  
    17. start:
    18.  
    19. banksel TRISB
    20. clrf     TRISB
    21. banksel LATB
    22. movlw     0xff
    23. movwf     LATB
    24.  
    25. here
    26. goto    here
    27.  
    28. 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.
     
  5. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    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: Jan 6, 2011
  6. BenjaminD

    Thread Starter New Member

    Jan 5, 2011
    4
    0
    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: Jan 6, 2011
  7. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    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.
     
  8. BenjaminD

    Thread Starter New Member

    Jan 5, 2011
    4
    0
    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?
     
  9. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    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.
     
  10. BenjaminD

    Thread Starter New Member

    Jan 5, 2011
    4
    0
    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?
     
  11. xainnasir

    New Member

    Nov 8, 2012
    26
    2
  12. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    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: Mar 8, 2013
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    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.
     
Loading...