Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Software UART for PIC16f877a

Status
Not open for further replies.

akhilskb

Newbie level 4
Joined
Apr 20, 2011
Messages
7
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Location
Quilon/Trivandrum,India
Activity points
1,334
I am using two serial communication in a single PIC , so i need a software uart .So, Can anyone post the code for Software Uart in PIC16f877a
 

yes , I am using C compiler. HI-TECH C Complier for pic 10/12/16 version, MCus V9.70PLO.

---------- Post added at 17:44 ---------- Previous post was at 17:43 ----------

can you give me the material
 
By the way, what are each of the two serial ports communicating with? PC and some sort of sensor, modem, etc?
 

well i haven't used Hi-Tech compiler but you can post the code here than we will try to solve it....
 

Attached is a soft UART routine for 16FXXX family. I have tested it and it does function corretly. Coded for a 4MHz OSC, so adjustments must be made for a different OSC frequency. I recommend using the soft UART on the port with the least traffic.
 

Attachments

  • softUART-16F.7z
    1.8 KB · Views: 217
  • softUART-16F.zip
    1.7 KB · Views: 316
Attached is a soft UART routine for 16FXXX family. I have tested it and it does function corretly. Coded for a 4MHz OSC, so adjustments must be made for a different OSC frequency. I recommend using the soft UART on the port with the least traffic.

is this all the code??? Nothing else needed for Software UART sir...?? If i just program this in my PIC16f877a, can i use the 2 pins for my read and write using UART...?? I am going to connect a GSM to these pins through Soft UART..., so only, i am asking...!!!
 
Last edited:

Actually I posted a different version, the complete MPLAB project, with an example app as well on your original thread:


Can i use any other pins for UART in PIC? other than Tx,Rx??

You'll need to change the MCU type in MPLAB.

Set the parameters to match your project's specifications:

Code:
/*	Xtal frequency */
#define	XTAL		4000000

/*	Baud rate	*/
#define	BRATE		4800

/*	Transmit and Receive port bits */
#define	TxData		RA1				/* Map TxData to pin */
#define	RxData		RA2				/* Map RxData to pin */
#define	INIT_PORT	TRISA = 1<<2	/* set up I/O direction */

And I believe that should do it for you. Let me know if you have any other problems.

---------- Post added at 05:05 ---------- Previous post was at 05:02 ----------

By the way, is your GSM a 5v device? If not you'll need a level shifter between the PIC and the GSM, unless you can run your PIC at 3.3v.
 

Gokul,

If i get it right, you are using 16F877 which has a single UART and if you are using TX and RX both pins and you connect a GSM. well... you are done with the UART pins and you cannot use it any further for other devices. You can use multiplexing but than thats a different thing.

One more UART... Bit Bang is the option but than needs a bit of coding.
 

Gokul,

If i get it right, you are using 16F877 which has a single UART and if you are using TX and RX both pins and you connect a GSM. well... you are done with the UART pins and you cannot use it any further for other devices. You can use multiplexing but than thats a different thing.

One more UART... Bit Bang is the option but than needs a bit of coding.

what is that Bit bang??? and, i am using the Tx, Rx pins for interfacing with GPS.., so i need to use some other pins for GSM with a software UART...

---------- Post added at 11:34 ---------- Previous post was at 11:08 ----------

Actually I posted a different version, the complete MPLAB project, with an example app as well on your original thread:


Can i use any other pins for UART in PIC? other than Tx,Rx??

You'll need to change the MCU type in MPLAB.

Set the parameters to match your project's specifications:

Code:
/*	Xtal frequency */
#define	XTAL		4000000

/*	Baud rate	*/
#define	BRATE		4800

/*	Transmit and Receive port bits */
#define	TxData		RA1				/* Map TxData to pin */
#define	RxData		RA2				/* Map RxData to pin */
#define	INIT_PORT	TRISA = 1<<2	/* set up I/O direction */

And I believe that should do it for you. Let me know if you have any other problems.

---------- Post added at 05:05 ---------- Previous post was at 05:02 ----------

By the way, is your GSM a 5v device? If not you'll need a level shifter between the PIC and the GSM, unless you can run your PIC at 3.3v.


Y should i modify like this? is there any reasons?? And, PORTA is a 6 pin port as i am using PIC16f877a... and, i tried to simulate it with Proteus Software., by just loading this program and connecting a virtual terminal to the RB6., RB7 pin, but i couldnt get the output??
 
Last edited:

Y should i modify like this? is there any reasons?? And, PORTA is a 6 pin port as i am using PIC16f877a...

No, you can use any free digital I/O pins you have available on the PIC. However make sure you disable any ADC, Comparator, etc, peripherals you may have using those pins.

The example code is setting the clock frequency as 4MHz and the baud rate to 4800, change appropriately as well as assign the pin you would like to use as TX and RX. The INIT_PORT is just setting digital I/0 direction using the appropriate TRIS register.
 
Hi guru sir.,
i changed the code as u said..., used RA1 and RA2...., and changed the BRATE as 4800 and..., where all it was compared with the old 1200., i changed it as 4800......, i saw in Proteus..., there was some statement written, but, it was scrambled., may be, its not in correct baud rate i hope...., so, pls help me sir....

And, is it that., its TRISA = 1<<7 or 1<<2...???
 
Last edited:

Zip and upload the entire Proteus project with code. I'll take a look at it, most likely just a setting error.
 

here is the proteus design sir.... In the program, u had sent, i had just modified Tx as RA1 and Rx as RA2 as u said... And, BRATE as 4800., and also, wherever i saw 1200., i modified as 4800 sir...
 

Attachments

  • Proteus_soft_UART.zip
    11.9 KB · Views: 143

Ok, I've got it.

It getting late here so I most likely won't get it back to you till tomorrow.

Hi guru sir.,
And, is it that., its TRISA = 1<<7 or 1<<2...???

This is just setting the seventh, "1<<7" or the second, "1<<2" bit of the TRISA to '1', the same as TRISA = 0b01000000; or TRISA = 0b00000010; for the input/output direction.

Ciao
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top