---
+ Post New Thread
Results 1 to 14 of 14
  1. #1
    Junior Member level 2
    Points: 633, Level: 5

    Join Date
    Feb 2010
    Posts
    21
    Helped
    1 / 1
    Points
    633
    Level
    5

    Serial Communication Between Pic16F877a and PC(Hyperterminal)

    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

  2. #2
    Advanced Member level 3
    Points: 6,883, Level: 19
    milind.a.kulkarni's Avatar
    Join Date
    Oct 2011
    Location
    Bangalore
    Posts
    922
    Helped
    209 / 209
    Points
    6,883
    Level
    19
    Blog Entries
    1

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    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
    Hope the post will be helpful to you....
    "Sharing is the best way of Learning"



    •   Alt9th December 2011, 13:31

      advertising

        
       

  3. #3
    Junior Member level 2
    Points: 633, Level: 5

    Join Date
    Feb 2010
    Posts
    21
    Helped
    1 / 1
    Points
    633
    Level
    5

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    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



  4. #4
    Junior Member level 2
    Points: 633, Level: 5

    Join Date
    Feb 2010
    Posts
    21
    Helped
    1 / 1
    Points
    633
    Level
    5

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    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;}
    }
    }



  5. #5
    Newbie level 4
    Points: 958, Level: 7

    Join Date
    Apr 2009
    Posts
    6
    Helped
    1 / 1
    Points
    958
    Level
    7

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    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).



    •   Alt14th December 2011, 12:50

      advertising

        
       

  6. #6
    Full Member level 3
    Points: 1,609, Level: 9
    sreepss's Avatar
    Join Date
    Jun 2009
    Location
    Cochin, Kerala, India
    Posts
    166
    Helped
    26 / 26
    Points
    1,609
    Level
    9

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

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



    •   Alt14th December 2011, 13:05

      advertising

        
       

  7. #7
    Junior Member level 2
    Points: 633, Level: 5

    Join Date
    Feb 2010
    Posts
    21
    Helped
    1 / 1
    Points
    633
    Level
    5

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

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



  8. #8
    Junior Member level 3
    Points: 686, Level: 5

    Join Date
    Mar 2010
    Location
    pakistan
    Posts
    26
    Helped
    0 / 0
    Points
    686
    Level
    5

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    Quote Originally Posted by E11022 View Post
    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



  9. #9
    Newbie level 3
    Points: 428, Level: 4

    Join Date
    Aug 2010
    Location
    Malaysia
    Posts
    4
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    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?


    Quote Originally Posted by E11022 View Post
    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;}
    }
    }



  10. #10
    Junior Member level 2
    Points: 633, Level: 5

    Join Date
    Feb 2010
    Posts
    21
    Helped
    1 / 1
    Points
    633
    Level
    5

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    Quote Originally Posted by faisalengr View Post
    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 :)


    1 members found this post helpful.

  11. #11
    Newbie level 3
    Points: 428, Level: 4

    Join Date
    Aug 2010
    Location
    Malaysia
    Posts
    4
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    btw, the hyperterminal default BRGH is high/low?



  12. #12
    Junior Member level 2
    Points: 633, Level: 5

    Join Date
    Feb 2010
    Posts
    21
    Helped
    1 / 1
    Points
    633
    Level
    5

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    Quote Originally Posted by alexyee View Post
    btw, the hyperterminal default BRGH is high/low?
    It depends on your coding.



  13. #13
    Newbie level 3
    Points: 428, Level: 4

    Join Date
    Aug 2010
    Location
    Malaysia
    Posts
    4
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    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;
    }
    }
    }



  14. #14
    Newbie level 3
    Points: 428, Level: 4

    Join Date
    Aug 2010
    Location
    Malaysia
    Posts
    4
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: Serial Communication Between Pic16F877a and PC(Hyperterminal)

    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 by alexyee; 10th February 2012 at 17:25.



+ Post New Thread
Please login