Solved

Interfacing RS232 to PIC16f877

Posted on 2003-12-09
6
6,201 Views
Last Modified: 2013-12-09
hi, Im doing a project using PIC16F877 and I want to interface it with RS232 of my PC so that I can have the output to my PC monitor. I made GUI but my problem is how to get the data from PIC. Can anyone give me a program about interfacing using RS232 I already have the hardware and schematic but I dont have the software for it to work. Anyone? I appreciate your help...
0
Comment
Question by:winsthon
6 Comments
 

Accepted Solution

by:
Thorn01 earned 168 total points
ID: 9929561
To send a byte.
First you will have to make a delay function based on what baud you want to use and how fast your Clock is running at. You can calculate this or experiment. A scope is an awsome tool for watching this.. just continuasly send the same byte over and over in a loop and you can watch whats going on.

Then to send the byte follow the next steps. (Here i am talking about N81)
No parity, 1 stop bit, 8 data bits. RS232 Transmitts Least Signifcant Digit First

1) Pull the pin low.. Delay a couple times to settle down
2) Start Bit - Put your output high, delay once
3) Take your byte you want to send then bitwise AND with 0x01
4) Output this value to your output pin
5) Delay once
6) Shift your byte to send to the right one bit
7) Repeat step 3 Until you have shifted it 7 times which will have sent all your data across the line.
8) Stop Bit - Place output High Delay once
9) Pull low again wait a little while then send next byte.

Depending on what your RS232 - TTL Level converter does you may have to invert the output.. Have step 1 high then pull the start bit low.. so on and so forth. If you are using a C compiler they always put serial send functions in which automatically figure out the delay for the baud and frequency of the chip.. I always use C2C as a compiler works great and you can inline asm if you need it.
0
 

Author Comment

by:winsthon
ID: 9947763
can you give me a code to start with I mean I dont know how to start that's I ask for help. I already have the hardware all I need is a code for the PIC...anyone?
0
 
LVL 6

Assisted Solution

by:DaFox
DaFox earned 166 total points
ID: 9991102
Hi winsthon,

I case you're using MPASM, take a look at the microchip site, e.g.
- http://www.microchip.com/download/appnote/pic16/00774a.pdf
  - http://www.microchip.com/download/appnote/pic16/00774.zip
- http://www.microchip.com/1010/suppdoc/appnote/func/commun/usart/index.htm

If you're using a C compiler search for its serial communications library. Then you can use printf() (and all the other) commands that make life very easy ;)
As the host software I often just use HyperTerminal!

Good luck,
Markus
0
 
LVL 17

Assisted Solution

by:mokule
mokule earned 166 total points
ID: 10000927
Hi
Download MPLAB IDE from Microchip site
And here are some helpful procedures
;initializing procedure
init_rs
    BSF     STATUS, RP0     ; Select Bank 1
      MOVLW      B'00100000' ; 8 bits, TXEN, asynchronous, low speed
      MOVWF      TXSTA
      movlw      5  ;9600 bauds in case of 3,6864MHz quartz
      movwf      SPBRG            ; speed
    BCF     STATUS, RP0     ; Select Bank 0
      MOVLW      B'10010000'      ; SPEN, 8 bitow, CREN
      MOVWF      RCSTA
      return
;receiving procedure
getrs
      btfss      PIR1,RCIF
      return
      movf      RCREG,W
      return
;sending procedure
sendrs
      movwf      TXREG ; you should test PIR1,TXIF before next send
      return

Good Luck
Marek

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A little history Back in 1997 when I built my first custom computer using the revolutionary Gateway website I didn’t have much to choose from except for the CPU. The race between computer manufacturers was held back by processor manufacturers. They…
Introduction: When experiencing some peculiar problem with the functioning of your PC, how many times has it happened that you look for a solution and even google can’t help? It could be that you are one of the only few people on earth who ma…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now