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 CCS Technical Support

16f877 rs232 interesting problem??
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
capella



Joined: 07 Feb 2009
Posts: 38

View user's profile Send private message

16f877 rs232 interesting problem??
PostPosted: Thu Mar 11, 2010 11:57 am     Reply with quote

hello everybody,
I have a silly problem. I don't know what I do.
Code:
#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000)

//====== LCD Tanıtılıyor ==========//

#define use portb_lcd TRUE
#include <lcd.c>
//==============================/

//=======RS232 AYARLARI========//

#use rs232 (baud=9600,  xmit=pin_C6, rcv=pin_C7, parity=N, stop=1)

//=============================//



void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

while (TRUE) {

      printf("\rBaslamak İçin B tusuna basınız");
      if (getchar() == 'b')
      {
         printf("1 khz signal activated\r");
            while (!kbhit()) {
               output_high(PIN_B0);
               delay_ms(500);
               output_low(PIN_B0);
               delay_ms(500);
            }
      }
   }
}





this circuit is working normally but

Code:
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

while (TRUE) {

      printf("\rBaslamak İçin B tusuna basınız");
      if (getchar() == 'b')
      {
         printf("1 khz signal activated\r");
            while (!kbhit()) {
               output_high(PIN_B0);
               
            }
      }
 if (getchar() == 'c)
      {
         printf("1 khz signal activated\r");
            while (!kbhit()) {
               output_high(PIN_B1);
               
            }
      }

 if (getchar() == 'd')
      {
         printf("1 khz signal activated\r");
            while (!kbhit()) {
               output_high(PIN_B2);
               
            }
      }

   }
}

When I changed this code as above, only it works Proteus but when I try real (on the board) this circuit does not work. While I try this circuit on the board I use hyperterminal. I want to do pin_bo or other pins (as B) just burn led.. I think to problem is code please help me...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 11, 2010 12:18 pm     Reply with quote

In your code, you're calling getchar() several times, and you're calling
kbhit several times.

Look at this sample code. Look at how I read a character with one call
to getc(). Then I convert it to upper case. Then I test it with a switch-case
statement, and take action based on what key was pressed by the user.
http://www.ccsinfo.com/forum/viewtopic.php?t=39145&start=1
capella



Joined: 07 Feb 2009
Posts: 38

View user's profile Send private message

PostPosted: Fri Mar 12, 2010 10:20 am     Reply with quote

sorry maybe this code is very well. but I do a little understand. If it is possible please you can do make change on my code...
rafique4m



Joined: 15 Mar 2010
Posts: 2
Location: Pakistan

View user's profile Send private message

PostPosted: Tue Mar 16, 2010 9:47 pm     Reply with quote

1. Have you configured the respective tris register. I think your are missing set_tirs_c(nn). Configure Input Output direction properly.
2. Have you connected Serial Port connecter DB9 properly.
i.e. Rx,Tx,Gnd pin connections...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 16, 2010 10:06 pm     Reply with quote

The CCS compiler automatically sets the correct TRIS when you use
getchar(), output_high(), output_low(), and many other functions.
You don't need to set it.
evaradharaj



Joined: 15 Jan 2009
Posts: 60

View user's profile Send private message Visit poster's website

check the #use rs232
PostPosted: Thu Mar 18, 2010 4:10 am     Reply with quote

What is the baud rate , crystal frequency and bits r u using?

set the bits to 8 . It has worked fine for me. if its 9 not working
_________________
embedding innovation in engineers
capella



Joined: 07 Feb 2009
Posts: 38

View user's profile Send private message

PostPosted: Thu Mar 18, 2010 7:34 am     Reply with quote

Stopbits is 8, baudrate is 9600, everything is ok no problem about settings. But circuit is not working with PC together. So I research again what is the problem. But I don't still find anything. I want to learn this question.. this problem is code or circuit. what is the problem...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 18, 2010 1:06 pm     Reply with quote

Here is a cleaned up version of your program, with some of the changes
that I suggested:
Code:

#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//=========================================
void main()
{
int8 c;

printf("Start\n\r");

while(1)
  {
   c = getc();   // Wait for a key to be pressed.


   if(c == 'b')
     {
      printf("Pressed: b \n\r");
      output_high(PIN_B0);
     }
   else if(c == 'c')
     {
      printf("Pressed: c \n\r");
      output_high(PIN_B1);
     }
   else if(c == 'd')
     {
      printf("Pressed: d \n\r");
      output_high(PIN_B2);
     }
   else
     {
      printf("Pressed other key: %c \n\r", c);
     }

  }

}
capella



Joined: 07 Feb 2009
Posts: 38

View user's profile Send private message

PostPosted: Fri Mar 19, 2010 9:09 am     Reply with quote

sorry but your code is like false because you defined c as a integer but if c='b' is a string so I think it has error..
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Mar 19, 2010 9:47 am     Reply with quote

PCM programmer before you start banging your head against a brick wall I will get this one for you Smile

capella, If you use single quotes ' then you are referencing a single character value which is the 8 bit ASCII code for the character.

'b' = 98 decimal, 0x68 hex or 0b01101000 binary.
'\r' = 13 decimal, 0x0D hex
'\x68' = 98 decimal, 0x68 hex, 'b'

A string in C is represented by using double quotes "Hello World".

Did you try to compile it ?
capella



Joined: 07 Feb 2009
Posts: 38

View user's profile Send private message

PostPosted: Fri Mar 19, 2010 4:18 pm     Reply with quote

Problem is still continue. It means that when I send b or c or d on my
circuit via hyperterminal it is not working this circuit. But virtual terminal setting is

So when I changed inverted as a normal, this circuit is not working on
the Proteus. Only it is working inverted mode of virtual terminal. But
everytime is not working as a real circuit. but I read inside of pic as below

but everytime leds are off (no reaction)

So this code is not working or?...
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 2:51 am     Reply with quote

I think this problem is a little more basic.

#fuses XT <-------

#use delay(clock=4000000)

Your circuit diagram does not show an external crystal!!!

Are you trying to use the internal OSC at 4MHz ?

If this is the case then you need to change your fuse settings.
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 22, 2010 7:45 am     Reply with quote

Quote:
our circuit diagram does not show an external crystal!!!

Are you trying to use the internal OSC at 4MHz ?

If this is the case then you need to change your fuse settings.
Capella, you can't use an internal oscillator with the '877, because it doesn't have one! You have to use an external oscillator.

(Wayne - you probably knew this, but just missed the fact that he was using an '877) Razz

Rohit
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 8:07 am     Reply with quote

LOL, no I don't always check the data sheet of the device in question, I have plenty of other things I should be getting on with Smile

Well spotted Rohit de Sa.
capella



Joined: 07 Feb 2009
Posts: 38

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 12:23 pm     Reply with quote

I already use external oscillator which is 4Mhz on my real circuit. I think problem is different from what you said...I still do to work. But I did not get any result...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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