I'm trying to program the onboard usart to just trasmit simple characters to a hyperterminal screen.
Here is what i have, I get nothing when I hook it up to my serial port and connect in hyperterminal.
Anyone have any suggestions? I'm using the 16F690.
Test Program:
*********************
'test_usart.bas
'Chip model
#chip 16F690, 8
#config INTRC_OSC_NOCLKOUT, WDT_OFF
#include "usart.h"
'Main routine
ADOFF
dir PORTC.7 out
SetupSerial
Main:
SET PORTC.7 ON
Wait 1 s
number = 99
TransmitSerial(number)
SET PORTC.7 OFF
wait 1 s
goto Main
********************
Here is my usart.h file
********************
'Hardware USART constants
#define SPBRG_VAL 51 'sets baud rate, 2400 for 8mhz clock
#define GOTNEWDATA 0 'bit that indicates new data received
#define USART_PORT PORTB 'hardware usart port
#define USART_TX 7 'hardware usart tx pin
#define USART_RX 5 'hardware usart rx pin
sub SetupSerial
ADOff 'make port digital
DIR USART_PORT.USART_TX OUT 'set tris bits for TX and RX
DIR USART_PORT.USART_RX IN
SPBRG = SPBRG_VAL 'set baud rate
TXSTA = b'01100000' 'enable transmission and low baud rate (BRGH = 0)
RCSTA = b'11010000' 'enable serial port and reception
SET FLAGS.GOTNEWDATA OFF
end sub
sub TransmitSerial(xmitdata)
LoopTransmit:
IF PIR1.TXIF OFF THEN goto LoopTransmit 'check if transmitter is busy
TXDATA = xmitdata
CalcParity(TXDATA) 'calculate parity
rotate ParityByte RIGHT 'get parity bit into status.c
SET TXSTA.TX9D OFF 'set parity bit to zero
IF STATUS.C = 1 THEN SET TXSTA.TX9D ON 'if status.c is one, set parity bit
TXREG = TXDATA 'transmit data
end sub
sub CalcParity(Temp) 'calculate even parity bit, data starts in paritybyte
'result is in Lsb of ParityByte
Paritybyte = Temp 'get data for parity calculation
rrf Paritybyte,W 'rotate
xorwf Paritybyte,W 'compare all bits against neighbor
movwf Paritybyte 'save
rrf ParityByte,F 'rotate
rrf ParityByte,F 'rotate
xorwf ParityByte,F 'compare every 2nd bit and save
swapf ParityByte,W 'rotate 4
xorwf ParityByte,F 'compare every 4th bit and save
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to program the onboard usart to just trasmit simple characters to a hyperterminal screen.
Here is what i have, I get nothing when I hook it up to my serial port and connect in hyperterminal.
Anyone have any suggestions? I'm using the 16F690.
Test Program:
*********************
'test_usart.bas
'Chip model
#chip 16F690, 8
#config INTRC_OSC_NOCLKOUT, WDT_OFF
#include "usart.h"
'Main routine
ADOFF
dir PORTC.7 out
SetupSerial
Main:
SET PORTC.7 ON
Wait 1 s
number = 99
TransmitSerial(number)
SET PORTC.7 OFF
wait 1 s
goto Main
********************
Here is my usart.h file
********************
'Hardware USART constants
#define SPBRG_VAL 51 'sets baud rate, 2400 for 8mhz clock
#define GOTNEWDATA 0 'bit that indicates new data received
#define USART_PORT PORTB 'hardware usart port
#define USART_TX 7 'hardware usart tx pin
#define USART_RX 5 'hardware usart rx pin
sub SetupSerial
ADOff 'make port digital
DIR USART_PORT.USART_TX OUT 'set tris bits for TX and RX
DIR USART_PORT.USART_RX IN
SPBRG = SPBRG_VAL 'set baud rate
TXSTA = b'01100000' 'enable transmission and low baud rate (BRGH = 0)
RCSTA = b'11010000' 'enable serial port and reception
SET FLAGS.GOTNEWDATA OFF
end sub
sub TransmitSerial(xmitdata)
LoopTransmit:
IF PIR1.TXIF OFF THEN goto LoopTransmit 'check if transmitter is busy
TXDATA = xmitdata
CalcParity(TXDATA) 'calculate parity
rotate ParityByte RIGHT 'get parity bit into status.c
SET TXSTA.TX9D OFF 'set parity bit to zero
IF STATUS.C = 1 THEN SET TXSTA.TX9D ON 'if status.c is one, set parity bit
TXREG = TXDATA 'transmit data
end sub
sub CalcParity(Temp) 'calculate even parity bit, data starts in paritybyte
'result is in Lsb of ParityByte
Paritybyte = Temp 'get data for parity calculation
rrf Paritybyte,W 'rotate
xorwf Paritybyte,W 'compare all bits against neighbor
movwf Paritybyte 'save
rrf ParityByte,F 'rotate
rrf ParityByte,F 'rotate
xorwf ParityByte,F 'compare every 2nd bit and save
swapf ParityByte,W 'rotate 4
xorwf ParityByte,F 'compare every 4th bit and save
end sub