Macros for Microchip PIC controllers
Most errors in programs written in assembly language are the result of the mistyped labels and conditionals. In any programming languages the use of labels reduces readability. In high level languages the use of labels are considered a bad practice and in most cases it should be avoided. I had a teacher in the university who went so far as to remove the goto instruction from the Pascal compiler we used.
Using our struct.inc macro file assembler programs are made more readable. Files can be compiled with any version of MPASM.
movlf 20H,fsr
loop
clrf indf ; Clear bank0
incf fsr,f
endloop_b fsr,7
|
|
Example of clearing bank 0 memory on PIC16F870
|
; Oscillator frequency
xtal equ 18432000; Hz
xtime equ 400000000/(xtal/10) ; ns
; Variables ; 20-7F
cblock 020H
w0, w1, w2 ; Temporary registers
endc
;--------------
; Wait w*100us
; IN: w
; Registers: -
wait100us
movwf w1
loop
movlf (100000/4/xtime)+1,w0 ; 100 us
loop
crwdt
endloop w0
endloop w1
ret
|
|
Example of waiting w*100us on a processor running
at 18.432 MHz
|
; Hardware definitions
#define ena portb,0 ; Enable input
#define inp portb,1 ; Data input
#define out portb,2 ; Output
;------------------------------------------------
; Generate pulse width modulated output if ena=1
; Assume ena and inp inputs and out is output
; Registers: -
pwm
loop
if_b ena
if_b inp
nop
bsf out
bcf out
melse
bsf out
nop2
bcf out
mendif
mendif
endloop_infinite
|
|
Example of bit manipulation
|
Before downloading the include file please register. There is no registration fee, if you register then you are allowed to use the file, and we will inform you about future upgrades.