View previous topic :: View next topic |
Author |
Message |
capella
Joined: 07 Feb 2009 Posts: 38
|
16f877 rs232 interesting problem?? |
Posted: Thu Mar 11, 2010 11:57 am |
|
|
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
|
|
Posted: Thu Mar 11, 2010 12:18 pm |
|
|
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
|
|
Posted: Fri Mar 12, 2010 10:20 am |
|
|
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
|
|
Posted: Tue Mar 16, 2010 9:47 pm |
|
|
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
|
|
Posted: Tue Mar 16, 2010 10:06 pm |
|
|
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
|
check the #use rs232 |
Posted: Thu Mar 18, 2010 4:10 am |
|
|
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
|
|
Posted: Thu Mar 18, 2010 7:34 am |
|
|
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
|
|
Posted: Thu Mar 18, 2010 1:06 pm |
|
|
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
|
|
Posted: Fri Mar 19, 2010 9:09 am |
|
|
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
|
|
Posted: Fri Mar 19, 2010 9:47 am |
|
|
PCM programmer before you start banging your head against a brick wall I will get this one for you
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
|
|
Posted: Fri Mar 19, 2010 4:18 pm |
|
|
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
|
|
Posted: Mon Mar 22, 2010 2:51 am |
|
|
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
|
|
Posted: Mon Mar 22, 2010 7:45 am |
|
|
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)
Rohit |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon Mar 22, 2010 8:07 am |
|
|
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
Well spotted Rohit de Sa. |
|
|
capella
Joined: 07 Feb 2009 Posts: 38
|
|
Posted: Mon Mar 22, 2010 12:23 pm |
|
|
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... |
|
|
|