?
Solved

Interfacing RS232 to PIC16f877

Posted on 2003-12-09
6
Medium Priority
?
6,225 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
4 Comments
 

Accepted Solution

by:
Thorn01 earned 672 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 664 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 664 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Hello It is a very old trick to use a ram disk in order to boost PC performances, in the past, when in home environments the fastest common devices were floppy disks a part of the very small ram memory available was used to create a virtual hard …
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

809 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