Also is it true that the fcall macro is no longer needed? which sets up the pclath reg properly before calling functions on a different page
here is the 16F code for the sound player (1bit,1pin setup)
Code:
#include <p16F877A.inc>
__CONFIG _HS_OSC & _WDT_OFF & _CP_OFF & _CPD_OFF & _LVP_OFF
cblock 0x20
d1
d2
d3
Delay1 ; Define two file registers for the
Delay2 ; delay loop
bitCount
byteCount
blockCount
dataByte
OffsetH
OffsetL
endc
; the fcall macro
fcall macro subroutine_name
local here
lcall subroutine_name ; set PCLATH correctly
pagesel here ; set PCLATH correctly - means?
here:
endm
org 0x00
bsf STATUS,RP0 ; select Register Bank 1
bcf TRISD,0 ; make IO Pin RD0 an output
bcf STATUS,RP0 ; back to Register Bank 0
Start clrf OffsetH
clrf OffsetL
SoundLoop
fcall Table
nop
nop
nop
nop
movwf dataByte
movlw d'8'
movwf bitCount
BitBang
rlf dataByte
btfss STATUS,C
bcf PORTD,0
btfsc STATUS,C
bsf PORTD,0
call delay
decfsz bitCount
goto BitBang
incf OffsetL ; add 1 to data pointer
skpnz
incf OffsetH
NoUp movlw Low(d'8060')
xorwf OffsetL,W
skpz
goto SoundLoop
movlw High(d'8060')
xorwf OffsetH,W
skpz
goto SoundLoop
fcall label
delay
;998 cycles
movlw 0xC7
movwf d1
movlw 0x01
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
retlw 0x00
;
; SOUND DATA TABLE
;
Table movlw High(TStart)
addwf OffsetH,W
movwf PCLATH
movlw Low(TStart)
addwf OffsetL,W
skpnc
incf PCLATH,F
movwf PCL ;computed goto with right PCLATH
; end Table subroutine
TStart
;------------------------- 0
retlw b'10010110' ; 96
retlw b'11000010' ; c2
retlw b'10101111' ; af
retlw b'00100100' ; 24
retlw b'11010110' ; d6
retlw b'00110011' ; 33
retlw b'00110110' ; 36
retlw b'10001100' ; 8c
retlw b'11100101' ; e5
retlw b'10010010' ; 92
retlw b'11010101' ; d5
retlw b'10001101' ; 8d
retlw b'10010101' ; 95
..... 8060 retlw's in total (not included) ...
and the 18F code ... changes include:
1) RLF to RLCF for cycling the bits through the port
2) changing offset range from 8060 to 8060 x 2 = 16120
3) No need for fcall macro since 'call' can address 2MB ROM space
4)skpnc, skpnz, skpz, and skpc weren't defined anymore so had to use btfsc STATUS, C ... ect
Code:
LIST P=18F4620 ;directive to define processor
#include <P18F4620.INC> ;processor specific variable definitions
;******************************************************************************
__CONFIG _CONFIG1H, 0xC2
__CONFIG _CONFIG2H, 0x1E
__CONFIG _CONFIG2L, 0x1F
__CONFIG _CONFIG3H, 0x87
__CONFIG _CONFIG4L, 0x81
__CONFIG _CONFIG5H, 0xC0
__CONFIG _CONFIG5L, 0x0F
__CONFIG _CONFIG6H, 0xE0
__CONFIG _CONFIG6L, 0x0F
__CONFIG _CONFIG7H, 0x40
__CONFIG _CONFIG7L, 0x0F
cblock 0x80
d1
d2
d3
Delay1 ; Define two file registers for the
Delay2 ; delay loop
bitCount
byteCount
blockCount
dataByte
OffsetH
OffsetL
endc
org 0x00
bcf TRISD,0 ; make IO Pin RD0 an output
Start clrf OffsetH
clrf OffsetL
SoundLoop
call Table
nop
nop
nop
nop
movwf dataByte
movlw d'8'
movwf bitCount
BitBang
rlcf dataByte
btfss STATUS,C
bcf PORTD,0
btfsc STATUS,C
bsf PORTD,0
call delay
decfsz bitCount
goto BitBang
incf OffsetL ; add 1 to data pointer
btfsc STATUS,Z
incf OffsetH
incf OffsetL ; add 1 to data pointer
btfsc STATUS,Z
incf OffsetH
NoUp
movlw Low(d'16120')
xorwf OffsetL,W
btfss STATUS,Z
goto SoundLoop
movlw High(d'16120')
xorwf OffsetH,W
btfss STATUS,Z
goto SoundLoop
call Start ; end
delay
;998 cycles
movlw 0xC7
movwf d1
movlw 0x01
movwf d2
Delay_0
decfsz d1, f
goto $+6
decfsz d2, f
goto Delay_0
nop
nop
retlw 0x00
;
; SOUND DATA TABLE
;
Table
movlw High(TStart)
addwf OffsetH,W
movwf PCLATH
movlw Low(TStart)
addwf OffsetL,W
btfsc STATUS,C
incf PCLATH,F
movwf PCL ;computed goto with right PCLATH
; end Table subroutine
TStart
;------------------------- 0
retlw b'10010110' ; 96
retlw b'11000010' ; c2
retlw b'10101111' ; af
retlw b'00100100' ; 24
retlw b'11010110' ; d6
retlw b'00110011' ; 33
retlw b'00110110' ; 36
retlw b'10001100' ; 8c
retlw b'11100101' ; e5
retlw b'10010010' ; 92
retlw b'11010101' ; d5
retlw b'10001101' ; 8d
retlw b'10010101' ; 95
retlw b'01001101' ; 4d
retlw b'01011000' ; 58
retlw b'11010101' ; d5
retlw b'01100010' ; 62
retlw b'10111010' ; ba
retlw b'01010101' ; 55
retlw b'01100011' ; 63
retlw b'01010101' ; 55
..... 8060 retlw's in total (not included) ...