Assembly Programming Help

Discussion in 'General Electronics Chat' started by JDR04, Jun 28, 2012.

Thread Status:
Not open for further replies.
  1. JDR04

    Thread Starter Active Member

    May 5, 2011
    339
    4
    Man, I need Help on This one! Some time ago I bought a PICKIT 2 programmer from Microchip and an experimental board (Low Pin Count board with 16F690 on it)

    I just cannot get my head around where to start and how to start on all this. I find it somewhat scary. Tried finding somebody in West lothian Scotland to show me how with the offer of a small fee for their patience but no luck. I'm told its best for me to learn assembly programming and use MPLAB IDE etc etc.

    Anybody out there with any wise words for me?

    Thanks JDR04
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    There should be a set of tutorials for the low pin count board on the CD that came with it. If not search around a bit. There are also youtube videos, and other information around the web on how to connect it up, start using MPlab, etc.
    Give it a go, it's really pretty simple to get started.
    I'd recommend Mplab 8.something rather than MPlab X at the moment.
     
    JDR04 likes this.
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    JR,
    You did not indicate if you had any programming experience so its hard to know where to send you.

    Markd77 is right about starting on MPLAB 8.xx MPLABX is great but more of a learning curve. Get 8.xx at: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469

    Googlium: http://www.gooligum.com.au/index.html has some nice tutorials but there are lots of others. The Microchip website/forum has many resources as well.

    If you are a programming or uCHIP newbie, you don't even need to hook up the board as you can experiment in MPSIM.

    Step by step:
    Launch MPLAB 8.xx. You get a blank workspace.
    Click Project->Project Wizard. Enjoy the happy welcome.. then click Next..
    Select 16F690 as the device.
    Select Microchip MPASM Toolsuite
    Select Create New Project File radio button and enter a project directory and name of project. Next.
    At Add existing files to you project click Next.. you don't have any. Click Finish.
    You should have a project window open with a bunch of folder icons.. Source Files, Header Files etc. If not open it with View-Project.
    Click File-Add New File to Project. Navigate to your project directory. It should be in the 'Jump To' dropdown.
    Pick a name.. JR.asm or something. The MPLAB editor opens. Enter this:

    Code ( (Unknown Language)):
    1.     INCLUDE "P16F690.inc"    ; where all of the PIC registers, IO etc are defined
    2.                             ; MPLAB knows where to find this file
    3.  
    4.     cblock    20h                ; block of constants. Used to define two bytes of RAM starting at 20h
    5.         Abyte:    1            ; declare some RAM
    6.         AnotherByte:1
    7.     endc
    8.        
    9.  
    10.         ORG    0                ; tells MPASM where to start
    11.    
    12.         nop                    ; step through these
    13.         nop
    14.  
    15. loop:
    16.         clrf    Abyte        ; init RAM
    17.         clrf    AnotherByte
    18.  
    19.         movlw    0            ; clear W
    20.         addlw    .1            ; bump it
    21.  
    22.         movlw    'H'            ; stuff something into RAM that you can see
    23.         movwf    Abyte        ; in a watch window.
    24.         movlw    'i'
    25.         movwf    AnotherByte        
    26.         goto    loop
    27.  
    28.         END                    ; denotes end of source
    29.  
    30.  
    On the MPLAB toolbar, click Debugger->MPSIM. MPSIM will allow you to mess with code without attached hardware..

    Take a deep breath and click Project->Build All. When prompted, select Absolute code. It should build with no errors.

    Click View->Watch to open a watch window. Click under symbol name and enter the names of the two RAM bytes (Abyte and AnotherByte). Right-click on the watch window bar and select various representations of the same data.

    In Edit->Properties select the 'Other' tab and check 'Debugger PC Location..' to highlight the source lines you are stepping.

    You are ready! Click STEP (an arrow between { } on the toolbar). Don't see it? Click View->Toolbars->Debug to turn it on.

    Step through the code and watch W: on the MPLAB status bar (bottom of the main window) get loaded to 0 then 1. Watch the RAM get loaded to HI. Click View->FileRegisters and examine the line at 0020h. You should see 'HI' in the ASCII area.

    You're ready to go. In the data book, read about the ROM and RAM organization. Pay attention to the bank selection requirements etc. that I have ignored for this example (then look at 18F..)
    Next, go to the back of the book and read up on the instruction set. Plug a few in and step them to see what they do. Then plug them ALL in and see what they do. Understand the difference between ,f and ,W and assembler syntax.

    Muck about a bit in MPSIM then get on to the chip:
    Select Configure->Configuration Bits and set up for your particular board (oscillator type etc). Rebuild.
    When it comes time to actually run your code, select Debugger->PicKit2 and rebuild. Plug in the board and have at it.

    BTW, I just slapped this together so don't take it as exactly good programing practice. When you get past the play stage, look at the Microchip templates to get started... After that.. we'll talk.

    Have fun!

    As Markd77 said, lots of stuff on the CD but this should get you on your way.
     
    Last edited: Jun 29, 2012
    JDR04 likes this.
  4. upand_at_them

    Active Member

    May 15, 2010
    246
    29
    JDR04 likes this.
  5. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Yes, this is a good tutorial site. I have made 50% of all the project boards using stripboards plus 3 of the MCU boards. All the tutorial lessons worked well. This is a highly recommended site for beginners who want to start PIC with assembly language.

    Allen
     
    JDR04 likes this.
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    JDR04 likes this.
  7. upand_at_them

    Active Member

    May 15, 2010
    246
    29
    Too bad nobody reads Stickies. :)
     
    JDR04 likes this.
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    JDR04 likes this.
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    This document may also be of some help. http://ww1.microchip.com/downloads/en/DeviceDoc/51281d.pdf
    By the way. All the 12 lessons in the low pin count demo. Are created as projects. In MPLAB just go to file->open project and then select a lesson folder. As a tip. Then you are up to starting your own programming. ALWAYS create a project. It takes about 15 seconds and it will make the programming more easy
     
  10. JDR04

    Thread Starter Active Member

    May 5, 2011
    339
    4
    Can I just thank all the folk who have kindly set out here how I may help myself. There is a huge mountain of info for me to go through now so I'll start on it as soon as possible. This forum has always had great people on it who always are willing to share their knoweledge, and for newbies like myself it's a goldmine.

    Thanks guys for all the help and no doubt I'll be asking for plenty more in the future. - JDR04
     
    absf likes this.
  11. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Not everyone appreciates the helps they get here and some took them for granted.

    Allen
     
    Last edited: Jun 30, 2012
Loading...
Thread Status:
Not open for further replies.