learning to edit asm.

Status
Not open for further replies.

gazza1966

New Member
Hi people of the board!
My name is Gaz and I've joined this board as I am trying to learn to write PIC programs and could do with a little help.
I have a programmer (picstart+) and a developement board (matrix multimedia) and have had a little success in editing existing programs to flash LED's, I cannot yet write a program from scratch but Ive found editing existing asm a good way to start.
Ok, my question...........I have a program (listed at the end of here) which I found on the web which I have been editing by changing the binary segments so as to make different flashing patterns of LED's.
The program seems to be only limited to 48 lines of binary sequences and no matter how many sequences I add it always resets after 48 lines.
Could someone point out to me the part of the prog where I could change the number of binary sequence lines so the program will run to say 168 lines?
As I said I am finding the editing of existing programs easier to understand at the moment so no in depth stuff! hehe

Here is the code I am trying to edit:

PROCESSOR 16F84a
__CONFIG 3FFB ;XT oscillator

PCL equ 2
STATUS equ 3 ;standard register files
PORTB equ 6
EEDATA equ 8
EEADR equ 9
INTCON equ 0BH
OPTREG equ 081H
TRISB equ 086H
EECON1 equ 088H
EECON2 equ 089H

RP0 equ 5
Z equ 2
GIE equ 7
T0IE equ 5
T0IF equ 2
WREN equ 2
WR equ 1
RD equ 0

#define bank0 bcf STATUS,RP0 ;select bank 0
#define bank1 bsf STATUS,RP0 ;select bank 1

magic macro ;magic EEPROM write sequence
movlw 55H
movwf EECON2^80H
movlw 0AAH
movwf EECON2^80H
endm

cblock 0CH ;variable block
n_vals
n_tmp
endc

;**************************;
; Main program entry point ;
;**************************;

org 0
goto start


;***********************;
; Interrupt entry point ;
;***********************;

org 4

; Normally context should be saved before the interrupt service
; routine and restored after but that's not necessary in this program
; because the processor is doing nothing between interrupts. See
; the PIC datasheet for the recommended procedure.

movf EEADR,w
xorwf n_vals,w
btfsc STATUS,Z ;EEADR == n_vals?
clrf EEADR ;yes, start again at 0
call ee_rd
movf EEDATA,w ;read EEPROM
movwf PORTB ;display byte
incf EEADR,f ;new address
bcf INTCON,T0IF ;clear interrupt flag
retfie


start clrf PORTB
bank1
clrf TRISB^80H ;port B all outputs
movlw B'00000111'
movwf OPTREG^80H ;timer 0 prescale 256:1
bsf EECON1^80,WREN ;allow writing to EEPROM
bank0
call ee_init ;transfer table to EEPROM
bank1
bcf EECON1^80H,WREN ;disallow writing to EEPROM
bank0
bsf INTCON,T0IE ;enable timer interrupt
bsf INTCON,GIE ;globally allow interrupts

loop goto loop ;do nothing forever


; ee_init
;
; initialise EEPROM from table

ee_init clrw
call lut ;get number of table entries
movwf n_vals ;and save
movwf n_tmp ;and again
clrf EEADR
decf EEADR,f ;EEADR = -1
ee_in1 incf EEADR,f ;next address
movf EEADR,w
addlw 1
call lut ;get associated table entry
movwf EEDATA
call ee_wr ;write to EEPROM
decfsz n_tmp,f ;another?
goto ee_in1 ;yes
clrf EEADR ;no, then finished
return


; lut
;
; look up table

lut addwf PCL,f ;add W to PCL to get table entry
retlw D'148' ;number of entries in table
retlw B'10000000' ;first entry
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000' ; 48 end of 1st speed sequence
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'00000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000' ;68
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00010000'
retlw B'00010000' ;80
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000' ; end of 2nd speed sequence
retlw B'10000000'
retlw B'10000000' ;90
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000' ;100
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000' ; 120 end of 3rd speed sequence
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000' ;124 end of 4th speed sequence
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'10000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'01000000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00100000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000'
retlw B'00010000' ; 148 end of 5th speed sequence

; ee_wr
;
; Writes byte in EEDATA to EEPROM location at EEADR. Interrupts
; should be disabled before calling ee_wr.

ee_wr bank1
magic ;invoke magic sequence
bsf EECON1^80H,WR ;start write
ee_wr1 btfsc EECON1^80H,WR ;write complete?
goto ee_wr1 ;no
bank0
return


; ee_rd
;
; Reads EEPROM byte at EEPROM location EEADR into EEDATA

ee_rd bank1
bsf EECON1^80H,RD ;start read
bank0
return ;read will be complete on return

end


any help would be greatly appreiciated.

thanks

Gaz
 
hi Gaz,

Your problem is due whats called Page boundaries, Pages have a fixed length and your table crosses a boundary.

EDIT:
Checked thru your program, lots of errors.

Why dont you start with a simple program, say flashing an LED.?

What assembler are you using.?
 
Last edited:
Hi Gaz,

As Eric said, you should start with simpler coding - try Nigels excellent tutorials - he's one of the moderators here so knows what its all about.

Your code shows the chip 16F84A - do you actually have that chip or do you have other more modern ones to hand..?

Don't know which version of the MM development board you have; are you aware that they have a programmer built in, so you can do everything on that one board. Depending on the version it could be a parallel or usb connection.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…