Microchip Pickit 2 with PIC16F887 in Assembly

Discussion in 'Programmer's Corner' started by MMattar9, Sep 12, 2013.

  1. MMattar9

    Thread Starter New Member

    Sep 12, 2013
    3
    0
    Hello,

    I have a university project due soon that requires me to count from 0 - 255 in binary. I am completely stuck on this. I know it's fairly simple, just not making much progress. If someone could help me out that would be awesome!

    I am using the Pickit 2 from Microchip with PIC16F887.

    Here is the data sheet for the chip:
    http://ww1.microchip.com/downloads/en/DeviceDoc/41291G.pdf

    http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en026561

    Additional information:
    http://www.mikroe.com/products/view/11/book-pic-microcontrollers/

    Thanks!!
     
  2. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,521
    2,369
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    The datasheet has all the information you could want for this task beginning on page 235.

    What exactly are you struggling with?
     
  4. MMattar9

    Thread Starter New Member

    Sep 12, 2013
    3
    0

    On where to start the program... I haven't done programming for 3 years and it was never my strength!
     
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Gotcha...

    If you look here, there is a simple program to show the general structure of an assembly program.

    I'd recommend going through some of the other tutorials too in order to get the hang of things...
     
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,521
    2,369
    +1 on Nigel Goodwin's site.
    If this is a one off, you may not be into building the boards, but if so, Futurlec has the strip boards.
    http://www.futurlec.com/Protoboards.shtml fairly cheap.
    If going on to other projects, I have found the different modules handy for prototyping.
    The difference was I found it easier to use double row 20pin ribbon instead of the single row headers.
    Max.
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Sound strange to me that you are thrown into such a project just out of the blue. In most university settings if not any. You will always have some course background before a task like this is given to you. You learn the theory first then you get back the lab to use what you have learned.
    Regarding the matter on how to start programming that we may help you with. But it would help us (at leat me) if you could give some information. Like will you be using C or Assembler.
     
  8. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,521
    2,369
    Someone slapped me the other day for not reading the OP's title. :p
    Max.
     
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Well I am sure you deserved that smack on your hands:p Typical a beginner mistake.
    And to the OP that might have skipped the two first classes since he already could program a MCU. Take a look here http://www.microchip.com/Microchip....wnload.aspx?device=en023805&lang=en&ReturnURL on the "44-Pin Demo Board User's Guide" link
     
  10. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,521
    2,369
    Who said it was hands? :confused:
    Besides, your not a 'Beginner', what your excuse? :)
    Max.
     
  11. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I had a vague feeling that this was to be done in assembly, but I couldn't remember why I thought that after rereading the OP. :p
     
  12. JohnInTX

    Moderator

    Jun 26, 2012
    2,342
    1,024
    This describes how to do a quick project in MPLAB 8.x. Use the attached source file in place of the one in the post and specify the 18F887 in place of that PIC. Use MPSIM as the debugger as discussed. Build and open a watch window. Watch 'Count'. Step through to see how it works.

    Have fun.
     
  13. mitko89

    Member

    Sep 20, 2012
    123
    19
    I suppose the result is displayed on 8 leds?
     
  14. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    The program only increments a variable called "count". You have to copy the contents of "count" to one of the ports first before it can be displayed in binary form.

    I simulated the program on proteus and copy "count" onto "Port D" and use the "7-seg BCD" in the library to display as 2 hex digits from 00-FF. I also added some delays between each display so it wont display too fast

    Allen
     
    Last edited: Sep 14, 2013
  15. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    The 7 segment display you drew seems to take 4 bits as an input to produce a hex number output. Do you have a part number for this?
     
  16. JohnInTX

    Moderator

    Jun 26, 2012
    2,342
    1,024
    The OP asked for a counter. Its a counter. I agree its pretty lame as is. A better description of the problem would help from here.
     
  17. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    Yes, since counting from 0-255 in binary is a nonsensical objective in the first place.

    Nothing wrong or lame with your example at all,
    the result just has to be moved to a port of LEDs for every count iteration to display binary.
     
  18. MrChips

    Moderator

    Oct 2, 2009
    12,437
    3,360
    How to count from 0-255 in binary?

    Here is the PIC assembler code:

    Code ( (Unknown Language)):
    1.     INCF count
     
Loading...