Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

UART and Hyperterminal

Status
Not open for further replies.

sandeepa

New Member
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

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.
 
I suggest you look at my PIC tutorials, I have both hardware and software UART's working fine with Hyperterminal.

You don't mention your hardware, I'm presuming you are using a MAX232 to connect the PIC to the PC?.
 
I have looked at your tutorial.Infact I am using the circuit on your site.
The MAX232,caps...theya re all theer.
Is there somethig wrong in the code thatI posted?
What am I doing wrong?
Thanks
 
sandeepa said:
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.

<snip>

;goto loop
;clrf STATUS
bcf TXSTA,TXEN;disable transmision
here
goto here

What am I doing wrong?

Thanks.

Clearing the TXSTA,TXEN bit aborts any transmission. Just leave it set. It only causes a problem if you use interupts by setting the PIR1,TXIE bit.

As for the pic doing stuff while it's powered down, I suggest that it's being powered some other way. Connecting one of the I/O pins to 5v will power the chip. This is because there is a protection diode from the I/O pins to Vcc which will power the chip.

HTH

Mike.
 
Keeping the TXEN bit set made no difference.I have also tried implementing a continuous loop,instead of a sigle transfer.Again,I saw a chain of the character I transmitted.....but only after the PIC was switched off.
I have tried a few pieces of code used successfully by others,whatever is supposed to be displayed is displayed....but only after I shut off the PIC.
So I suppose something must be wrong in the hardware side,but what?
I am using the circuit on Nigel's site,so nothings wrong with the basic circuit.
What should I check out for?
Thanks.
 
Maybe the PC is buffering the input. Try sending a CrLf (carriage return = chr(13), linefeed = chr(10)).

How about sending the famous "Hello World" as follows

Code:
                Movlw       "H"
                Call          serial_transmit 
                ; repeat for "ello Worl"
                Movlw       "d"
                Call           serial_transmit 
                Movlw        .13;                                 Carriage return
                Call           serial_transmit 
                Movlw        .10;                                 Linefeed
                Call            serial_transmit

HTH

Mike.
 
I tried this code
Code:
loop
	clrf	STATUS
serial_transmit
	banksel	PIR1
	btfss	PIR1,TXIF
	goto	serial_transmit
	clrf	STATUS
	movlw	'h'
	movwf	TXREG
	call	transmit_wait
	movlw	'e'
	movwf	TXREG
	call	transmit_wait
	movlw	'l'
	movwf	TXREG
	call	transmit_wait
	movlw	'l'
	movwf	TXREG
	call	transmit_wait
	movlw	'o'
	movwf	TXREG
	call	transmit_wait
	movlw    .13;    Carriage return 
	movwf	TXREG
    call    transmit_wait
	movlw     .10;   Linefeed
	movwf	TXREG 
    call    transmit_wait
	goto	loop
transmit_wait
	
	banksel	TXSTA
	btfss	TXSTA,TRMT
	goto	transmit_wait
	clrf	STATUS
	return

This si the output that i got on the HT
hello
h


But this again after I switched off the PIC....

Any ideas on what is wrong???

Thanks.
 
Your on/off switch is backward? :D

Sorry.

If your Pic really is being switched off, then, as Nigel says, the PC must be buffering it.

Can you try the following.

Edit - before you try this be aware that you may have to exit this window by using the task manager. And you may have to reset to free up your com port.

go to start
select run
type cmd
press enter

You should get a DOS window.

At the DOS prompt type :-
copy com1: con

Change com1 to the com port you are using and press enter.

If you now turn on your Pic circuit you should see "hello" on the screen.

To exit this you would normally use Ctrl-C and then type exit at the prompt, but this doesn't seem to work under XP.

Let us know how you get on.

Mike.
 
Hi

I tried this,nothing happens.The cursor just goes to the next line and thast it.

Also,the first time I send the command,I get the Abort,Retry,Fail thing.After A when I give the command again,the cursor goe to the next line and stays there.
The PC however becomes very slow while thisis happening,does this mean anything?

Thanks.
No, Hyperterminal works fine for me,

I tried Tera Term Pro as well,because I read around that Hyperterminal gives problems at time,but the result was the same.

Thanks.
 
Is there something not standard with the PC you use. Is the RS232 a USB to RS232 converter? Can you try a different port?

Can you try this on another PC?

Mike.
 
Last edited:
Is the RS232 a USB to RS232 converter?

No.



Can you try a different port?

Ok,will try the other port.
Right now,I have the mouse connected to it.The mouse works on both ports,if that means anything.
If somethings wrong with the prot,then shoring shorting the Tx and Rx lines shouldnt have displaye dthe characters,right?

Tried the other port,same result.

Can you try this on another PC?

That seems like the only thing left to do?? :(
 
I just tried shorting pins 2&3 of the RS232 port and ran HyperTerminal. With the standard settings I got nothing. I had to set the Flow Control to none. It then worked as expected I.E. Whatever I typed was displayed but if I disconected pins 2&3 I got nothing again.

To set flow control.

Select File/Properties
Where it says COM1, there is a configure button
The flow control is in the configure dialog.

HTH

Mike.
 
Hello everyone

Finally its worked...my mistake all along(as is always the case)

The configuration word had been accidently set to 3F7A instead of 0x3F7A!!! :shock: :oops:

Tried all the codes I had tried before and they all work fine.

A missing "0x" and two days of complete frustration.
Anyway,thanks a lot everyone esp. Pommie and Nigel Goodwin.
Thanks
 
sandeepa said:
Hello everyone

Finally its worked...my mistake all along(as is always the case)

The configuration word had been accidently set to 3F7A instead of 0x3F7A!!! :shock: :oops:

Tried all the codes I had tried before and they all work fine.

A missing "0x" and two days of complete frustration.
Anyway,thanks a lot everyone esp. Pommie and Nigel Goodwin.
Thanks

So what was it setting your fuses as?.
 
So what was it setting your fuses as?.

The fuse settings were shown as before.
Brown Out and Memory Write enabled and the type of oscillator as HS.

But without any base specified for the configuration word,would it be programmed into the memory?
 
sandeepa said:
So what was it setting your fuses as?.

The fuse settings were shown as before.
Brown Out and Memory Write enabled and the type of oscillator as HS.

Doesn't your programmer software show you what the fuses are set to?.

BTW, why do you have memory write enabled?.

But without any base specified for the configuration word,would it be programmed into the memory?

I would expect it to give an error message, unless you have the default radix set as hexadecimal.
 
"BTW, why do you have memory write enabled?."

No particular reason...it wont really cause any harm,will it?

unless you have the default radix set as hexadecimal.

Where is this setting done?I havent particularly done any such setting.Though I didnt get any error message regarding this.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top