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.

PIC C codes for communicating 16f877 and Rs232

Status
Not open for further replies.

HYBRITECH

Newbie level 3
Joined
Nov 20, 2006
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,307
hi my friend i am new in your board....

And i need some samples about communicating pic 16f877 and rs232

has any body have pic c codes about this issue?

thank you in advance
 

uart example 16f877

i need some samples about communicating pic 16f877 and rs232
PIC16F877 is a processor, and RS232 is a interface technique/communication protocol, they can't communicating each other.

PIC6F877 can communicating with PC via RS232 interface line, say PIC16F877 send ADC value to PC an the value displayed on Windows Secreen
 

pic plc 16f877

you missunderstood my friend....:(

for example i setup the harware like this

rs232----->max232-------->16f877
now i want that....

in hyperterminal or visual basic when i push 1 in keyboard the led in Port d,0 will flash.
and how can i understand from hyperterminal which led is flashing?
 

microchip serial communication rs232 16f877

I suppose you can find some code example on microchip website or searching on web.
If you need c code you can find libraries for serial communcation on any compiler.


Bye
 

Re: 16f877 Rs232 help?

Hi,
Please clarify some doubts for properly understanding ur problem. Hav u connected MAX to UART module of PIC or any general Purpose I/Os ? Are u new using PIC uC?
Thanks.
 

Re: 16f877 Rs232 help?

Do u need the RS232 communication code.
 

Re: 16f877 Rs232 help?

yes i need some code to start :)
 

Re: 16f877 Rs232 help?

You can refer to microchip website.
www.microchip.com

They have sample code for Serial communication.
Search for "USART Serial communication PIC16F877"

The best thing to do is to refer to the datasheet PIC16F877a,
under the topic USART.
They have list down the steps to do (initialisation),
before you can start using it for serial communication.

Some reference:

http://techref.massmind.org/techref/microchip/rs232.htm
**broken link removed**
 

Re: 16f877 Rs232 help?

can U guys share the codes to me as well. I need that for my program also.

Many thanks!!!
 

Re: 16f877 Rs232 help?

Try this code, I'm using 16f877.
 

Re: 16f877 Rs232 help?

for this kind of situation, u have to determine what software vthat u want to use..te concept is that you are using PIC as a brain and the rs232 as a communication between the PIC and the computer..If u are using a VB...u can try to draw thw GUI and for the communicaion part...u can take a look at the sample inside the microchip website which is www.microchip.com the code is simple and it is a basic language..k bro...gud luck
 
Last edited by a moderator:
  • Like
Reactions: noel_t

    noel_t

    Points: 2
    Helpful Answer Positive Rating
Re: 16f877 Rs232 help?

Try this!!
 

Re: 16f877 Rs232 help?

This is an example about receiving data from another equipment by UART (RS232: 9600bps, 1 stop bit, 8 bit data, no parity), if you want to transmit data to another you can use "Printf("");"
#include <16f877.h>
//#fuses HS,WDT
#use fixed_io(d_outputs=PIN_D2, PIN_D3, PIN_D4, PIN_D5)
#use delay(clock=20000000) //one instruction=0.2us
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
unsigned char a[11] = {0x12,0xb7,0x19,0x91,0xb4,0xd0,0x50,0x97,0x10,0x90,0xff};
unsigned char TL1,TL2,TL3,TL4,TL5,TL6,TL7;
unsigned char CNT1,CNT2,CNT3,CNT4,CNT5;
unsigned char ERR1,ERR2,ERR11,ERR12;
unsigned char r[16];
unsigned char HANDS;
unsigned char POS;
unsigned char PTR;
//++++++++++++++++++++++quet led+++++++++++++++++++++++++++++
void QL()
{
OUTPUT_A(0xff);
output_high(PIN_C0);
output_high(PIN_C1);
output_high(PIN_C2);
output_high(PIN_C3);
output_high(PIN_C4);
output_high(PIN_C5);
output_high(PIN_D2);
output_high(PIN_D3);
output_high(PIN_D4);
output_high(PIN_D5); // off all LED
switch(POS)
{
case 0: {OUTPUT_B(a[TL6]); output_low(PIN_A0); break;}
case 1: {OUTPUT_B(a[TL5]); output_low(PIN_B4); output_low(PIN_A1); break;} // DOAN NAY SU THEM NGAY,B4: POINT
case 2: {OUTPUT_B(a[TL4]); output_low(PIN_A2); break;}
case 3: {OUTPUT_B(a[TL3]); output_low(PIN_A3); break;}
case 4: {OUTPUT_B(a[TL2]); output_low(PIN_A4); break;}
case 5: {OUTPUT_B(a[TL1]); output_low(PIN_A5); break;}
case 6: {OUTPUT_B(a[TL7]); output_low(PIN_C0); break;}
case 7: {OUTPUT_B(a[CNT5]); output_low(PIN_C1); break;}
case 8: {OUTPUT_B(a[CNT4]); output_low(PIN_C2); break;}
case 9: {OUTPUT_B(a[CNT3]); output_low(PIN_C3); break;}
case 10: {OUTPUT_B(a[ERR11]); output_low(PIN_C4); break;}
case 11: {OUTPUT_B(a[ERR12]); output_low(PIN_C5); break;}
case 12: {OUTPUT_B(a[ERR1]); output_low(PIN_D2); break;}
case 13: {OUTPUT_B(a[ERR2]); output_low(PIN_D3); break;}
case 14: {OUTPUT_B(a[CNT1]); output_low(PIN_D4); break;}
case 15: {OUTPUT_B(a[CNT2]); output_low(PIN_D5); break;}
}
POS++;
POS = POS%16;
}
void main() {
unsigned char Rec;
POS = 0;
HANDS = 0;
PTR = 0;
//-------------------------------------
TL1 = 1;
TL2 = 2;
TL3 = 3;
TL4 = 4;
TL5 = 5;
TL6 = 6;
TL7 = 7;
CNT1 = 0;
CNT2 = 1;
CNT3 = 2;
CNT4 = 3;
CNT5 = 4;
ERR1 = 1;
ERR2 = 2;
ERR11 = 3;
ERR12 = 4;
while(TRUE)
{
QL();// quet led
//----------------Kiem tra tin hieu tu PLC-------------
SET_TRIS_D( 0xc0 );// D6 and D7 is input
if(!input(PIN_D6)) // co tin hieu truyen tu PLC
output_low(PIN_E0); // cho phep nhan du lieu tu PLC
else
{
output_high(PIN_E0); // cho phep truyen tu dau can --> PLC
//day la doan chuong trinh viet them ngay 9-8-2006
HANDS = 0x0; // ko cho phep nhap chuoi tu PLC
}
//=====================================================
if (kbhit())
{
Rec = getc();
if ((PTR < 16)&&(HANDS == 0xff))
{
r[PTR] = Rec;
PTR++;
}
else
if ((HANDS != 0xff) && (Rec == 0x2))
{
HANDS = 0xff;
PTR = 0;
}
}
if (PTR == 16)
{
TL1 = r[0]&0xf;
TL2 = r[1]&0xf;
TL3 = r[2]&0xf;
TL4 = r[3]&0xf;
TL5 = r[4]&0xf;
TL6 = r[5]&0xf;
TL7 = r[6]&0xf;
if (TL1==0)
{
TL1 = 10;
if (TL2 == 0)
{
TL2 = 10;
if (TL3 == 0)
{
TL3 = 10;
if (TL4 == 0)
{
TL4 = 10;
}
}
}
}
//----------------------
CNT1 = r[7]&0xf;
CNT2 = r[8]&0xf;
CNT3 = r[9]&0xf;
CNT4 = r[10]&0xf;
CNT5 = r[11]&0xf;
if (CNT1 == 0)
{
CNT1 = 10;
if (CNT2 == 0)
{
CNT2 = 10;
if (CNT3 == 0)
{
CNT3 = 10;
if (CNT4 == 0) CNT4 = 10;
}
}
}
//----------------------
ERR1 = r[12]&0xf;
ERR2 = r[13]&0xf;
//----------------------
ERR11 = r[14]&0xf;
ERR12 = r[15]&0xf;
//----------------------
PTR = 0;
HANDS = 0;
}
delay_us(100);
}
}
 

Re: 16f877 Rs232 help?

hi can any body send code for serial communication of PIC16f877 to PIC16f877 in proton using serial intrrupt. I am intertested in intrrupt because of the controller will be busy in processing of other large rourtines.
regards
 
  • Like
Reactions: noel_t

    noel_t

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top