Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Assembly for PIC18Fxxx

Assembly for PIC18Fxxx

Assembly for PIC18Fxxx

I'm just learning assembly and working with the PIC line of Microcontrollers, specificly the 18 line (A Little 16).

I'm not currently getting these chips to do anything whatsoever on my solderless breadboard, nomatter what the program says. I'm currently testing with an example peice of code from www.microchip.com

Count    equ    0x000
; reset vectors
    org    00000h    ; Reset Vector
    goto    Start

;program code starts here

    org    00020h    ; Beginning of program EPROM
    clrf    LATB    ; Clear PORTB output latch
    clrf    TRISB    ; Make PORTB pins all outputs
    clrf    Count    ; Clear Count
    btfsc    PORTA,4    ; Has S2 been pressed? (Normally high, goes low when pressed.)
    goto    Loop    ; No, check again

    incf    Count,F        ; Increment Count
    movff    Count,LATB    ; move Count to PORTB
    btfss    PORTA,4        ; Has key been released?
    goto    Debounce    ; No, wait some more
    goto    Loop        ; yes, wait for next key press

    END        ; directive indicates end of code


This was originally made for the PIC18CXX2 chip, but I've modified it slightly to be compatable with the PIC18F448 Chip which I am currently using. I Dont understand if it's a problem in the code or in the wiring. As of now i'm running a 5 Volt line to both Vdd's and grounding both Vss's (this is correct, right?). I'm grounding out S2 (on Port A pin4) and I Cant see anything coming up on any LED's. Nothing happens at all!! Does anyone see anything wrong with what I am doing?

My second question is, what is the significance of 'Org'. It seems to be defining memory addresses in the code i sent, but i dont understand the use of it.

RE: Assembly for PIC18Fxxx

Org 00000h defines the address of the following assembler instructions.

for instance:

org 1000h
   goto fred

will generate code that is located at address 1000h.


RE: Assembly for PIC18Fxxx

Does this PIC have 2 banks?  Ive used the 16 line, and I have to switch between bank 0 and 1 when initializing my Ports.

For instance:

TrisA is only used in bank 1 to set the ports to outputs or inputs, then I have to switch back to bank 0 to use PORTA.



            bcf       STATUS, RP0      ;bank 0
            clrf      PORTA           ;initialize portA
           clrf      PORTB           ;initialize portB

            bsf       STATUS, RP0     ;switch to bank 1
            clrf      TRISA
            clrf      TRISB
        movlw     b'10000'        ;set pin 4 in, restout
          movwf     TRISA           ;set portA propriately

          movlw     b'00000000'     ;set 8-bit portB to outputs
        movwf     TRISB           ;set portB to all outputs
        bcf       STATUS,RP0      ;switch back to bank 0 begin working

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close