CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Garbage characters generate when serial communication

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
prasadezoysa



Joined: 22 Jun 2009
Posts: 4
Location: colombo

View user's profile Send private message Visit poster's website Yahoo Messenger ICQ Number

Garbage characters generate when serial communication
PostPosted: Mon Jul 27, 2009 3:36 am     Reply with quote

I want to display the condition of, if I press the button then showing the status as "Y", else "N". Here with I attached my program. When I connect to computer and communicate with Hyperterminal it gives lot of garbage values. It happens when I supply voltage only. It works correctly with Easy pic 4 programmer.
Code:

#include <16F877.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=08000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

char string[3], IsOk[3];

//int i;

#int_rda              // Interrupt
void serial_isr()
{
   
      strcpy(IsOk, "OK");
      gets(string);
      printf("%2s\n",string);
    printf("%2s\n",IsOk);
      if(strcmp(string, IsOk))
      {
         output_low(PIN_B3);
        if(input(PIN_B0)) {printf("Y\r\n"); }           
         else {printf("N\r\n");}         
      }
      else
         output_high(PIN_B3);
           if(input(PIN_B0)) {printf("Y");}           
           else {printf("N");}
      }
 

void main()
{
   enable_interrupts(global);
   enable_interrupts(int_rda);
     
       do {
       
           printf("\r\n\Running....\n");
         
            while (!input(PIN_B1) );
            {
               if(input(PIN_B0)) {printf("Y\r\n"); }           
               else {printf("N\r\n");}           
            }
             
           }while (1); 
         
      }

_________________
sanjeewa
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 27, 2009 10:48 am     Reply with quote

Quote:
#int_rda // Interrupt
void serial_isr()
{

strcpy(IsOk, "OK");
gets(string);
printf("%2s\n",string);
printf("%2s\n",IsOk); if(strcmp(string, IsOk))

Don't use gets() and printf inside an interrupt service routine.
Use the Ex_sisr.c example file to make an interrupt-driven buffer
for incoming characters. Read the characters from the buffer
from code that runs in a loop in main(). Do your character
processing in main(). Also, the gets() function is not safe to use.
There is no limit on the number of incoming characters, and it's
easy to get more characters than the buffer size, and the result
is that over variables are over-written, causing your program
behave incorrectly. Use the get_string() function instead.

Ex_sisr.c is here:
Quote:
c:\program files\picc\examples\ex_sisr.c


get_string() is here:
Quote:
c:\program files\picc\drivers\input.c


Here is an example that combines Ex_sisr.c and get_string():
http://www.ccsinfo.com/forum/viewtopic.php?t=34267
prasadezoysa



Joined: 22 Jun 2009
Posts: 4
Location: colombo

View user's profile Send private message Visit poster's website Yahoo Messenger ICQ Number

garbage characters generate when serial communication
PostPosted: Wed Jul 29, 2009 3:50 am     Reply with quote

I run the program (sample program).
Still problem happen (garbage characters send).
Actually my objective is according to the input signal, "Y" should show in hyperterminal side.
_________________
sanjeewa
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 29, 2009 11:19 am     Reply with quote

Try a very simple "Hello World" example. Get that working first:
Code:
#include <16F877.H>
#fuses HS, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//====================================
void main()
{
printf("Hello World\n\r");

while(1);
}


Quote:

It happens when I supply voltage only. It works correctly with Easy pic 4 programmer.

Does this mean it works when the board has power supplied by the
Easy Pic 4 programmer ? But it fails when the board has power supplied
by a desk power supply ? Check if the desk power supply voltage
is correct. Also, you may have a grounding problem somewhere.
Or, you may be missing the MCLR pull-up resistor on the PIC.
Look for connection problems.
Guest








PostPosted: Wed Jul 29, 2009 12:08 pm     Reply with quote

Garbage is *almost always* an incorrect baud rate setting. At least that has been my experience. Usually the PC is OK, so check your PIC clock and settings.

HTH - Steve H.
prasadezoysa



Joined: 22 Jun 2009
Posts: 4
Location: colombo

View user's profile Send private message Visit poster's website Yahoo Messenger ICQ Number

garbage characters generate when serial communication
PostPosted: Thu Jul 30, 2009 6:24 am     Reply with quote

Actually problem with my max232 ic. I change it. Then circuit works correctly without any problems.
_________________
sanjeewa
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group