UART and PIC16f877a

I am trying to send characters to the PC using the hardware UART in

16f877a. The problem is that the characters are displayed only after I switch off the power to the PIC.I have tried various snippets of codes used successfully by others,however the result is always the same. I am using MAX232 between the PC and the PIC. Also when I tried receiving a character and transmitting it again,nothing happened.i.e. even after powering down the PIC,nothing was displayed as was the case previously. Shorting the Tx and Rx pins however displays the keyed in character on the screen. What could be going wrong? Thanks.
Reply to
sandeepa
Loading thread data ...

Hi,

Sounds like the PC end software is displaying 'whole lines' rather than character-at-a-time. When you switch off the PIC, you may be generating a 'break' condition which may trigger the end-of-line function.

Do you have a scope or logic probe? It would help to monitor the lines going both ways.

--
Luhan Monat (luhanis 'at' yahoo 'dot' com)
"The future is not what it used to be..."
http://members.cox.net/berniekm
Reply to
Luhan Monat

I'm betting the problem is in the PC setup. Hook two PCs together, get them talking, then try the PIC. mike

--
Return address is VALID but some sites block emails
with links.  Delete this sig when replying.
.
Wanted, PCMCIA SCSI Card for HP m820 CDRW.
FS 500MHz Tek DSOscilloscope TDS540 Make Offer
Wanted, 12.1" LCD for Gateway Solo 5300. Samsung LT121SU-121
Bunch of stuff For Sale and Wanted at the link below.
MAKE THE OBVIOUS CHANGES TO THE LINK
http://www.geocities.com/SiliconValley/Monitor/4710/
Reply to
mike

I've done the same thing, and have seen it work.

I suspect that Mr. Luhan has got the gist of it. If you use Hyperterminal, and defeat enough handshaking in its options dialog(s), (assuming your PIC is not handshaking as you would surely have stated if so), then you may well see the characters as soon as they are sent.

You are welcome.

--
--Larry Brasfield
email: donotspam_larry_brasfield@hotmail.com
Above views may belong only to me.
Reply to
Larry Brasfield

This was one of the codes I tried 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 is the output I got hello h after I turned the PIC off.

I dont have a scope,so cant check the sgnals on the lines.

I am not using handshaking,tried the ckt both ways,with just 3 lines(Tx,Rx,Gnd) as well as shorting the lines to make it look like the handshaking signals were present.The result in both cases is the same. And I tried using the other terminal software,Tera Term Pro as well,because I read HT can give problems.The reult...ditto...

Just cant figure out where the problem is.....please help.

Thanks.

Reply to
sandeepa

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

The output seen is hello h

after I switch the PIC off.

Dont have a scope;so cant see the waveforms on the pins. I am not using any handshaking signals.Have tried both ways;with just 3 pins(Tx,Rx,Gnd) as well as the others connected ina way to make it look like the handshaking signals were present.The result in both the cases is the same.

Also, since I had read that Hyperterminal causes problems,got the Tera Term software,the same thing happens with it as well.

Just cant figure out whats happening...please help.

Thanks.

Reply to
sandeepa

Nothing is displayed until you turn off the PIC? If so, that's wierd.

What you show as output amounts to 8 bytes. Not sure if that means anything. The PIC doesn't have an 8-byte buffer in its serial TX path but the receive end could.

You need a way to gather more info. You say you don't have a scope. I'd attach an LED to a pin on the PIC and write some code that can toggle it with a half second delay or thereabouts. First just get the LED toggling working. Now put that code at the end of your tx loop. If your LED keeps flashing and you got some data on the receiving end, then it is probably still sending. Simplify, checkpoint, rule things out, insert and move debugging code.

You should really find some way to see if the serial interface is toggling. There are cheap logic probes that could help or think of another way.

You need to find ways to gather more information, otherwise you are just making laps around the elephant. (The three blind men story. An elephant looks like a tree, no, it looks like...)

Reply to
xray

I`ve had this problem. With the pic 16f877 i think you can invert the polatiy of the uart signal as the max232 contains an inverter, so the signal is inverted.

I think this was the soloution, it was a long time ago i had that problem.

Thanks

Reply to
timmmmayyy!

Heck, if you're going for a dumb terminal, try Telix or Procomm or Kermit, if you can still find any of them.

Good Luck! Rich

Reply to
Rich Grise

SNIP

Try to get the ancient Terminal.exe (e.g. from windows 3.x) It is considerable less temperamentel than Hyperterminal.

Wim

Reply to
Wim Ton

Nope, the level shifter does do an invert, sort of, a 1 becomes a negative voltage and a 0 becomes a positive voltage, BUT all of that gets converted back to the appropriate values when the other ends level shifter does its thing. I believe you are remembering what you had to do if you wanted to use the UART with out a level shifter. There is a little resistor trick you can do to get a PIC to do half asses rs-232 with out the level shifter.

Jim

Reply to
James Beck

Last year I was looking for a simple terminal program that had an option to display or send in hex. I found this one...

formatting link

Its freeware too.

Reply to
xray

Hello everyone, Thanks for all your inputs.Last night got the thing working. My mistake all along(as is always the case) ...

The configuration word had been accidently set to 3F7A instead of

0x3F7A!!!

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

A missing "0x" and two days of complete frustration.

Though still dont know what it would have actually meant,because I have read that numbers without any explicit base are taken as the default which is hex anyway. But changing that and absolutely nothing else has got the thing wprking.

Thank you all for all your help once again.

Reply to
sandeepa

Just a update,because things are I think now making some sense. I tried the code that worked yesterday with __config 3F7A,i.e. without the 0x. And it still worked....and I almost got spooked out.

So went back to my first code .The config value set there is 3F79,which sets the oscillator to XT.(3F7A sets it to HS).Burned it on the chip(i.e. config set to 3F79),and things started behaving as before i.e. display after power switched off.Changed the setting to 3F7A and all was fine again.

So the mistake really was not,not specifying the base(which makes no difference),but setting the wrong oscillator bits.(I need to set it to HS as I am using 8MHz crystal).

JUst thought I should put in the final update here. Thanks.

Reply to
sandeepa

Have a look at Bray Terminal:

formatting link
also free!!

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
Manufacturers and Suppliers of HF Selcall
P O Box 1108, Morley, WA, 6943
Tel: +61 8 9370 5533 Fax +61 8 9467 6146
Web Site: http://www.jenal.com 
Contact: http://www.jenal.com/?p=1
++++++++++++++++++++++++++++++++++++++++++
Reply to
Alan

Kermit is still alive and kicking.

-- "Electricity is of two kinds, positive and negative. The difference is, I presume, that one comes a little more expensive, but is more durable; the other is a cheaper thing, but the moths get into it." (Stephen Leacock)

Reply to
Fred Abse

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.