Jon Wilder
Active Member
16F628 MIDI Code Template...Experts Please Review
Hi there...as I'm learning more about the 16F628 I've decided to make a template for coding MIDI stuff that I know will work for MIDI. Was wanting to get a 2nd set of eyes to look it over and maybe offer advice regarding how I can improve on it or if it's fine the way it is. Any and all suggestions from the experts welcome.
This is a pre-canned template for the 16F628 that I wrote and have tested in a MIDI circuit. Just looking for pointers on how I can improve my coding technique in order to keep from becoming what the pros refer to as a "sloppy programmer".
For those of you who are just starting out in the world of MIDI with the 16F628 are more than welcome to use this template. Everything I do with the 16F628 is purely experimental and is considered open source. I plan to graduate to a higher level PIC uC here in the near future so please feel free to use this template for anything MIDI as it has been tested and it does work.
Hi there...as I'm learning more about the 16F628 I've decided to make a template for coding MIDI stuff that I know will work for MIDI. Was wanting to get a 2nd set of eyes to look it over and maybe offer advice regarding how I can improve on it or if it's fine the way it is. Any and all suggestions from the experts welcome.
This is a pre-canned template for the 16F628 that I wrote and have tested in a MIDI circuit. Just looking for pointers on how I can improve my coding technique in order to keep from becoming what the pros refer to as a "sloppy programmer".
For those of you who are just starting out in the world of MIDI with the 16F628 are more than welcome to use this template. Everything I do with the 16F628 is purely experimental and is considered open source. I plan to graduate to a higher level PIC uC here in the near future so please feel free to use this template for anything MIDI as it has been tested and it does work.
Code:
;***************************************************************************************************************
;***************************************************************************************************************
;** **
;** **
;** **
;** **
;** MIDI Software Template **
;** With 16F628 PIC Micro **
;** **
;** By **
;** **
;** Jon Wilder **
;** **
;** **
;** **
;** **
;***************************************************************************************************************
;***************************************************************************************************************
;** **
;** Processor Config **
;** **
;** **
;***************************************************************************************************************
;***************************************************************************************************************
processor 16F628
include <P16F628.INC>
__CONFIG 0x3D22 ;disable cp, dcp, lvp, boden, wdt & enable mclre, pwrt, hs osc
; external clock speed = 20MHz
;***************************************************************************************************************
;***************************************************************************************************************
;** **
;** Port Initialization **
;** **
;** **
;***************************************************************************************************************
;***************************************************************************************************************
org 0x00 ;start at address 0
clrf PORTA ;initialize Port A register
clrf PORTB ;initialize Port B register
bsf STATUS,RP0 ;switch to Bank 1
bcf STATUS,RP1 ;switch to Bank 1
movlw B'00000000'
movwf TRISA ;set Port A up as all outputs
movlw B'00000110' ;set Port B up as all outputs
movwf TRISB ;with the exception of RB1/RX and RB2/TX
bcf STATUS,RP0 ;switch to Bank 0
bcf STATUS,RP1 ;switch to Bank 0
movlw 0x07 ;disable on board
movwf CMCON ;comparator
;***************************************************************************************************************
;***************************************************************************************************************
;** **
;** USART Initialization **
;** **
;** **
;***************************************************************************************************************
;***************************************************************************************************************
bsf STATUS,RP0 ;switch to Bank 1
bcf STATUS,RP1 ;switch to Bank 1
movlw 0x09 ;set Baud Rate Generator up for
movwf SPBRG ;31,250 baud with 20MHz crystal
bcf TXSTA,SYNC ;enable asynchronous serial comm mode
bcf STATUS,RP0 ;switch to Bank 0
bcf STATUS,RP1 ;switch to Bank 0
bsf RCSTA,SPEN ;serial port enable
bsf RCSTA,CREN ;continuous receive enable
;***************************************************************************************************************
;***************************************************************************************************************
;** **
;** Program Start **
;** **
;** **
;***************************************************************************************************************
;***************************************************************************************************************
Main
Program Goes Here
;***************************************************************************************************************
;***************************************************************************************************************
;** **
;** Subroutines **
;** **
;** **
;***************************************************************************************************************
;***************************************************************************************************************
Subroutines go here
End
Attachments
Last edited: