|
|
View previous topic :: View next topic |
Author |
Message |
cstan_02
Joined: 24 Jul 2005 Posts: 13
|
Soft UART |
Posted: Wed Sep 21, 2005 8:43 pm |
|
|
Code: |
#case
#if defined(__PCM__)
#include <12F675.h>
#DEVICE ADC=10
#fuses XT,NOWDT,MCLR,PUT
#use delay(clock=4000000,restart_wdt)
#use rs232(baud=9600, xmit=PIN_A1,rcv=PIN_A0, parity=N, bits=8, stream=COM3, DISABLE_INTS,BRGH1OK)
#priority ra,rtcc
#endif
#use fast_io(A)
static short read_adc_vlu;
//.................................................................................................
#int_ra
void uart_isr() {
char c;
c=fgetc(COM3);
switch(c){
case 0x55:
fputc(c,COM3); // If i disable this line and/or put some delay instead, it won't work. why??
read_adc_vlu=TRUE;
break;
default:
fputc(c,COM3); // If i disable this line and/or put some delay instead, it won't work. why??
break;
}
}
//....................................................................................................
void main()
{
system_init();
while(TRUE)
{
if (read_adc_vlu) {printf("%ld\n\r", read_adc());read_adc_vlu = FALSE;} // read_adc_vlu flag is set in the interrupt routine
}//End the while loop!!
}
//.....................................................................................................
//.....................................................................................................
// Function declarations
void system_init(void)
{
set_tris_a(0b100001);
//..............................................................................
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN2);
set_adc_channel(2);
//..............................................................................
int_count = INTS_PER_SECOND;
set_timer0(0);
setup_counters(RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
enable_interrupts(INT_RTCC);
// rtcc routine is not shown here as it does'nt matters!!
//............................................................................................
enable_interrupts(INT_RA0);
enable_interrupts(GLOBAL);
//..............................................................................
}
|
Why is this that, when i don't send out a character everytime i receive one, it won't work? Tried adding delays instead, but won't budge. (compiler's the latest one!!)
Thanks. _________________ -cstan
.................................................
Your Mind Is Your Biggest Asset !!
................................................. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Sep 22, 2005 1:55 am |
|
|
I suspect your problem has something to do with the use of the interrupt on the A0 pin. This interupt has some strange side effects, for example the interrupt flag is cleared on every read/write of GPIO. You would make life a lot easier on yourself by using the INT pin (A2) instead of A0. |
|
|
cstan_02
Joined: 24 Jul 2005 Posts: 13
|
Soft UART |
Posted: Thu Sep 22, 2005 6:56 am |
|
|
Thanks ckielstra, I'll try with the EXT on A2. _________________ -cstan
.................................................
Your Mind Is Your Biggest Asset !!
................................................. |
|
|
|
|
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
|