Académique Documents
Professionnel Documents
Culture Documents
; DATE: 20/08/2002
; ITERATION: 1.0
; FILE SAVED AS: foot_ped.ASM
; FOR: PIC16F877
; CLOCK: 4.00 MHz CRYSTAL
; INSTRUCTION CLOCK: 1.00 MHz T= luS
; PROGRAMME FUNCTION: Foot pedal
; 8 controller and switch i/ps to MIDI out
__CONFIG _CP_ALL & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _WRT_ENA
BLE_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
;*************************************************************
; Constant Assignments
;*************************************************************
;
;************************************
; Initialize EEPROM
;************************************
org 2100h
dw 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
;************************************************************
; PROGRAMME Reset Point
;************************************************************
org 00 ; reset vector
goto init
org 04 ; interrupt vector
goto init
;
;--------------------------------------------------------------------------
init
PAGE1
movlw 0FFh
movwf TRISB ;all pins inputs
movwf TRISA ;all inputs
movwf TRISD
clrf ADCON1 ; Set porta as analogue I/P's
PAGE0
; Set up USART
PAGE1
bsf STATUS,RP0 ; goto page 1
movlw b'10001111' ; RC7 is RX input
movwf TRISC
movlw 01h ; 31250 baud for MIDI
movwf SPBRG
movlw b'00100000' ; async tx 8 bit
movwf TXSTA
bcf STATUS,RP0 ; return to page 0
movlw b'10010000' ; async rx 8 bit
movwf RCSTA
bsf STATUS,RP0 ; enable weak pull-up resistors
movlw 07h ; rtcc/256
movwf OPTION_REG
bcf STATUS,RP0
movf PORTC,W ; read midich. switches
andlw 0Fh
movwf midich
goto main
;-------------------------------------------------------------------------
;************************************
; Switch Debounce Delay (40mS)
;************************************
sw_dbnc movlw 40h ; Delay routine
movwf dlyreg2
debnce call delay3
decfsz dlyreg2
goto debnce
return
;*************************************
; Delay Subroutine (770uS)
;*************************************
delay3 movlw .255
movwf dlyreg3
dly3 decfsz dlyreg3
goto dly3
nop
return
;******************************************
; transmission complete subroutine
;***************+**************************
txchar bsf STATUS,RP0
btfss TXSTA,1 ; test for end of transmission
goto $-1
bcf STATUS,RP0
return
;*********************************************
; Start A/D conversion Subroutine
;*********************************************
convert bsf ADCON0,2 ;set GO/DONE Bit
btfsc ADCON0,2
goto $-1
PAGE1
rrf ADRESL,F
PAGE0
btfss ADRESH,0
goto shift_r
PAGE1
bsf ADRESL,7
rrf ADRESL,W
;;;;;;;;;;;;;;;;;;andlw 07Fh
PAGE0
movwf temp_lo
shift_r
PAGE1
rrf ADRESL,W
andlw 07Fh
PAGE0
movwf temp_lo
rrf ADRESH,W
;;;;;;;;;;;;;;;;;;;;;;andlw 07Fh
movwf temp_hi
return
;************************************************************************
; Output MIDI Pitch Bend data
;***********************************************************************
pitchbend
movlw 0E0h ; Pitch-bend + ch.?
addwf midich,W
movwf TXREG ; send chazacter from W
call txchar
movf temp_lo,W
movwf TXREG ; send character from W
call txchar
movf temp_hi,W
movwf TXREG ; send character from W
call txchar
return
;************************************************************************
; Output MIDI Control data
;***********************************************************************
control
movlw 0B0h ; Control change + ch.?
addwf midich,W
movwf TXREG ; send chazacter from W
call txchar
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;movlw 01h
movf control_hi,W
movwf TXREG ; send character from W
call txchar
movf temp_hi,W
movwf TXREG ; send character from W
call txchar
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; movlw .33
movf control_lo,W
movwf TXREG ; send character from W
call txchar
movf temp_lo,W
movwf TXREG ; send character from W
call txchar
return
;+++++++++++++++++++++++++++++++++++++++++++++++++
;*****************************************************
; Control-on subroutine
;*****************************************************
ctrlon movf midich,W
addlw 0B0h ; Control Change
movwf TXREG ; send character from W
call txchar
movf ped_val,W
movwf TXREG ; send character from W
call txchar
;*****************************************************
; Start-on subroutine
;*****************************************************
starton movlw 0FAh ;Start
movwf TXREG ; send character from W
call txchar
return
;*****************************************************
; Continue subroutine
;*****************************************************
continue movlw 0FBh ; Continue
movwf TXREG ; send character from W
call txchar
return
;*****************************************************
; Stop subroutine
;*****************************************************
stop movlw 0FCh ;Stop
movwf TXREG ; send character from W
call txchar
return
;************************************
; Portamento +time on
;************************************
portmon movf midich,W
addlw 0B0h ; Control Change
movwf TXREG ; send character from W
call txchar
movlw .05 ; Portamento Time control
movwf TXREG ; send character from W
call txchar
movf port_time,W
movwf TXREG ; send character from W
call txchar
;****************************************************************
; Main Programme
;****************************************************************
movlw 07Fh
andwf temp_lo
call pitchbend
call sw_dbnc
movlw 07Fh
andwf temp_lo
call control
call sw_dbnc
movlw 07Fh
andwf temp_lo
call control
call sw_dbnc
movlw .2 ;breath
movwf control_hi
movlw .34
movwf control_lo
movlw 07Fh
andwf temp_lo
call control
call sw_dbnc
movlw .8 ;balance
movwf control_hi
movlw .40
movwf control_lo
movlw 07Fh
andwf temp_lo
call control
call sw_dbnc
movlw 07Fh
andwf temp_lo
call control
call sw_dbnc
ch7 movlw B'01111001' ; channel 7
movwf ADCON0
call convert
call convert
movf tab7,W
subwf temp_lo,W ; (f) - (W)--) (dest)
btfsc STATUS,Z ; Skip if result -Ve. ie f<W
goto sw0 ; no ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;11111111111
1111
movf temp_lo,W
movwf tab7
movlw 07Fh
andwf temp_lo
call control
call sw_dbnc
;-------------------------------------------
;-------------------------------------------
;-------------------------------------------
;-------------------------------------------
sw9
goto ch0
end