Solved

Interfacing RS232 to PIC16f877

Posted on 2003-12-09
6
6,203 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
System overheating may become a serious problem if not taken care of at the proper time. I am writing this article because I faced a similar problem. Intro All electronic devices produce heat, but computers are a special case - the processors bo…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

20 Experts available now in Live!

Get 1:1 Help Now