Interrupt based software UART TX beta

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
Blue Bill
Posts: 10
Joined: Thu Sep 27, 2012 3:37 pm
Location: Toronto

Interrupt based software UART TX beta

Post by Blue Bill » Sun Jun 02, 2013 4:36 am

Just hammering out some code and getting back into PIC programming.
I'm working on a buffered IRQ & TIMER driven software UART that doesn't tie up the CPU with delays. It's a first draft but seems to work and is currently only a single character. I'll post more code as I complete the full TX/RX routine with buffers.

QpinTX = PORTx.y
Put the character to be transmitted in QTXSendChar and set QTXControl = 12
Requires a TIMER interrupt at your chosen baud rate.

Code: Select all

Dim QTXSendChar, QTXControl As Byte
Interrupt ISR()		
If TIMERIRQ = 1 Then     
	If QTXControl > 0 Then  ' service the TX buffer one bit at a time
		Dec(QTXControl)
		If QTXControl = 11 Then 	' Start bit
			Low(QpinTX)
	    Else     					' shift out byte LSB to MSB
	        QTXSendChar = QTXSendChar >> 1
		QpinTX = STATUS.0		' transmit overflow bit
		QTXSendChar.7 = 1		' fill with stop bit, $FF on exit
		EndIf
	EndIf
Comments welcome.
Blue Bill (aka BlueRoomElectronics)

Post Reply