void SendCC(uint8_t no, uint8_t v) { while (Busy2USART()); Write2USART(0xB0|CHANNEL); while (Busy2USART()); Write2USART(no); while (Busy2USART()); Write2USART(v); __delay_ms(1); }
void SendNoteOff(uint8_t no) { while (Busy2USART()); Write2USART(0x80|CHANNEL); while (Busy2USART()); Write2USART(no); while (Busy2USART()); Write2USART(VELOCITY); clrbit(leds,no-octave*12); __delay_ms(1); }
SendNoteOn(uint8_t no) { while (Busy2USART()); Write2USART(0x90|CHANNEL); while (Busy2USART()); Write2USART(no); while (Busy2USART()); Write2USART(VELOCITY); setbit(leds,no-octave*12); __delay_ms(1); }
void Uart2_TransmitHandler(void) { volatile UINT8 data ; if( uart[1].txDataCount == 0 ) //check whether there is data to be transmitted { #if(defined __18F8722_H) ||(defined __18F46K22_H) while(Busy2USART()); #else while(BusyUSART()); #endif #ifdef __RS485__ TX2_EN = 0; //disable RS485 control #endif TXSTA2bits.TXEN = 0; //disable transmission return; } data = uart[1].txBuff[uart[1].txDataIndex]; TXREG2 = data; //transmit uart[1].txDataIndex++; //increase the dataIndex to point to the next data to be transmitted if( uart[1].txDataIndex >= TX_PACKET_SIZE) //on rollover { uart[1].txDataIndex = 0; //reset } if( uart[1].txDataCount > 0) uart[1].txDataCount--; //decrement the data count to indicate transmission }
void putch( char data) { while (Busy2USART()) continue; // Write2USART(data); // Should use this, but gives linker error TXREG2 = data; // Write the data byte to the USART2 }
void puts2USART( char *data) { do { // Transmit a byte while(Busy2USART()); putc2USART(*data); } while( *data++ ); }
// http://microchip.wikidot.com/faq:29 void putch(char c) { #ifdef DEBUG #ifdef WITH_HOS while (Busy2USART()) CLRWDT(); Write2USART(c); while (Busy2USART()) CLRWDT(); #else while (Busy1USART()) ; Write1USART(c); while (Busy1USART()) ; #endif #endif }
/*Bluetooth UART Functions*/ void UART2_Write_Char(char data) { while ( Busy2USART() ); Write2USART(data); /* while (!TXSTA2bits.TRMT); //wait until transmit shift register is empty TXREG2 = data; //write character to TXREG and start transmission */ }
// USB/USART combined put char (handles printf) void _user_putc(unsigned char c) { #ifdef USE_USART putc1USART(c); while(Busy1USART()); #endif #if defined(DEBUG_USART2_TX) || defined(UART2_DATA_OUTPUT) Write2USART(c); while(Busy2USART()); #endif usb_putchar(c); }
BOOL UART2_write(UINT8 data) { #if(defined __18F8722_H) ||(defined __18F46K22_H) while(Busy2USART()); //wait for current transmission if any #else while(BusyUSART()); //wait for current transmission if any #endif //DISABLE_UART_TX_INTERRUPT(); //disable the transmit interrupt uart[1].txBuff[uart[1].txBuffIndex++] = data; //store the data in the tx buffer uart[1].txDataCount++; //increment the data count if(uart[1].txBuffIndex >= TX_PACKET_SIZE) //check for overflow { uart[1].txBuffIndex = 0; } //ENABLE_UART_TX_INTERRUPT(); return TRUE; }
char UART2_TX_Empty() { return(!Busy2USART()); // return TXSTA2bits.TRMT; //Returns Transmit Shift Status bit }