First post here I'm afraid, stumbled across the site when googling for header84.asm (a header file from a book im studying - pic in practice which is apparently available to download but the link doesn't work).
Anyway, I'm stuck. I know a little assembly from college so it's not my first time playing with pics, but since it's been a while (and in all fairness we didn't learn much though I worked out the seven segs on the dev boards we were given on my own which was pretty cool) I thought i'd start from the beginning. Not a bad idea because I seem to be useless now!
So I bought myself a book, development board and got a copy of mplab, all seemed to be set. So I thought i'd start by teaching myself the header included in the book. So I typed it out and after a while I hit compile - errors.
Surprisingly enough, I used my initiative and solved them on my own. I'd messed up some formatting and it now compiles.
But does it work? No. I think it's a logic error of some sort but I really can't trap it!
Basically, the header included a subroutine to cause a one second delay. I made a quick example to set the output pins on porta to high, and then call the delay before setting them back again, call the delay and repeat.
The software compiles, and runs, however it gets stuck in an endless loop in the delay subroutine. If I put a breakpoint in after I call the elay subroutine, it never gets there.
Can you see anything obvious?
thanks
Kristian
Anyway, I'm stuck. I know a little assembly from college so it's not my first time playing with pics, but since it's been a while (and in all fairness we didn't learn much though I worked out the seven segs on the dev boards we were given on my own which was pretty cool) I thought i'd start from the beginning. Not a bad idea because I seem to be useless now!
So I bought myself a book, development board and got a copy of mplab, all seemed to be set. So I thought i'd start by teaching myself the header included in the book. So I typed it out and after a while I hit compile - errors.
Surprisingly enough, I used my initiative and solved them on my own. I'd messed up some formatting and it now compiles.
But does it work? No. I think it's a logic error of some sort but I really can't trap it!
Basically, the header included a subroutine to cause a one second delay. I made a quick example to set the output pins on porta to high, and then call the delay before setting them back again, call the delay and repeat.
The software compiles, and runs, however it gets stuck in an endless loop in the delay subroutine. If I put a breakpoint in after I call the elay subroutine, it never gets there.
Can you see anything obvious?
Code:
; *************************************
; PIC1684 Header file
; Equates section (defining memory locations for ports etc)
; The number after 'equ' is for an internal number/address for that function
;
; Source code written by Kristian Mason, probably in 2009, all rights reserved no doubt.
;
; anyway let's declare some registers!
;
TMR0 EQU 0x01 ; timer register - oscillates at 1/4 of crystal frequency, use it with option_r to create timing loops...
STATUS EQU 3 ; holds status of calculations and arithmetic, eg: has zero bit if calculation is absolute and carry bit if it isn't.
PORTA EQU 5 ; 5 bit register (0000 0) - set bits to output data (check bit for input)
PORTB EQU 6 ; 8 bit register (0000 0000) - set bits to output data (check bit for input)
TRISA EQU 85H ; holds the i/o values of portb pins
TRISB EQU 86H ; holds the i/o values of porta pins eg 1111 for four input pins...
OPTION_R EQU 81H ; 4 bit register (0000-1111) that can divide tmr0 by 2, 4, 8, 16 - 256 etc
ZEROBIT EQU 2
COUNT EQU 0CH ; a register to count events
;configure assembler to use pic processor
LIST P=16F84
ORG 0
GOTO START ; go to start!
; configure the pic itself
__CONFIG H'3FF0' ; hexidecimal to select LP oscillator (not power hungry, low frequency operation), WDT off, PUT on and disable code protection;
;************************
; Common subroutines - add some subroutines/code functions here to enjoy at a later line
;routine one - one second delay - assumes pic is running on a 32khz crystal.
DELAY1 CLRF TMR0 ;START + clear TMR0
LOOPA MOVF TMR0,W ;READ TMR0 INTO WORKING REGISTER *YIKES!*
SUBLW .32 ;TIME -32
BTFSS STATUS,ZEROBIT
GOTO LOOPA
RETLW 0
;************************
;**********************************************************
; CONFIG SECTION - TIME TO SET OUR PINS AND TIMING SETTINGS
;**********************************************************
START BSF STATUS,5 ;TURNS TO BANK1
MOVLW B'00000000' ; PUT THAT BINARY INTO WORKING REGISTER
MOVWF TRISA ;AND THEN PUT IT INTO TRISA AND NOW FOR PORTB:
MOVLW B'00000000'
MOVWF TRISB
MOVLW B'00000111' ;FOR AN UNKNOWN REASON THIS MAKES THE TIMER PRESCALER /256
MOVWF OPTION_R ; TIMER IS 1/36 SECS
BCF STATUS,5 ; RETURN TO BANK 0
CLRF PORTA ; FLUSH PORTA
CLRF PORTB ; CLEAR PORTB
; ___________________________________________________________________________________________________________________________
;*********************************************************
;*********************************************************
;*********************************************************
; WE CAN START THE PROGRAM! HURRAH!***********************
; OVER TO YOU NOW SQUIRE!*********************************
;*********************************************************
BEGIN
; set a pin on port A to high then delay
MOVLW B'00000001'
MOVWF PORTA
CALL DELAY1
; and clear port A again and repeat:
MOVLW B'00000000'
MOVWF PORTA
CALL DELAY1
GOTO BEGIN
;Call a halt to the program - let's call it a day
END
thanks
Kristian