'******************************************************** '* * '* HARDWARE USART LIBRARY FOR USE WITH BOOST BASIC * '* * '* WRITTEN BY : PUNERJOT SINGH MANGAT * '* COUNTRY : INDIA * '* CITY : PATIALA * '* WEB PAGE : www.rackeys.com/punerjot * '* EMAIL : punerjot@rackeys.com * '* SOURCEBOOST ID : c58_4311 * '* RELEASE DATE : May 24, 2006 * '* REVISED DATE : May 24, 2006 * '* * '******************************************************** ' ' ' ' commandas are ' usart_tx(ASCII value of the char to be sent) ' usart_rx() as byte ' usart_init() ' ' ' RC6 = output TX ' RC7 = input RX ' ' parameters are: baud rate = 4800, Data bits = 8, Patity = none, Stop bit = 1 ' ' the baud rate can be changed by changing the SPBRG value that can ' be calculated by BaudCalc.Exe '*************** USART Initializing routines *********************** sub usart_init() trisc.6 = 0 'RC6 as output TX trisc.7 = 1 'RC7 as input RX txsta = 0 spbrg = 12 'for 4800 baud at 4 Mhz freq txsta = 0x22 '00100010 rcsta = (10010000b) 'with continuous recieve end sub '************** USART Initializing routines ends ******************* '******************** USART TX procedure *************************** sub usart_tx(b as byte) do while ( !(txsta & 0x02) ) _asm nop _asm clrwdt loop txreg = b end sub '******************** USART TX procedure ends ********************** '******************** USART RX procedure *************************** function usart_rx() as byte if ( (rcsta.OERR = 1) ) then rcsta.CREN = 0 rcsta.CREN = 1 usart_rx = 0x00 else do while (pir1.RCIF = 0) _asm nop loop usart_rx = rcreg end if end function '******************** USART RX procedure ends *********************
Copyright © 2006 SourceBoost Technologies