Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assembly for PIC18Fxxx

Status
Not open for further replies.

SSChicken

Programmer
Nov 4, 2003
3
US
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


-------------------------------------------------
Count equ 0x000

;************************************************************
; reset vectors

org 00000h ; Reset Vector
goto Start

;************************************************************
;program code starts here

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

IncCount
incf Count,F ; Increment Count
movff Count,LATB ; move Count to PORTB

Debounce
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.
 
Org 00000h defines the address of the following assembler instructions.

for instance:

org 1000h
fred
goto fred

will generate code that is located at address 1000h.

rgds
Zeit.
 
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.

Example:

MAINLINE_CODE

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


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top