PDA

View Full Version : How to HSERIN and MIDI code?



francolok
- 18th December 2008, 15:24
How do I make to acquire data in entry with HSERIN to 31250 Baudrate with 20 MHz clock and PIC16f877?.I must handle the MIDI.
Can someone help me?:(
I'm try with this code...but no data!.... WHy?

@ DEVICE HS_OSC
DEFINE OSC 20
B0 VAR BYTE
B1 VAR BYTE
BIT5 VAR BIT
BIT4 VAR BIT
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 31250
DEFINE HSER_CLOERR 1

TRISA = $85
PORTA = $5
TRISB = $86
PORTB = $6
TRISC = $87
PORTC = $7
TRISD = $88
PORTD = $8
TRISE = $ff
PORTE = $9
PIR1 = $0C
TXREG = $19
RCREG = $1A
TXSTA = $98

POKE TRISA, %11011111
poke TRISB, %00000011
poke TRISC, %10111111
poke TRISD, %00000000
poke TRISE, %00000011
POKE PORTD, %00000000
POKE PORTB, %00000000
RCSTA = $90
'-------------------------------------------------
loop:
Gosub charin
If B1 = 0 Then loop
Gosub charout
Goto loop
charin:
B1 = 0
BIT5 = PIR1 & $20
If Bit5 = 0 Then ciret
Peek RCREG,B1
ciret:
Return
charout:
BIT4 = PIR1 & $0F
If Bit4 = 0 Then charout
Poke TXREG,B1
Return

skimask
- 18th December 2008, 16:59
DEFINE HSER_BAUD 31250
Not sure if PBP/HSERIN/HSEROUT calculate baud rate or use a lookup table, but I'm sure that 31250 isn't a 'standard' baud rate. You may have to set the baud rate (SPBRG) manually, by hand, by doing a few calculations, looking it up in the 16F877 datasheet, etc.


POKE TRISA, %11011111
What's up with the POKEs and PEEKs when you can just access the registers directly like:

RCSTA = $90