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.

[SOLVED] Serial Communication Between Pic16F877a and PC(Hyperterminal)

Status
Not open for further replies.

E11022

Junior Member level 2
Junior Member level 2
Joined
Feb 28, 2010
Messages
21
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,474
i am connecting PIC16F877a to PC using MAX232 and Rs232, and i wanna view the output in Hyperterminal.
My project is like this, when sensor is triggered, buzzer sounds and Hyperterminal will show help.
Now i wanna figure out how to make my hyperterminal response and display the word. I researched online and found this code to be tested. But there is nothing show in my hyperterminal.
This is the code i used to test my PIC and Hyperterminal but it is not working (Got it online).I connected Pin 2 (RS232) - Pin 14 (MAx232)
Pin 3 (RS232) - Pin 13 (MAX232)
Pin 12 (MAX 232) - Pin 25 (PIC)
Pin 13 (Max232 - Pin 26(PIC)

#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Highspeed Osc > 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=20000000) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=9600, xmit=PIN_C6, invert) //Sets up serial port output pin & baud rate

void main(){
int x = 0;
while(true){
x = x + 1;

//This is an ordinary C language printf statement that will display on the screen of your PC.
//But, you need to open a special program to read serial port input, like HyperTerminal.
//Make sure the baud rate of the program matches this code’s baud rate (9600 bits / second)

printf("hello, x=%d\r\n",x); //send this text to serial port

delay_ms(100); //wait 100 milliseconds
}
}

Can anyone give some advises on it? Thanks
 

For PIC based baord you need to do some more work before to make printf to work... It will not work just like that.....you need to have a init_serial() kind of function and then you need to port Printf function....

Refer the following link where you will get serial port code....
Microchip PIC micros and C - source and sample code


Good Luck
 

Hi milind,
thanks for the link provided.
Actually, i tried the code provided by microchip too, my hyperterminal is still not working with the PIC. i tried loop test before, the serial port is working. I am suspecting it is because of the PC modem itself, when i start up the Hyperterminal, this shown up. The PC i used now is from the lab.
untitled.JPG
 

This is my serial programming code, but it is not working. None of my friend has experience working serial problem. can anyone pin point what is the problem of the code? High appreciate your helps. Thanks.

#include <pic.h>
__CONFIG(0x3F32);

#define sensor RA0
#define sw RA1
#define buzzer RC5
#define led RC4
#define BAUD 9600
#define _XTAL_FREQ 20000000

void uart_transmit(char data);
void uart_string(const char*s);

void uart_transmit(char data){
while (TXIF==0)continue;
TXREG='j';
}
void uart_string(const char*s)
{while(*s)
uart_transmit(*s++);
}

void main (void)
{
ADCON1 = 0x06;
TRISA=0b11111111;
TRISC=0b00000000;
TXSTA=0b00100000;
RCSTA=0b10010000;
SPBRG=265;
SYNC=0;
BRGH=1;
SPEN=1;
TXEN=1;

sensor=0;
sw=0;
buzzer=0;
led=0;

while(1)
{
if ((sensor == 1) && (sw ==0))
{ led=1,buzzer=1;
uart_string("ATD+60125597225");//call
uart_transmit(0x0D);}//enter
else if ((sensor == 0) && (sw ==1))
{ led=0,buzzer=0;}
else {led =0,buzzer =0;}
}
}
 

I don't think there i any problem with your first code, but with your connection. Try connecting pin 25(PIC) to pin 11(MAX232).
 

Please Check your hardware connection between PIC AND max 232. and also check the null modem connection mode (RS232 Cable)
 

Hi guys,
Thanks for all the help. At the end, I managed to make my program work using CCS. :)
 

Hi guys,
Thanks for all the help. At the end, I managed to make my program work using CCS. :)

well i am compiling your program on mplab using ccs compiler but the program is giving error... ... is it a full code or there is something missing in it... i am new in serial communication and am not getting any progress in it .. i was hoping that your code will work but its giving error so kindly if u give me a program of a serial communication so it will be very greatfull
thanks in advance
 

I follow you code but same having problem with hyperterminal . It dont display any thing . I check my max232(11) to pic(RC6) & max232(12) to pic(RC7) . Do u solve the prob?


This is my serial programming code, but it is not working. None of my friend has experience working serial problem. can anyone pin point what is the problem of the code? High appreciate your helps. Thanks.

#include <pic.h>
__CONFIG(0x3F32);

#define sensor RA0
#define sw RA1
#define buzzer RC5
#define led RC4
#define BAUD 9600
#define _XTAL_FREQ 20000000

void uart_transmit(char data);
void uart_string(const char*s);

void uart_transmit(char data){
while (TXIF==0)continue;
TXREG='j';
}
void uart_string(const char*s)
{while(*s)
uart_transmit(*s++);
}

void main (void)
{
ADCON1 = 0x06;
TRISA=0b11111111;
TRISC=0b00000000;
TXSTA=0b00100000;
RCSTA=0b10010000;
SPBRG=265;
SYNC=0;
BRGH=1;
SPEN=1;
TXEN=1;

sensor=0;
sw=0;
buzzer=0;
led=0;

while(1)
{
if ((sensor == 1) && (sw ==0))
{ led=1,buzzer=1;
uart_string("ATD+60125597225");//call
uart_transmit(0x0D);}//enter
else if ((sensor == 0) && (sw ==1))
{ led=0,buzzer=0;}
else {led =0,buzzer =0;}
}
}
 

well i am compiling your program on mplab using ccs compiler but the program is giving error... ... is it a full code or there is something missing in it... i am new in serial communication and am not getting any progress in it .. i was hoping that your code will work but its giving error so kindly if u give me a program of a serial communication so it will be very greatfull
thanks in advance

Hi there,
the code that i put here was not working.
You can try this code, you should be able to see "help" being displayed in Hyperterminal. If it is still not working in your case, that means you need to check your connections. Hope this will help you :)

#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,NOBROWNOUT
#use delay(clock = 20000000)
#use RS232(baud = 9600, xmit = PIN_C6, rcv = PIN_C7)

void main ()
{

while(1)
{
delay_ms(10);
puts("help");
set_tris_b(0x00);
output_b(0xFF);
}
}

---------- Post added at 16:07 ---------- Previous post was at 16:04 ----------

Please see my reply to faisalengr. Good luck :)
 
Can any tell me where i'm wrg cnt communicate with hyperterminal. My logic is like this. when user press A,B,C,D . It will turn on/off the led in the mean time it send to the user which led is on/off. Is the setting correct ?

#include<pic.h>
#include"usart.h"
#define PIC_CLK == 20000000 //be sure to include this argument;this argument is inside delay.h
#include"delay.h"

__CONFIG(0x3F32); //chip setting
#define Laser RB0
#define Smoke RB1
#define LED1 RB6
#define LED2 RB7
#define buzzer RB2
#define sw1 RB3
#define sw2 RB4
#define RX_PIN TRISC7
#define TX_PIN TRISC6

//------function prototype-------//
void delayS(int sec);
void delaymS(int msec);

//----global variable---------//



//------main program-------//
void main()
{
int flag;
TRISB=0b00000011;
TRISC=0b11000000;
TXSTA=0b00100100;
RCSTA=0b10010000;
RX_PIN=1;
TX_PIN=1;

LED1=0;
LED2=0;
buzzer=0;

//initialize the USART
USARTInit();

while(1)
{
char data;
data=USARTReadByte();
//checking if the sw1 is pressed
if(((Laser==1)&&(sw1==0))||data=='A')
{
LED1=1;
USARTWriteByte('a');
}
if(((Laser==0)&&(sw1==1))||data=='B')
{
LED1=0;
USARTWriteByte('b');
}
if(((Smoke==1)&&(sw2==0))||data=='C')
{
LED2=1;
USARTWriteByte('c');
}
if(((Smoke==0)&&(sw2==1))||data=='D')
{
LED2=0;
USARTWriteByte('d');
}
if(LED1==1 || LED2==1)
{
buzzer=1;
}
else
{
buzzer=0;
}
}
}
 

Attachments

  • usart.rar
    666 bytes · Views: 132

Forgot to mention , i'm using Hi-tech compiller

I will try my code in hyperterminal if works then only move to vb interface so does the coding suit in both GUI software?
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top