View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
Problem with hardware and software uart |
Posted: Wed Aug 05, 2015 5:12 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Wed Aug 05, 2015 5:46 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Wed Aug 05, 2015 6:06 pm |
|
|
I'sorry, here is:
Code: | #include <12F1822.h>
#FUSES NOWDT, INTRC_IO, NOMCLR, NOBROWNOUT, NOLVP |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 05, 2015 6:15 pm |
|
|
Quote: | fputc(pcout,keypress); |
Look in the CCS manual. You have the parameters reversed. |
|
![](templates/subSilver/images/spacer.gif) |
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Wed Aug 05, 2015 6:23 pm |
|
|
Excuse my clumsiness but I do not understand what the problem, if is not too much to ask please could you put an example... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 05, 2015 6:29 pm |
|
|
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).
|
|
|
![](templates/subSilver/images/spacer.gif) |
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Wed Aug 05, 2015 6:36 pm |
|
|
Thank you, it was that |
|
![](templates/subSilver/images/spacer.gif) |
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Wed Aug 05, 2015 6:38 pm |
|
|
Hi Temtronic,
Why do you say: Quote: | 3) while(true.... isn't properly constructed.... |
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Thu Aug 06, 2015 5:01 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|