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

Serial Port, Can I do this?

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



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

Serial Port, Can I do this?
PostPosted: Tue Aug 16, 2005 9:59 am     Reply with quote

I want the received characters to buffer in the RDA interrupt. Receive will always be 9600 baud.

But I want complete control over the transmit characters in software. Will this do it?

I don't want to use the SET_UART_SPEED command....

PIC18F452
I took only snippets to show here so this program may not compile.....

Code:


#define rsxmt PIN_C6
#define rs9600 PIN_B3

#use rs232(baud=9600,parity=N,rcv=PIN_C7,bits=8,errors)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,bits=8,force_sw)

#int_RDA
RDA_isr(){

gotpoll = 0;
rt = 0;
rcin = getc();
bytcnt++;
if (bytcnt <= buffer) rcvbuff[bytcnt] = rcin;

}


void rs232putc(int inp){
int rot,par;

   if (!input(rs9600)) putc(inp); //tx at 9600 baud
   else {//transmit manually at 300 baud odd parity
      output_low(rsxmt);
      delay_us(3333);
      par = 0;
      for (rot = 1; (rot !=0) && (rot <= 128); rot = rot * 2){
         if (inp & rot) output_high(rsxmt);
         else output_low(rsxmt);
         if (inp & rot) par++;
         delay_us(3333);
      }
      par++;
      if (bit_test(par,0)) output_high(rsxmt);
      else output_low(rsxmt);
      delay_us(3333);
      output_high(rsxmt);
      delay_us(3333);
   }
}


void main(){

   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

while(1){
   rs232putc(0xA);
   delay_ms(1000);
 }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 16, 2005 10:28 am     Reply with quote

You can't split the hardware UART into a hardware part and a software
part. That is because of a hardware limitation of the PIC, not CCS.
You must either have a full hardware UART or a full software UART.

These two lines will create two software UARTs:
#use rs232(baud=9600,parity=N,rcv=PIN_C7,bits=8,errors)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,bits=8,force_sw)
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Tue Aug 16, 2005 10:44 am     Reply with quote

Thanks. I think I will just move my transmit pin somewhere else for a software (my own) UART and use the hardware UART for receive and PIN_C6 will be open...
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