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

Problem with hardware and software uart

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Problem with hardware and software uart
PostPosted: Wed Aug 05, 2015 5:12 pm     Reply with quote

Hi, I'm trying to make a baud rate changer, for that I am using USART hardware to receive the data and I used a software UART to forward the data but with different baud.

Code:
#use delay(clock=8000000)
#use rs232(baud=9600,xmit=PIN_A0,rcv=PIN_A1,ERRORS)
#use rs232(baud=4800,xmit=PIN_A2,ERRORS,FORCE_SW,STREAM=pcout)

char Keypress=' ';

#int_rda
void serial_isr() {

  Keypress=0x00;
  if(kbhit()){
    Keypress=getc();
    if(Keypress!=0x00){
      fputc(pcout,keypress);
      keypress=0x00;
    }
  }
}

void main(){
   enable_interrupts(global);
   enable_interrupts(int_rda);

while(TRUE) ;

}


but I have the following error when compiling the program
Quote:
Stream must be a constant in the valid range


Anyone can tell me how to correct the error?
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Aug 05, 2015 5:46 pm     Reply with quote

need some more input
1) which PIC ? A0, A1 don't look like hardware pins to me...
2) if(kbhit().... not needed, ISR already saw 'something' in the buffer
3) while(true.... isn't properly constructed....


Jay
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Wed Aug 05, 2015 6:06 pm     Reply with quote

I'sorry, here is:

Code:
#include <12F1822.h>
#FUSES NOWDT, INTRC_IO, NOMCLR, NOBROWNOUT, NOLVP
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 05, 2015 6:15 pm     Reply with quote

Quote:
fputc(pcout,keypress);

Look in the CCS manual. You have the parameters reversed.
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Wed Aug 05, 2015 6:23 pm     Reply with quote

Embarassed Excuse my clumsiness but I do not understand what the problem, if is not too much to ask please could you put an example...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 05, 2015 6:29 pm     Reply with quote

The CCS manual shows that the 'stream' parameter must be the 2nd one.
You have the stream as the first parameter. That's why you get the error.
From the CCS manual:
Quote:

putc( ) putchar( ) fputc( )

Syntax:
putc (cdata)
putchar (cdata)
fputc(cdata, stream)

Parameters:
cdata is a 8 bit character.
Stream is a stream identifier (a constant byte)

Returns: undefined

Function:
This function sends a character over the RS232 XMIT pin. A #USE RS232
must appear before this call to determine the baud rate and pin used. The
#USE RS232 remains in effect until another is encountered in the file.
If fputc() is used then the specified stream is used where putc() defaults
to STDOUT (the last USE RS232).
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Wed Aug 05, 2015 6:36 pm     Reply with quote

Razz Thank you, it was that
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Wed Aug 05, 2015 6:38 pm     Reply with quote

Hi Temtronic,

Why do you say:
Quote:
3) while(true.... isn't properly constructed....
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 06, 2015 5:01 am     Reply with quote

hmm... it just didn't look right.
I'm so used to seeing

while(TRUE) {
stuff to do...
}

that
while(TRUE) ;

seemed 'odd'


Jay
so the 'old dog' learned a new trick today
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