Solved

Interfacing RS232 to PIC16f877

Posted on 2003-12-09
6
6,216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Memory (not to be confused with Hard Drive Space) can greatly increase the performance of a computer. Each version of Window has greater demands on memory. My personal recommendation to get decent performance out of a machine is as follows: Windows…
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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