Help me with RS232 comms.
Moderators: David Barker, Jerry Messina
-
- Posts: 41
- Joined: Thu Feb 26, 2009 6:54 pm
- Location: UK
Help me with RS232 comms.
Hi guys,
I need my PC to communicate with the PIC using RS232.
I understand well the hardware set-up, but I am a little lost with regard to the software.
I had a look in the software library and did not find an example to start me going.
Can anyone show me, to start with, a simple example to send a byte to my PC. I will use 'Terminal' to receive it.
Thanks in advance.
Francesco C
I need my PC to communicate with the PIC using RS232.
I understand well the hardware set-up, but I am a little lost with regard to the software.
I had a look in the software library and did not find an example to start me going.
Can anyone show me, to start with, a simple example to send a byte to my PC. I will use 'Terminal' to receive it.
Thanks in advance.
Francesco C
If you are using the USART module the setup is very simple.
Sorry do not know how to use the software module.
Code: Select all
Include "usart.bas"
USART.Write("HELLO WORLD",13)
-
- Posts: 41
- Joined: Thu Feb 26, 2009 6:54 pm
- Location: UK
If your using a PICKit 2, then USART coms is pretty easy..
If not, then something like a MAX232 or DS275 will allow interfacing with your PC from the PIC, here's a max232 circuit;
Example program;
Hyperterminal Output;
Not sure if that's what your chasing, but more info can be found hereeither way
If not, then something like a MAX232 or DS275 will allow interfacing with your PC from the PIC, here's a max232 circuit;
Example program;
Code: Select all
Device = 18F458
Clock = 20
Include "usart.bas"
Include "convert.bas"
Dim Variable_1 As Byte
// Start Of Program...
Variable_1 = 242
SetBaudrate(br19200)
USART.Write("Hello World", 13, 10) // string
USART.Write("Binary : ", BinToStr(Variable_1), 13, 10) // binary number
USART.Write("Hex : ", HexToStr(Variable_1), 13, 10) // hex number
USART.Write("Decimal : ", DecToStr(Variable_1), 13, 10) // decimal number
Not sure if that's what your chasing, but more info can be found hereeither way
digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples.
Australian distributor for the Swordfish Compiler
Australian distributor for the Swordfish Compiler
-
- Posts: 41
- Joined: Thu Feb 26, 2009 6:54 pm
- Location: UK
Hi,
Thank you for the help provided so far.
I was not aware of the large ammount of info available on the subject.
However I have not managed to make the comms work.
This is the very simple program I chose to make things happen.
#####################
Device = 18F2553
Clock = 20
Include "usart.bas"
SetBaudrate(br19200)
again:
USART.Write("HELLO WORLD",13)
DelayMS(200)
GoTo again
#########################
All I get is 'D2H' .......
My hardware set-up is on a PCB with a PIC18F255 connected to a MAX232
and to my computer comm port1.
I tryed to change the baud rate with no luck.
I replaced the MAX232, no luck again.
I know the PIC is working as I have been using it until I decided to start this project.
Am I missing something silly from the code?
I would appreciate some more input from you guys.
Thanks again.
Francesco C
Thank you for the help provided so far.
I was not aware of the large ammount of info available on the subject.
However I have not managed to make the comms work.
This is the very simple program I chose to make things happen.
#####################
Device = 18F2553
Clock = 20
Include "usart.bas"
SetBaudrate(br19200)
again:
USART.Write("HELLO WORLD",13)
DelayMS(200)
GoTo again
#########################
All I get is 'D2H' .......
My hardware set-up is on a PCB with a PIC18F255 connected to a MAX232
and to my computer comm port1.
I tryed to change the baud rate with no luck.
I replaced the MAX232, no luck again.
I know the PIC is working as I have been using it until I decided to start this project.
Am I missing something silly from the code?
I would appreciate some more input from you guys.
Thanks again.
Francesco C
What happens if you do this:-
Code: Select all
Device = 18F2553
Clock = 20
Include "usart.bas"
while 1=1
USART.SetBaudrate(br19200)
USART.Write("HELLO WORLD",13)
DelayMS(200)
wend
-
- Posts: 41
- Joined: Thu Feb 26, 2009 6:54 pm
- Location: UK