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

software uart with INT_RDA

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



Joined: 14 Feb 2011
Posts: 1

View user's profile Send private message

software uart with INT_RDA
PostPosted: Mon Feb 14, 2011 11:28 am     Reply with quote

Hello!

I need to use uart 2 port so I will use software uart (I use 16F877A).

If xmit=PIN_C6, rcv=PIN_C7, this code can use
but when I use like this, it can't receive string so I want to ask everybody.

What can I do? and How to write the code?
Please give some example to me.

Thank you so much.
Code:

#include <16F877A.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C4, rcv=PIN_C5, stream=COM)

#define relay_door      PIN_B0
#define magnetic_elec   PIN_B1

char close_e[5];
char open_e[5];
char order_e[5];
BOOLEAN rx_int = FALSE;


#INT_RDA
void RS232_isr(void)
{
    gets(order_e);
    rx_int = TRUE;
}

void main(char order_e)
{
   int v;
   int w;
   set_tris_b(0x00);
   set_tris_a(0x00);
   output_b(0x00);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);
   strcpy(close_e,"0100");
   strcpy(open_e,"01FF");
   printf("\r\n Hello");
   
   while(TRUE)
   {
      printf("\r\n MOVE to WHILE TRUE");
      printf("\r\n ENTERED ORDER is \"%s\"",order_e);
      while(!rx_int)
         {
            output_toggle(PIN_A0);
            delay_ms(1000);
         }
     if(rx_int) // True or False not 1 or 0
      {
         printf("\r\n RX_INT TRUE");
         v = strcmp(order_e,open_e);
         printf("\r\n V is %d",v);
          if (v == 0)
            {
               printf("\r\n ENTERED ORDERE is \"%s\"",order_e);
               output_high(PIN_B0);
            } 
          else if(v != 0 )
            {
               w = strcmp(order_e,close_e);
               printf("\r\n W is %d",w);
                  if (w == 0)
                  {
                     printf("\r\n ENTERED ORDERE is \"%s\"",order_e);
                     output_high(PIN_B1);
                  }
                  else
                  {
                     printf("\r\n read command or file name");
                     printf("\r\n ENTERED ORDERE is \"%s\"",order_e);
                  }
             }
      }
      else
      {
      printf("\r\n End Process");
      }
      rx_int = FALSE;
   }
   
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Feb 14, 2011 11:42 am     Reply with quote

Of course, INT_RDA can't work with software UART. But it's also a bad idea to use gets() inside an ISR function with hardware UART. It won't return from interrupt and thus block the processor until the final carriage return. You would want to use a RX buffer in this case.
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