;********************************************************************** ; This file is a basic code template for assembly code generation * ; on the PIC16F628A. This file contains the basic code * ; building blocks to build upon. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PIC data sheet for additional * ; information on the instruction set. * ; * ;********************************************************************** ; * ; Filename: xxx.asm * ; Date: * ; File Version: * ; * ; Author: * ; Company: * ; * ; * ;********************************************************************** ; * ; Files Required: P16F628A.INC * ; * ;********************************************************************** ; * ; Notes: * ; * ;********************************************************************** list p=16f628A ; list directive to define processor #include ; processor specific variable definitions #define LED PORTA,4 #define Bank0 bcf STATUS,RP0 #define Bank1 bsf STATUS,RP0 errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & DATA_CP_OFF & _LVP_ON & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_OFF & _HS_OSC ;***** VARIABLE DEFINITIONS w_temp EQU 0x7E ; variable used for context saving status_temp EQU 0x7F ; variable used for context saving ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt main ; port inits clrf PORTA ; zero ports A et B clrf PORTB movlw 0x07 movwf CMCON ; set port A mode I/O digital bcf STATUS,RP1 Bank1 clrf TRISB ; port B is OUT bsf TRISB,1 ; RX is IN clrf TRISA ; port A is OUT Bank0 ; USART config Bank1 movlw 0x09 ; value for the BRG movwf SPBRG ; init BRG 31250 bauds bcf TXSTA,SYNC Bank0 bsf RCSTA,SPEN ; start the USART rx/tx bsf RCSTA,CREN ; both line can be resume in one here MainLoop bsf LED ; LED- WaitMidi btfss PIR1,RCIF ; wait for RX flag goto WaitMidi ; loop until a byte is received bcf LED ; LED+ movf RCREG,W ; read the USART register (the MIDI byte is now avalable in W register for future use) movwf TXREG ; write W to the USART register goto MainLoop ; initialize eeprom locations ORG 0x2100 DE 0x00, 0x01, 0x02, 0x03 END ; directive 'end of program'