'************************************************************************
'* *
'* SOFTWARE USART AT 2400 BAUD 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 : March 03, 2006 *
'* REVISED DATE : May 24, 2006 *
'* *
'************************************************************************
'
'
' commandas are
' rs232_putch(ASCII value of the char to be sent)
' rs232_getch() as byte
' rs232_init()
'
' RB0 and RB1 of PORTB are being used here for software RS232_TX and RS232_RX
'
' RB1 = output TX
' RB0 = input RX
'
' parameters are: baud rate = 2400, Data bits = 8, Patity = none, Stop bit = 1
'******************************* delays for the rs232 **************************
Dim rs232_count as byte
sub wait()
asm
{
MOVLW d'132'
MOVWF _rs232_count
LOOP1:
DECFSZ _rs232_count, F
GOTO LOOP1
return
}
end sub
sub wait_1()
asm
{
MOVLW d'64'
MOVWF _rs232_count
LOOP:
DECFSZ _rs232_count, F
GOTO LOOP
return
}
end sub
'************************ RS232 Initializing routines *****************************
'following is the procedure to intialize the pins of PORTB for rs232 port
Sub rs232_init()
trisb = ( 00000001b ) 'PORTB(0) = RX; PORTB(1) = TX PORTB, PIN2 to PIN7 are being used for lcd
call rs232_putch(0)
End Sub
'************************ RS232 Initializing routines ends ************************
'************************ RS232 TX procedure *****************************
'following is the procedure to output a byte to the rs232 port
Sub rs232_putch(c as byte)
Dim bit_no as byte
portb.1 = 0
bit_no = 9
do while (bit_no > 0)
call wait()
bit_no = bit_no - 1
portb.1 = (c & 1)
c = (c >> 1) | 0x80
loop
portb.1 = 1
call wait()
end sub
'************************ RS232 TX procedure ends *************************
'************************ RS232 RX procedure *****************************
'following is the function that recieves the byte from the rs232 port. The function waits till a byte is recieved
function rs232_getch() as byte
Dim bit_no as byte, byteread as byte
bit_no = 8
byteread = 0
do while (portb.0 = 1)
_asm nop
loop
call wait_1()
do while (bit_no > 0)
call wait()
byteread = (byteread >> 1)
byteread.7 = portb.0
loop
call wait()
rs232_getch = byteread
end function
'************************ RS232 RX procedure ends ************************
Copyright © 2006 SourceBoost Technologies