Home > pic18f, Uncategorized > pic18f4620 assembly bundle

pic18f4620 assembly bundle

Here’s a small (3.6 MB) bundle that I use to program my pic18f4620 using a pickit2 with assembly code on my PC. I’ve only tested this on XP.

It doesn’t have all the features of a full blown IDE like MPLABX (no stepping through code I’m afraid) but is a nice concise package that encourages the use of command line scripting.

The bundle also includes some example code.

Getting Started

Download the bundle from here and extract the files.

pic18fassemby_extracted_files

The extracted folder contains the mpasmx assembler files, the pk2cmd software tool which is used to communicate with the PICkit2, and Notepad++ text editor, which can be used to write and modify code.

The bundle includes 6 example projects.

To create a new project do the following:

  1. First create a new folder inside the “pic18f4620_asm” folder and copy the build.bat file into that folder.
  2. Run the Notepad++ editor and paste the example code (flashing LED) given below. Save the code in the new folder as a file called “main.asm” (don’t include quotes in the filename).
  3. Make sure the PICkit2 programmer is correctly connected to the PIC18f4620 and finally double click the build.bat file.
  4. If there are no errors in the code and the hardware is set up correctly then the PIC18f4620 will be programmed.

asm_output

Example Code to work with this circuit
This code will flash the LED connected to pin 19 (RD0)

;configure the  assembler directive 'list' so as to set processor to 18f4620 and set the radix used for data expressions to decimal (can be HEX|DEC|OCT)
    list p=18f4620, r=DEC
    #include <p18f4620.inc>
; configure the micro so that the watchdog timer is off, low-voltage programming is off, master clear is off and the clock works off the internal oscillator
    config WDT=OFF, LVP=OFF, MCLRE=OFF, OSC=INTIO67
;The org directive tells the compiler where to position the code in memory
    org 0x0000 ;The following code will be programmed in reset address location i.e. This is where the micro jumps to on reset
    goto Main ;Jump to Main immediately after a reset
 
;--------------------------------------------------------------------------
; Main Program
;--------------------------------------------------------------------------

    org 0x0100 
Main
    clrf TRISD ; All PORT D IO pins are configured as outputs

    ; Set up timer 0 so it can be used to control flash rate
    bcf T0CON, T0CS; use internal instruction cycle clock
    bcf T0CON, T08BIT; use 16 bit mode
    bcf INTCON, TMR0IF; reset timer overflow flag
    bsf T0CON, TMR0ON; turn on timer 0    
        
loop  
    ; check if the timer0 overflow flag has been set
    btfss INTCON, TMR0IF
    goto loop
    bcf INTCON, TMR0IF; reset timer overflow flag

    ;invert LATD0
    movlw 0x1
    XORWF LATD,F
    
    goto loop   
    END
    
Categories: pic18f, Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: