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.

Need code for Serial comm using PIC16f877

Status
Not open for further replies.

ganavel9783

Member level 1
Member level 1
Joined
Sep 6, 2005
Messages
38
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,257
16f877a.h download

hi every1..i'm trying to set up a serial comm using pic16f877.i would like to know if any has a C or assembly code to send characters typed in PC echoed back form PIC using hyperterminal.I'm using PICC C compiler.thanks..
 

pic16f877a serial communication

Hi ganavel9783'

You can find sample code (for PICC Compiler)
on https://www.microchipc.com

and the Serial port example at **broken link removed**

Regards
 
pic16f877 serial

i have on MPLAB assembler,but need more data.
I use VBasic and COMM Rs232.
Call me at my Email.
good luck!
 

terminal v1.9b

nah... this is my code... as i am quite free today

if any mistake please do tell me...
Code:
//author: sp
//date: 07/01/2006
//function: use PC to send 4 character to PIC and when the 4 character is detected as "ABCD" (ASCII), it echo back.
//			 : the "ABCD" sequence have to be correct or it will not echo back to PC.

#include <16F877A.h>
#fuses HS, NOWDT, NOPUT, NODEBUG, NOLVP, NOBROWNOUT, NOCPD, NOPROTECT, NOWRT
#use delay(clock = 20000000)

#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#INT_RDA              //RS232 receive data available
void isr_rs232(){
   int A_char, B_char, C_char, D_char;
   int protocol;  // use as a dummy to make sure the sequence of character received is correct.
   
   A_char = getc();
   if (A_char == 'A'){
      protocol = 1;
   }
   if (protocol == 1){
      B_char = getc();
      if (B_char == '3'){
         protocol = 2;
      }
   }
   if (protocol == 2){
      C_char = getc();
      if (C_char == 'C'){
         protocol = 3;
      }
   }
   if (protocol == 3){
      D_char = getc();
      if (D_char == 'D'){
         protocol = 4;
      }
   }
   if (protocol == 4){
   		putc(A_char); putc(B_char); putc(C_char); putc(D_char);	//echo back the character u send to your PIC
	}
   protocol = 0; //clear the dummy for further use.
}

void main(){
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);
   while(1){
   		;	//do nothing and wait for rs232 interrupt
	}
}

please dont use hyperterminal... use "Terminal v1.9b" or higher version... it is about 10,000 times better than hyper terminal...

please make sure u set the correct baud rate... and the RX n TX pin on your 877A is the same in the code...

warm regards,
sp
 
16f877a.h

quote="Ahmad Abbas"]Hi ganavel9783'

You can find sample code (for PICC Compiler)
on https://www.microchipc.com

and the Serial port example at **broken link removed**

Regards[/quote]

--> hi every1 i tried da link provided by Ahmad Abbas n used the available hex file in the zipped file for serial communication. the readme text mention to place a PIC16f876 on bread board to test the serial connection. but when i tried to program the hex file into my PIC16f877 using a JDM programmer an error sign showed displaying, "verify failed at address 0000h".is it bcoz of the diff PIC that i'm using or is it bcoz of my programmer?

Thanks sp for providing me a sample code.i'll try da link given by Ahmad Abbas first.Later i'll try ur code n let u know if there is ne problem.thnks in advance.
 
Last edited by a moderator:

serial communication in pic16f87x using mplab

Hi ganavel9783'

Your problem may have several reasons.
So

First check that your PIC is working ( program it again with a simple tested before program).

Second compile the C program with PICC (it is better to compile it with your specification than using the HEX file).

Third program your PIC with your HEX file and check that the code protection is off.

Regards,
A.Abbas
 
bray terminal v1.9

i think the problem would b quite obvious... the hex file is for 876.... 877 cannot b used.... even if sometimes it works... it might act weird (i tried wth 877A wth 628A...)

start a project... start wth simple one b4 u go to more complicated one... so debugging prob would b much easier...

ya ya... get this fantastic rs232 prog (a tiny and very easy/convenient to use) Terminal v1.9b here

Code:
http://bray.velenje.cx/avr/terminal

regards,
sp
 
serial communication pic16f877

hi sp..

i tried to compile the code u provided in MPlab wit PICC lite but da first error was:

Error[141] D:\Project32\Serial2.c 6 : can't open include file "16f877a.h": No such file or directory

i later changed the header file form "16f877.h " to "pic.h". i recompiled n got the following errors...

Error[107] D:\Project32\Serial2.c 7 : illegal # directive "fuses"
Error[107] D:\Project32\Serial2.c 8 : illegal # directive "use"
Error[107] D:\Project32\Serial2.c 10 : illegal # directive "use"
Error[107] D:\Project32\Serial2.c 12 : illegal # directive "INT_RDA"..

how 2 debug these errors?

i even tried da link provided by Ahmad Abbas. I included serial.h & serial.c to compile but still getting errors as below:

Advisory[1209] : An old MPLAB tool suite plug-in was detected. Some options may not work correctly
Advisory[1210] : Visit www.htsoft.com or contact support@htsoft.com for an update
Error[103] C:\Documents and Settings\End User\Desktop\PIC serial\PIC serial using PICC Lite\delay.h 69 : #error: please define pic_clk correctly
Error[103] C:\Documents and Settings\End User\Desktop\PIC serial\PIC serial using PICC Lite\delay.h 97 : #error: please define pic_clk correctly
Halting build on first failure as requested.

what is the problem?ne other code to set up serial comm in PIC16f877?

need help...
 

pic16f87x.h download hi-tech

are u using the CCS C for PIC?.... if u are using CCS C... do u hav the full version?...

using MPLAB.. u hav to hav the full version of CCS compiler as well... then u hav to download the plug-in to use the MPLAB IDE wth CCS C compiler...

the error u get for
Code:
Error[141] D:\Project32\Serial2.c 6 : can't open include file "16f877a.h": No such file or directory
is quite obvious tht u do not own the full version of CCS C...

once u change the device... u hav to look for the valid fuses tht support for tht device...

i nvr c this "pic.h" before.... i doubt tht u are using CCS C...

please provide more information as i can successfully compile the code...

regards,
sp
 

mplab error 141

hi sp n every1..

firstly i'm sorry coz i was using PICC Lite C compiler by Hitech C.so when i tried to compile da code porvided by sp,it was showing some errors.

2day i tried da code on CCS compiler n it was compiled sucessfully!
i even programmed da hex code using da JDM programmer n there was no problem.

BUT when i tried to connect my circuit to PC there was no characters displayed on Hyperterminal. i even tried Terminal v1.9b but still no characters was displayed.

-->>Where is the mistake???

here is my settings for hyperterminal & Terminal v1.9 b:

Bits per second: 19200
Data bits: 8
Parity: None
Stop bits: 1
Flow control: None

Attached is the circuit i'm using for da serial comm but i'm using 16.00Mhz Osc instead of the 4.00Mhz Osc shown in the attachement.
 

pic16f877 serial communication

then u hav to change the CCS C code i did for this line...

Code:
#use delay(clock = 20000000)

change to

Code:
#use delay(clock = 16000000)

it is quite clear here... u should understand y i change this... if u dont study the CCS manual properly..


regards,
sp
 

+pic16f877 +rs232 +assembler

Hello all,

I need the DC-ROM for the book " EMBEDDED C PROGRAMMING AND THE MICROCHIP PIC".

I wound be glag if any one can help me. I´ll pay for the postage.

Thanks in advance,

RICKYLO
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top