Trouble Reading the PIC Beginner Tutorials

Discussion in 'Programmer's Corner' started by ajm113, Apr 29, 2011.

  1. ajm113

    Thread Starter Member

    Feb 19, 2011
    Hello I got my PIC programmer in today and it's the iCP01 PIC Programmer and I've got the MPLABs installed and the PICKit 2 Software installed to compile code into my chip.

    I'm currently using a 18F2550 and when I was reading through some of the tutorials, I'm already lost on the code. They use a different PIC then me and all of them don't explain how to code for different other PICs or explain what your looking for when your coding on different platforms unless they explain this somewhere in a more later tutorial.

    I'm sorta new to assembly, but any other languages such as C or C++ aren't new to me and these tutorials suspect you may have a good understanding of Assembly which in my case is a little bit of a problem from what it looks.

    Here is a hello world for my PIC18F2550 I'm working on to simply turn a LED on as a hello world.
    Code ( (Unknown Language)):
    2.  processor 18F2550
    3.  include <>
    4. WDT = 0
    6.  org 0x0
    7.  clrf RB0  ; all outputs := 0
    8.  movlw b'11111110'  
    9.       ;tris RB0  ; lowest bit of GPIO becomes an output
    10.  bsf RB0,0 ; bring GPIO bit 0 high
    11. x    goto x  ; endless loop
    12.  end
    As you can see I marked out function tris on line 10, because every time I run that line in a 12F508 simulator it doesn't have a problem, but if I do uncomment that line in the 18F2550 I get the "Illegal opcode (RB0)".

    Can someone tell me a little more information about how to know what your looking for when programming a PIC you never compiled for and how do I know if a specific PIN would be wanting input or is doing an output in the simulator exactly? Did I maybe choose the wrong PIC for a beginner in the first place and should have gone for a 12F or a 16F series?
    Last edited: Apr 29, 2011
  2. Markd77

    Senior Member

    Sep 7, 2009
    Have a look at the 18F2550 datasheet section 10 for how to set up the ports. The 18F is more complicated and uses some different instructions to the 12F and 16F so it might be better to get the chip the tutorial is for, or find a tutorial for 18F.
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    The 12f508, and the 18f2550 have a quite different structure. So a program written for 12508 will not work on the 18f2550. Spend some time reading the datasheet. The datasheet is your best friend. And will also contain a lot program examples. Be sure to understand the how the configuration words work on the 18Fxxxx PIC. Se the section
    SPECIAL FEATURES OF THE CPU section in the data sheet. Without the configuration words set properly your PIC will not work at all. As a tip start using the internal oscillator. That is most beginner friendly.
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    ;tris RB0 ; lowest bit of GPIO becomes an output

    I can see what is the intent of that is:

    Your problem comes from a name change Microchip uses. For the simplest devices with but one I/O port the name it GPIO. For all other devices with two or more ports they are named PORTA, PORTB, and so on. So you need to look at the data sheet for the 2550 you are using and select the port and pin you wish to use.

    I'm going to show you PORTB, pin 0.

    Code ( (Unknown Language)):
    2.    movlw b'11111110'    ; tristate mask
    3.    movwf TRISB, F        ; copy W to TRIS resister B
    As you have a whole bunch of stuff to learn here, hardware, software, prototyping, code loading, and so on I really don't recommend trying to jump into the middle with your own processor. Instead, get a nice kit (several are under $50) with a PICKIT and a board and a CD with examples for the board they give you that they tested and insured to work.

    Then you can look at their sample programs, try a change, and have a chance to see where you went wrong. That is not a put-down, we all go wrong doing this stuff, you need to a simple example to see where the problem is.

    Then once you get bored with the kit jump to your own hardware (and know the joys of making something like a USB PIC where you have to figure out if the problem is in the PC, the PIC, or the PIC hardware).

    Last edited: Apr 29, 2011
  5. DerStrom8

    Well-Known Member

    Feb 20, 2011
    What are you using for a compiler?
  6. ajm113

    Thread Starter Member

    Feb 19, 2011
    Yes on second thought I'll buy a beginners kit on Microchip's website before I get my hands dirty in coding, because I still don't know what some of the pins even mean or do and ErnieM, your right I think it would be best if I look at examples to have a much better understanding using assembly code with PICs using a PIC kit and I did find one for 34 dollars I think I would like so I bought that.

    Thanks for your helpful replies! I've been so eager to jump into PIC programming I guest I'm trying to learn it the very hard way.

    @DerStrom8 I'm using the latest MPLab's default assembly compiler if thats what your asking.