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

Soft UART

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



Joined: 24 Jul 2005
Posts: 13

View user's profile Send private message

Soft UART
PostPosted: Wed Sep 21, 2005 8:43 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 22, 2005 1:55 am     Reply with quote

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

View user's profile Send private message

Soft UART
PostPosted: Thu Sep 22, 2005 6:56 am     Reply with quote

Thanks ckielstra, I'll try with the EXT on A2.
_________________
-cstan
.................................................
Your Mind Is Your Biggest Asset !!
.................................................
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