Solved

Interfacing RS232 to PIC16f877

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 and AMD Radeon HD4600 - Display not filling entire screen. 12 117
UPS Power design 11 73
i7s vs i7 core 3 134
iPhone 6S - ios10 - Text Messaging sounds 2 73
Introduction: When a connection to the internet is established, there always exists a modem between the connected device and the ISP (Internet Service Provider). The Operating System (OS) on your PC controls the modem which communicates with the …
On Beyond Tools A conversation I recently had with the DevOps manager of a major online retailer really made me think about DevOps monitoring tools (https://www.onpage.com/devops-incident-management-tool/). The manager and I discussed how sever…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

778 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