; WRITTEN BY: TOM SCARFF ; 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 list p=16F877 ; list directive to define processor #include "p16f877.inc" ; processor specific variable definitions __CONFIG _CP_ALL & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. #DEFINE PAGE0 BCF 3,5 #DEFINE PAGE1 BSF 3,5 ;************************************************************* ; Constant Assignments ;************************************************************* CARRY EQU 0 ; CARRY BIT ;************************************************************** ; Variable Assignment Addresses ;************************************************************** ; ; ; temp1 equ 0x20 temp equ 0x21 port_time equ 28h midich equ 29h ped_val equ 2Ah sw_flags equ 2Bh sw_flags_2 equ 2Ch pedal_val equ 2Dh temp_lo equ 2Eh temp_hi equ 2Fh control_lo equ 30h control_hi equ 31h base_addr equ 32h temp_data equ 33h AD_DATA equ 34h dlyreg2 equ 35h dlyreg3 equ 36h tab0 equ 3Ah tab1 equ 3Bh tab2 equ 3Ch tab3 equ 3Dh tab4 equ 3Eh tab5 equ 3Fh tab6 equ 40h tab7 equ 41h ctrller equ 42h s ; ;************************************ ; 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 ; controller value movwf TXREG ; send character from W call txchar movlw 07fh ; control on movwf TXREG ; send character from W call txchar return ;***************************************************** ; Control-off subroutine ;***************************************************** ctrloff 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 movlw 00h ; control off movwf TXREG ; send character from W call txchar return ;***************************************************** ; 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 movf pedal_val,W ; controller value movwf TXREG ; send character from W call txchar movlw 07fh ; control on movwf TXREG ; send character from W call txchar return ;************************************ ; Portamento off ;************************************ portmoff movf midich,W addlw 0B0h ; Control Change movwf TXREG ; send character from W call txchar movf pedal_val,W ; controller value movwf TXREG ; send character from W call txchar movlw 00h ; control off movwf TXREG ; send character from W call txchar return ;**************************************************************** ; Main Programme ;**************************************************************** main clrf sw_flags clrf sw_flags_2 ;+++++++++++++++++++++++++++++++++++++++++++++++++++++ ; Read pots on analogue inputs ;+++++++++++++++++++++++++++++++++++++++++++++++++++++ read_pots clrf tab0 clrf tab1 clrf tab2 clrf tab3 clrf tab4 clrf tab5 clrf tab6 clrf tab7 ch0 movlw B'01000001' ; channel 0 movwf ADCON0 call convert call convert movf tab0,W subwf temp_lo,W ; (f) - (W)--> (dest) btfsc STATUS,Z ; Skip if result -Ve. ie f (dest) btfsc STATUS,Z ; Skip if result not same goto ch2 ; no change, so do not o/p data movf temp_lo,W movwf tab1 movlw .1 ;modulation movwf control_hi movlw .33 movwf control_lo movlw 07Fh andwf temp_lo call control call sw_dbnc ch2 movlw B'01010001' ; channel 2 movwf ADCON0 call convert call convert movf tab2,W subwf temp_lo,W ; (f) - (W)--> (dest) btfsc STATUS,Z ; Skip if result -Ve. ie f