|
|
View previous topic :: View next topic |
Author |
Message |
young
Joined: 24 Jun 2004 Posts: 285
|
PIN_A0 problem? |
Posted: Fri Nov 26, 2004 1:32 pm |
|
|
I have following program, but it just wired, because the led connected to PIN_A0 is always blink, which I believe that it should wait for me to click a letter 'a' and then blink, any idea why?
Code: |
#include <12F675.h>
#fuses XT, BROWNOUT,NOWDT,NOPROTECT,PUT,NOMCLR
#use delay(clock = 4000000)
#use rs232(baud=9600, parity=N, RCV=PIN_A2)
void main ()
{
char a;
setup_comparator(NC_NC_NC_NC);
while(1)
{
output_high(PIN_A0);
delay_ms(200);
output_low(PIN_A0);
delay_ms(200);
a=getc();
if(a=='a')
{
output_high(PIN_A1);
delay_ms(200);
output_low(PIN_A1);
delay_ms(200);
}
}
}
|
|
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Fri Nov 26, 2004 1:57 pm |
|
|
When I click letter 'a', the led connected to PIN_A1 does not blink? |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Nov 26, 2004 1:58 pm |
|
|
While in iddle state, does PIN_A2 is stable HIGH ?
I guess getc() is getting a char != 'a'
Did you try to printf the value of variable a ?
HTH,
Humberto |
|
|
djwallace
Joined: 26 Nov 2004 Posts: 10
|
|
Posted: Fri Nov 26, 2004 2:06 pm |
|
|
In your code,
if you just hit 'a' once on the keyboard, the LED on pinA1 should blink on and off once. The next time your loop goes around, it will hang at the line
a=getc();
until you hit a character. if you do not hit 'a' again, then it will not blink. _________________ darryl |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Fri Nov 26, 2004 2:11 pm |
|
|
thank you, you are right? I measured the pin_a2, it is high connected to the max232 output pin, when I disconnected PIN_A2 to MAX232, it is low.
but how come it become a high. the connection I used for a long time, it works just fine, I did not change anything, even move wires.
when I printf out the a, I click on letter 'a', letter 'X' was returm, when I click on the other, different letter or no letter return, what is wrong? |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Nov 26, 2004 3:01 pm |
|
|
Quote: |
thank you, you are right? I measured the pin_a2, it is high connected to the max232 output pin, when I disconnected PIN_A2 to MAX232, it is low.
but how come it become a high. the connection I used for a long time, it works just fine, I did not change anything, even move wires.
|
It is right. Iddle state of MAX232 rcv pin must be HIGH in TTL side.
Does the PC COM settings: 9600,N,8,1 ?
Humberto |
|
|
Guest
|
|
Posted: Fri Nov 26, 2004 3:25 pm |
|
|
Yes, I did. I even checked the RS232 on another program with 16f76. It works just fine.
when I used this connect on 12f675, this thing just happen, right now, what ever I click, it will return me a 'X', and the hyperterminal show error message.
Code: |
#if defined(__PCM__)
#include <12F675.h>
#fuses XT, BROWNOUT,NOWDT,NOPROTECT,PUT,NOMCLR
#use delay(clock = 4000000)
#use rs232(baud=9600, parity=N, RCV=PIN_A3,XMIT=PIN_A2)
void main ()
{
char ch;
setup_comparator(NC_NC_NC_NC);
while(1)
{
output_high(PIN_A0);
delay_ms(200);
output_low(PIN_A0);
delay_ms(200);
ch=getchar();
putc(ch);
if(ch=='a');
{
output_high(PIN_A1);
delay_ms(200);
output_low(PIN_A1);
delay_ms(200);
}
}
}
|
|
|
|
Guest
|
|
Posted: Fri Nov 26, 2004 3:46 pm |
|
|
right now I used the following program, it isetting the right char after print out, but the led connected to PIN_A2 is on whenever I click a letter, no matter. where is the problem
Code: |
#if defined(__PCM__)
#include <12F675.h>
#fuses XT, BROWNOUT,NOWDT,NOPROTECT,PUT,NOMCLR
#use delay(clock =4000000)
#use rs232(baud=9600, parity=N, RCV=PIN_A3,XMIT=PIN_A2)
void main ()
{
char ch;
setup_comparator(NC_NC_NC_NC);
SETUP_ADC_PORTS(NO_ANALOGS);
while(1)
{
output_high(PIN_A0);
delay_ms(200);
output_low(PIN_A0);
delay_ms(200);
ch=getchar();
putc(ch);
if(ch=='a');
{
output_high(PIN_A1);
delay_ms(200);
output_low(PIN_A1);
delay_ms(200);
}
}
}
|
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Nov 26, 2004 4:57 pm |
|
|
Quote: |
right now I used the following program, it isetting the right char after print out,
|
Does it start running magically?
Young, you are fighting hard with the 12F675 trying to receive a char from a PC
through RS232 since June/04 and getting odd results frequently.
Could you pls tell us a brief description of the hardware tools you are using
to test your codes?
I guess you are working with a protoboard. Am I rigth ?
Humberto |
|
|
Guest
|
|
Posted: Mon Nov 29, 2004 7:40 am |
|
|
thank you , it is working right now, It was not the problem of RS232 communication , it was the setup of the port which cause me problem. |
|
|
padamo
Joined: 07 Dec 2004 Posts: 1
|
Missing line in Example 8 in 12F675 Kit |
Posted: Fri Dec 17, 2004 7:50 am |
|
|
It is easy to make the mistake to not set up the port pins into the digital mode because the code in the 12F675 kit example 8 is missing a line. The example does not do:
setup_adc_ports(NO_ANALOGS);
which causes getc() to return without waiting for a character. |
|
|
|
|
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
|