Sunday, November 28, 2004

Hello World Assembles! (and hardware is here...)

It's been too long since the last post. I've received all of my equipment except my helping hands with magnifying glass, which is on back order. I also spent some time at Jan's Hobby Shop and Radio Shack buying last minute little items like rubber cemenet, tin, thin pastic, insulated wires, etc. I rearranged my desk and organized my new tools near the window so that the soldering station can be ventillated. Let the games begin!

I wrote my first hello world assembly language program. It's a blinking LED. I went through the example from PIC in Practice (by Smith) and added my own comments. I thought everything was going fine until I tried to assemble it. I had some error messages. Cleaned up a few typos. Now - this problem of TRIS. The assembler was not accepting the instruction. Normally TRIS is used for low level microchips to set the register responsible for setting the I/O mode for the given port. The instruction format is:

TRIS PORT#

with # being A, B or C. Well, apparently Microchip has phased this instruction out for my particular chip. So, I tried several variations - none worked. I looked through the instruction set summary in the datasheet which came along with the chip and TRISA, TRISB, TRISC, TRISD, and TRISD were given as registers. Fine. I tried loading the value directly into these. No. TRISA is not recognized. I tried declaring TRISA with a file identifier in the beginning and all of a sudden no errors. Great!

We'll see if I can wire this up correctly and get it to run tommorow. I think it may need a little more tweeking, but at least it assembles. :)

The code looks like this:



; My first PIC assembly program!
; Denali Nicholson

; A simple LED
; *********************************************************


TMR0 EQU 1 ; Timer0 is set to file 1
STATUS EQU 3 ; Status variable is file 3
PORTA EQU 5 ; PORTA is file 5
PORTB EQU 6 ; PORTB is file 6
TRISA EQU 7 ; TRISA is file 7
TRISB EQU 8 ; TRISB is file 8
ZEROBIT EQU 2 ; ZEROBIT is bit 2
COUNT EQU 0C ; a register to count events

LIST P=18F4525 ; PIC spec
ORG 0 ; start address is 0
GOTO START ; start program

; **********************************************************

; 1 second delay
DELAY1 CLRF TMR0 ; clear contents of TMR0
LOOPA MOVF TMR0,W ; move contents of TMRO into working register
SUBLW .32 ; 32 - working reg is assigned to working reg
BTFSS STATUS,ZEROBIT ; test bit in file skip if set,
;skip goto if yes
GOTO LOOPA ; time is not 32, keep looping
RETLW 0 ; time is 32, return

; 0.5 second delay
DELAYP5 CLRF TMR0 ; clear contents of TMR0
LOOPB MOVF TMR0,W ; move contents of TNR0 into working register
SUBLW .16 ; 16 - working register, this is assigned to working reg
BTFSS STATUS,ZEROBIT ; test bit in file skip if set, skip goto if yes
GOTO LOOPB ; time is not 16, keep looping
RETLW 0 ; time is 16, return

;***********************************************************

;CONFIGURATION SECTION
START BSF STATUS,5 ;Bit Set in File, bit 5 is set to 1 in STATUS

MOVLW B'00011111' ; Move literal into working reg
MOVWF TRISA ; Move working reg into TRIS reg - this sets first five
; least significant bits to inputs, three most sig bits
; as outputs

MOVLW B'00000000' ; Move literal into working reg
MOVWF TRISB ; Move working reg into TRIS reg - this
; sets all bits in
; PORTB as outputs

MOVLW B'00000111' ; Move literal into working reg
OPTION ; Contents of working reg are loaded into OPTION reg
; This will prescale the timing rate to 1/32 seconds

BCF STATUS,5; Bit Clear in File, bit 5 is set to 0 in STATUS
CLRF PORTA ; Clears PortA
CLRF PORTB ; Clears PortB

;***********************************************************
;Program Starts Now

BEGIN BSF PORTB,0 ;Bit Set in File, bit 0 set to 1 in PORTB.
CALL DELAYP5 ;Wait 0.5 seconds
BCF PORTB,0 ;Bit Clear in File, bit 0 set to 0 in PORTB.
CALL DELAY1 ;Wait 1 second
GOTO BEGIN ;Repeat
END ;Finish

0 Comments:

Post a Comment

<< Home