mike20200
- 30th August 2007, 23:52
Im using PIC 16F877A with 20MHZ crystal
and the UART.bas
================================================== ==================
define OSC 20
B1 var byte
TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
SPBRG = 25 ' Set baud rate to 2400
RCSTA = %10010000 ' Enable serial port and continuous receive
TXSTA = %00100000 ' Enable transmit and asynchronous mode
'Echo received characters in infinite loop
loop: Gosub charin ' Get a character from serial input, if any
If B1 = 0 Then loop ' No character yet
Gosub charout ' Send character to serial output
Goto loop ' Do it forever
' Subroutine to get a character from USART receiver
charin: B1 = 0 ' Preset to no character received
If PIR1.5 = 1 Then ' If receive flag then...
B1 = RCREG ' ...get received character to B1
'high PORTB.5
'pause 200
'low PORTB.5
'pause 200
Endif
ciret: Return ' Go back to caller
' Subroutine to send a character to USART transmitter
charout: If PIR1.4 = 0 Then charout ' Wait for transmit register empty
TXREG = B1 ' Send character to transmit register
'high PORTB.4
'pause 200
'low PORTB.4
'Pause 200
Return ' Go back to caller
================================================== =================
However what ever i type in like ABCD then the HYPERTERMINAL will return back some funny symbol can anyone help me???
and the UART.bas
================================================== ==================
define OSC 20
B1 var byte
TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
SPBRG = 25 ' Set baud rate to 2400
RCSTA = %10010000 ' Enable serial port and continuous receive
TXSTA = %00100000 ' Enable transmit and asynchronous mode
'Echo received characters in infinite loop
loop: Gosub charin ' Get a character from serial input, if any
If B1 = 0 Then loop ' No character yet
Gosub charout ' Send character to serial output
Goto loop ' Do it forever
' Subroutine to get a character from USART receiver
charin: B1 = 0 ' Preset to no character received
If PIR1.5 = 1 Then ' If receive flag then...
B1 = RCREG ' ...get received character to B1
'high PORTB.5
'pause 200
'low PORTB.5
'pause 200
Endif
ciret: Return ' Go back to caller
' Subroutine to send a character to USART transmitter
charout: If PIR1.4 = 0 Then charout ' Wait for transmit register empty
TXREG = B1 ' Send character to transmit register
'high PORTB.4
'pause 200
'low PORTB.4
'Pause 200
Return ' Go back to caller
================================================== =================
However what ever i type in like ABCD then the HYPERTERMINAL will return back some funny symbol can anyone help me???