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.

Rubbish values problem im hyperterminal

Status
Not open for further replies.

oday_albadarneh

Newbie level 6
Newbie level 6
Joined
Dec 20, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,380
Hi all
I have a project connecting pic16f878a to the pc
i programmed it using mikroc. When testing serial communication virtually i recieved the data correctly. But when I test my hardware i recive rubbish letters on hyperterminal.
May anyone help me with that problem ?!!
I should submit my project after 18 hours, i stucked here !!
 

Have you checked whether the baud rates for the both are same?
Is there is any Software invert in the PIC or the PC?
Did you try the loop test to check the cable?

I have had some problems like this but it was mostly due to some incorrect software settings.

I hope you have time to try all of these out!!
 

What is the devices oscillator frequency?

What BAUD rate are you attempting to utilize?

Not all BAUD rates are viable for a give oscillator frequency.

BigDog
 

Have you checked whether the baud rates for the both are same?
Is there is any Software invert in the PIC or the PC?
Did you try the loop test to check the cable?

I have had some problems like this but it was mostly due to some incorrect software settings.

I hope you have time to try all of these out!!

Yes dear, I used 9600 bps as a baud rate on the two sides
I don't know what is the software you talk about "Invert" ?!!!
I don't know how to make a loop on the cable

- - - Updated - - -

What is the devices oscillator frequency?

What BAUD rate are you attempting to utilize?

Not all BAUD rates are viable for a give oscillator frequency.

BigDog

I used 4Mhz crystal to get 9600 bps baud rate !!
if there any problem how to fix it ?!
 

Software invert is when you have set the PIC to send the data in inverted mode, i.e. 0 and 1 instead of 1 and 0. Even the PC can receive in inverted mode. Because of this there is a possibility of seeing junk values. The compiler's function for serial transmission will have options to set this,

To do a loop back test, connect the serial cable to the PC, start hyper-terminal, short the transmit and receive pins on the free end of the serial cable. So whan you input anything in Hyper-terminal, it would go through the cable and come back and will be displayed in the screen. Just Search "Serial Cable Loop Back Test" for more details.
 
really i did the loop test now.. the cable is working
but i still have the problem, i didn't chose any option to send the data in inverted mode - note that i get the data correctly virtually -
I stuck here, no time to think :(
 

which controller you are using. can you give me your c code?
Are you sending ASCII format or direct decimal?
 

i'm using pic16f877a and the source code in mikroC

Code:
// variables
float vc1,vc2,vc3,beta;
char vc1_txt[15],vc2_txt[15],vc3_txt[15],beta_txt[15],adder_txt[15],subber_txt[15];
int check;
char uart_rd,adder,lock,add1,add2,subber,receive;

 void calculate_beta ()
{
    beta = ((5 - vc1)* 1000000) / ((5-.7)*3700 ) ;
    FloatToStr(beta,beta_txt);
    UART1_Write_Text("Beta = ");
    UART1_Write_Text(beta_txt);
    Uart1_Write(13);
    Uart1_Write(10);
    Delay_ms (2000);
}

 void Calculate_vc1()
 {
    vc1 = ADC_Read(0);
    vc1 = 0.004887585533*vc1;
    FloatToStr(vc1,vc1_txt);
    if (vc1 <= 0.2 )
         UART1_Write_Text("Saturated");
    else if (vc1 > 0.2 && vc1 < 4.85 )
         UART1_Write_Text("Forward");
    else if (vc1 > 4.85)
         UART1_Write_Text("Cut-Off");

    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);
 }

void Calculate_vc2()
 {
    vc2 = ADC_Read(1);
    vc2 = 0.004887585533*vc2;
    FloatToStr(vc2,vc2_txt);
    if (vc2 <= 0.2 )
         UART1_Write_Text("Saturated");
    else if (vc2 > 0.2 && vc2 < 4.85 )
         UART1_Write_Text("Forward");
    else if (vc2 > 4.85)
         UART1_Write_Text("Cut-Off");

    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);
 }

void Calculate_vc3()
 {
    vc3 = ADC_Read(2);
    vc3 = 0.004887585533*vc3;
    FloatToStr(vc3,vc3_txt);
    if (vc3 <= 0.2 )
         UART1_Write_Text("Saturated");
    else if (vc3 > 0.2 && vc3 < 4.85 )
         UART1_Write_Text("Forward");
    else if (vc3 > 4.85)
         UART1_Write_Text("Cut-Off");

    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);

 }


 void lock_check ()
 {
     PORTD = lock & 0x0F ;
     delay_ms (1500) ;
     check = PORTD.F4 ;
     if (check == 1)
         UART1_Write_Text("NO GO");
     else if (check == 0)
         UART1_Write_Text("GO");
    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);
  }


 void full_adder (char a , char b)
 {
   PORTB = ( a & 0x0F )+ ( b & 0xF0 );
   adder = PORTC ;
   adder = adder & 0x1F;
   ByteToStr(adder,adder_txt);
   Uart1_Write_Text(adder_txt);
   Uart1_Write(13);
   Uart1_Write(10);
   delay_ms (2000);
 
 }


void full_subber (char c , char d)
 {
   PORTB = ( c & 0x0F )+ ( d & 0xF0 );
   subber = PORTC ;
   subber = subber & 0x1F;
   ByteToStr(subber,subber_txt);
   Uart1_Write_Text(subber_txt);
   Uart1_Write(13);
   Uart1_Write(10);
   delay_ms (2000);

 }

void main() {

     ADRESL = 0x0F;
     ADRESH = 0;
     TRISA  = 0xFF;
     TRISB  = 0;
     TRISC  = 0x1F;
     //TRISD  = 0xF0;
     
     UART1_Init(9600);               // Initialize UART module at 9600 bps
     Delay_ms(100);                  // Wait for UART module to stabilize

     UART1_Write_Text("Start\r\n");
     add1 = 0b00001111;
     add2 = 0b10101111;
    while (1) {
      do {
            if (UART1_Data_Ready())
            lock = UART1_Read();
            calculate_beta();
            Delay_ms(500);
            Calculate_vc1();
            Delay_ms(500);
            Calculate_vc2();
            Delay_ms(500);
            Calculate_vc3();
            Delay_ms(500);
            lock_check();
            Delay_ms(500);
            full_adder (add1 , add2);
            Delay_ms(500);
            full_subber (add1 , add2);
            Delay_ms(500);
      }
      while(1);
    }

i cant read or write data and sometimes i read a rubbish data on the hyper terminal like this image
View attachment 12.bmp

- - - Updated - - -

Please anyone can fix the problem ?!!!
I have just several hours to fix i'll fail :'(
 

It has been more than six months since I saw this problem in my setup, so I don't remember much. I used CCS C. It is usually a software error, where the settings of the PIC and the PC do not match.
Try this :
Program the PIC to send a particular character every 2 seconds or so.
See what the hyper-terminal receives.
Compare the binary of what you sent to what you received on the PC, check if they are complementary.
Use this table : https://www.roubaixinteractive.com/PlayGround/Binary_Conversion/The_Characters.asp

If they are complementary there is an invert enabled in your PIC. Check your manual for the serial_init function and see if any other settings are involved for it.

Another option is to use a higher MCU frequency. Try with the highest possible.

I hope it works.
 

Try this code

Code:
// variables
float vc1,vc2,vc3,beta;
char vc1_txt[15],vc2_txt[15],vc3_txt[15],beta_txt[15],adder_txt[15],subber_txt[15];
int check;
char uart_rd,adder,lock,add1,add2,subber,receive;

 void calculate_beta ()
{
    beta = ((5 - vc1)* 1000000) / ((5-.7)*3700 ) ;
    FloatToStr(beta,beta_txt);
    UART1_Write_Text("Beta = ");
    UART1_Write_Text(beta_txt);
    Uart1_Write(13);
    Uart1_Write(10);
    Delay_ms (2000);
}

 void Calculate_vc1()
 {
    vc1 = ADC_Read(0);
    vc1 = 0.004887585533*vc1;
    FloatToStr(vc1,vc1_txt);
    if (vc1 <= 0.2 )
         UART1_Write_Text("Saturated");
    else if (vc1 > 0.2 && vc1 < 4.85 )
         UART1_Write_Text("Forward");
    else if (vc1 > 4.85)
         UART1_Write_Text("Cut-Off");

    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);
 }

void Calculate_vc2()
 {
    vc2 = ADC_Read(1);
    vc2 = 0.004887585533*vc2;
    FloatToStr(vc2,vc2_txt);
    if (vc2 <= 0.2 )
         UART1_Write_Text("Saturated");
    else if (vc2 > 0.2 && vc2 < 4.85 )
         UART1_Write_Text("Forward");
    else if (vc2 > 4.85)
         UART1_Write_Text("Cut-Off");

    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);
 }

void Calculate_vc3()
 {
    vc3 = ADC_Read(2);
    vc3 = 0.004887585533*vc3;
    FloatToStr(vc3,vc3_txt);
    if (vc3 <= 0.2 )
         UART1_Write_Text("Saturated");
    else if (vc3 > 0.2 && vc3 < 4.85 )
         UART1_Write_Text("Forward");
    else if (vc3 > 4.85)
         UART1_Write_Text("Cut-Off");

    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);

 }


 void lock_check ()
 {
     PORTD = lock & 0x0F ;
     delay_ms (1500) ;
     check = PORTD.F4 ;
     if (check == 1)
         UART1_Write_Text("NO GO");
     else if (check == 0)
         UART1_Write_Text("GO");
    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);
  }


 void full_adder (char a , char b)
 {
   PORTB = ( a & 0x0F )+ ( b & 0xF0 );
   adder = PORTC ;
   adder = adder & 0x1F;
   ByteToStr(adder,adder_txt);
   Uart1_Write_Text(adder_txt);
   Uart1_Write(13);
   Uart1_Write(10);
   delay_ms (2000);

 }


void full_subber (char c , char d)
 {
   PORTB = ( c & 0x0F )+ ( d & 0xF0 );
   subber = PORTC ;
   subber = subber & 0x1F;
   ByteToStr(subber,subber_txt);
   Uart1_Write_Text(subber_txt);
   Uart1_Write(13);
   Uart1_Write(10);
   delay_ms (2000);

 }

void main() {

     ADRESL = 0x00;
     ADRESH = 0x00;
     TRISA  = 0xFF;
     TRISB  = 0x00;
     TRISC  = 0x9F;
     CMCON = 0x07;
     ADCON1 = 0b10001001;
     CVRCON.CVROE = 0;

     UART1_Init(9600);               // Initialize UART module at 9600 bps
     Delay_ms(100);                  // Wait for UART module to stabilize

     UART1_Write_Text("Start\r\n");
     add1 = 0b00001111;
     add2 = 0b10101111;
    while (1) {
            if (UART1_Data_Ready())
            lock = UART1_Read();
            calculate_beta();
            Delay_ms(500);
            Calculate_vc1();
            Delay_ms(500);
            Calculate_vc2();
            Delay_ms(500);
            Calculate_vc3();
            Delay_ms(500);
            lock_check();
            Delay_ms(500);
            full_adder (add1 , add2);
            Delay_ms(500);
            full_subber (add1 , add2);
            Delay_ms(500);
    }
}

If this doesn't work then you have to set IRP bit manually in mikroC. See the warnings you are getting in mikroC. Also there might be a problem with your MAX232 or MAX232 circuit. Can you post your circuit? In Hyperterminal you have to choose baudrate 9600, stopbits 1, parity none, databits 8.

http://www.mikroe.com/forum/viewtopic.php?p=108458
http://www.mikroe.com/forum/viewtopic.php?p=101964#101964
https://www.mikroe.com/forum/viewtopic.php?f=97&t=27749
 

Attachments

  • oday.rar
    89.7 KB · Views: 118
  • uart.jpg
    uart.jpg
    192.9 KB · Views: 147
Last edited:

Implementing a 9600 BAUD rate with a 4MHz oscillator frequency shouldn't be issue as the percent error is only -0.2%.

As the error rate approaches +/- 1.0% reliability drops rapidly, an error rate of over +/- 1.0% are typically not viable.



PIClist SPBRG Calculator


Is this a development board or a design of your own?

In either case do you have a schematic of the design?

Is this your first attempt at configuring an RS-232 connection?


Have you properly entered the 4MHz oscillator frequency into the MikroC Pro IDE? If not many of the library routines will not function properly.




Have you tried using the MikroC example code?

Code:
char uart_rd;

void main() {
  ANSEL  = 0;                     // Configure AN pins as digital
  ANSELH = 0;
  
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize
  
  UART1_Write_Text("Start");
  UART1_Write(10);
  UART1_Write(13);
  
  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {     // If data is received,
      uart_rd = UART1_Read();     // read the received data,
      UART1_Write(uart_rd);       // and send data via UART
    }
  }
}

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top