PDA

View Full Version : 18f4520 serial communication



merlinknight
- 3rd March 2007, 18:41
Hello,
I am a newbie, sorry if this is a stupid question, but i can find anything on this issue. Trying to learn small programming at a time to pick it apart.
I am wanting to experiment with serial communication with this chip. does anyone have an example of serial communication with the 18f4520.
My circuit board uses portc.6 for tx and portc.7 for rx. I have tried the sample program and find that i can not get it to work.
All i would like to do is transfer a text message to hyperterminal to see how data transfer works.
I take it that is the program that i would use. I hear people talking about using Microcode to receive this, not sure about this.
This is what i have at the moment.
I would also like to see how receivinig data works too. Let say i hit a key and i get it back on the screen,Echo.

include "modedefs.bas"


CMCON = 7
TRISC.7 = O
PORTC.7 = 0

print:
Serout PORTC.7, N2400, ["test"] ' Send string
pause 100 ' pause 1/10 sec
Goto print ' Forever

end

Appreciate any help. I probably missed some type of configuration of the PIC chip but i think this is it.

Thanks,
Merlinknight

mister_e
- 3rd March 2007, 21:41
What's your crystal speed?

For ANY PIC with a built-in USART (EUSART) i will suggest you to use it with a MAX232 inverter (or else). HSERIN/HSEROUT

MicroCodeStudio Serial communicator work pretty well. In the IDE, just hit F4, set the right settings then hit F9 to connect on the selected COM port. Easy easy easy.

merlinknight
- 4th March 2007, 02:02
Thanks Steve,
It is connected to a MAX232 . OSC is at 4 mhz. didnt know about the serial communicator. Nice toy. Still learning. But not giving up.

Thanks for taking the time to reply.

Merlin Knight

skimask
- 4th March 2007, 02:13
Thanks Steve,
It is connected to a MAX232 . OSC is at 4 mhz. didnt know about the serial communicator. Nice toy. Still learning. But not giving up.

Thanks for taking the time to reply.

Merlin Knight

Didn't you say earlier you were using C.6 for TX and C.7 for RX?
Your code says exactly the opposite...

--> My circuit board uses portc.6 for tx and portc.7 for rx.

--> Serout PORTC.7, N2400, ["test"] ' Send string

Bruce
- 4th March 2007, 14:55
You need to use non-inverted serial mode if you're going through the max232.

merlinknight
- 4th March 2007, 15:18
ok, i did have the incorrect pin. Thank you
second, i needed to change to T2400. Thank you

I will try to review my work closer in the future. Didn't see these.

It is now working. One more question.


include "modedefs.bas"


print:
Serout PORTC.6, t2400, ["test"] ' Send string
pause 100 ' pause 1/10 sec
Goto print ' Forever

end


If i was to use this statement how would the con be stated? SO con PortC.6. It does not compile with this. What should be here. I would think that i need to state port and bit.

SO con portc.6 ' Define serial out pin

Bruce
- 4th March 2007, 15:30
PBP automatically makes the pin an output.

Serout PORTC.6 tells PBP which port & pin to use. You can't declare a port
pin as a constant.