I am trying to connect 16f877a to the PC,using the hardware UART.
The problem is that the Hyperterminal shows the data transmitted by the PIC when the PIC is switched off.
And even then,though most of the times it shows the correct character,at times it shows some crap.
This is my code
In this case I get "U" after switching the PIC off.When the program is looped instead of disabling the transmission,I get a string of "U" after switching off the PIC.
I also tried receiving a character and then transmitting it;but in this case nothing happens.
What am I doing wrong?
Thanks.
The problem is that the Hyperterminal shows the data transmitted by the PIC when the PIC is switched off.
And even then,though most of the times it shows the correct character,at times it shows some crap.
This is my code
Code:
list p=16F877A
include "P16F877A.inc"
__config 3F79
errorlevel 2
data_reg equ 0x20
serial_port equ PORTC
serial_port_tris equ TRISC
bit0 equ 0
bit1 equ 1
bit2 equ 2
bit3 equ 3
bit4 equ 4
bit5 equ 5
bit6 equ 6
bit7 equ 7
uart_in equ bit7
uart_out equ bit6
org 0x0000
goto start
org 0x0005
start
call serial_port_init
loop
clrf STATUS
serial_transmit
banksel PIR1
btfss PIR1,TXIF
goto serial_transmit
clrf STATUS
movlw 'U'
movwf TXREG
transmit_wait
banksel TXSTA
btfss TXSTA,TRMT
goto transmit_wait
;goto loop
;clrf STATUS
bcf TXSTA,TXEN;disable transmision
here
goto here
serial_port_init
clrf STATUS
bsf STATUS,RP0
movlw b'11000000' ;RC6,RC7 set as inputs
movwf serial_port_tris
movlw d'51' ;8MHz clock,9600 baud rate
movwf SPBRG
movlw b'00000100' ;BRGH high
movwf TXSTA
bsf TXSTA,TXEN
banksel RCSTA
bsf RCSTA, SPEN
bcf RCSTA, RX9
bsf RCSTA, CREN
return
end
In this case I get "U" after switching the PIC off.When the program is looped instead of disabling the transmission,I get a string of "U" after switching off the PIC.
I also tried receiving a character and then transmitting it;but in this case nothing happens.
What am I doing wrong?
Thanks.