• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to setup hyperterminal for serial communication

Status
Not open for further replies.

fan174

Member
I have connected PIC16F877a to PC using usb to rs232 cable , and i wanna view the output in Hyperterminal.

Pic16f877a
IDE Xc8

Code:
void main()
{ 
TRISC6=0;                    //Configure RC6/TX Pin as Output
RC6=0;
unsigned char a;
unsigned char msg[]=" ELECTRONICS  ";    //To Send the Data Serial                  
TXSTA=0x24;                    //Set Transmit Enable Bit and High Speed Baudrate in Asynchronous Mode           
SPBRG=0x81;                    //Load the Value of Baud Rate Generator Register                              
TXEN=1;                        //Set Transmit Enable Bit                                                      
SPEN=1;                        //Set Serial Port Enable Bit                                                  
while(1)
    {
        for(a=0;a<26;a++)
        {
        while(TXIF==0);                //RC6 Connect to Rx Pin of Serial Port//
        TXREG=msg[a];
        RC7=TXREG;
        }
    }
}
I think I am using wrong software
 

Attachments

Pommie

Well-Known Member
Most Helpful Member
From the manual,
Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be
set in order to configure pins RC6/TX/CK and RC7/RX/DT
as the Universal Synchronous Asynchronous Receiver
Transmitter.
You are setting TRISC6 to zero (output).

Mike.
Edit, what is the oscillator speed?
 

rjenkinsgb

Well-Known Member
Most Helpful Member
Use Putty or another terminal program _instead_ of hyperterm.
(I like Realterm: https://sourceforge.net/projects/realterm/ )

Check the terminal and port are working by linking pins 2 & 3 on the PC serial port. Whatever you type should be echoed back while the pins are linked.

Set the port speed parameter (baud rate) in the terminal program to whatever speed you used in the PIC baud rate calculation (and apply or restart the port if required in the program).

Connect the PIC ground to pin 5 of the PC port (assuming it's a 9 pin one) and the serial out from the PIC to pin 2.
(or 7 & 3 respectively for a 25 pin port).

There is no absolute guarantee it will work without a proper RS232 line driver between the PIC pin and the PC port; RS232 is supposed to work on +/- 12V levels...
Most ports will work with 0V & 5V levels but no guarantees - and the signal polarity is opposite, as the driver and receiver ICs are inverting devices..

You'll probably have to invert the level out of the TX pin on the PIC if you are not using an RS232 driver.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Its also declared unsigned char, and its actually a char string.
The XC8 compiler is just C so "unsigned char msg[]; " is fine... I also just use char msg[] but I should know better..
 

Cicero

Active Member
The XC8 compiler is just C so "unsigned char msg[]; " is fine... I also just use char msg[] but I should know better..
Ah fair enough, I was being rather pedantic there :). Just thought he could avoid a possible compile warning for differing signedness if trying to print that or similar.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
For completeness.. I wish that all compliers were the same... If I write char it would be assumed I want signed!! but several compilers ( SDCC is one ) that would like you to specify signed... Or they make it unsigned... I had one occasion the other day ( using the arduino ide ) that even though I specified unsigned int, the result would always be small enough to be an unsigned char!!! This is because I had a constant in the equation... I had to specify volatile unsigned int!!!
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top