View previous topic :: View next topic |
Author |
Message |
BMaxwell
Joined: 07 May 2004 Posts: 20
|
Problems with output_high |
Posted: Mon May 10, 2004 12:15 pm |
|
|
I have a section of code like this
void recievebyte()
{
output_low(PIN_A2);
charbyte=getc();
output_high(PIN_A2);
}
Im using a 16f819 and a 8MHz clock. I have already tested my rs232 portion of the code and it works. However when I run my full program the Pin A2 goes low but never comes back high. Should i put a delay. Im using setup adc no analogs, standard io and a rs232 running at 19200.
I can even add the line after getc(), putc(charbyte); and that works but the pin never goes back high. Im using a max 233a, could it be a voltage level thing. This is my cts pin. Thanks in advance guys.
Bryan |
|
![](templates/subSilver/images/spacer.gif) |
prwatCCS
Joined: 10 Dec 2003 Posts: 67 Location: West Sussex, UK
|
|
Posted: Mon May 10, 2004 1:17 pm |
|
|
How have you setup port A ?
Are you using the AnalogDigital conversion at all ? _________________ Peter Willis
Development Director
Howard Eaton Lighting Ltd UK |
|
![](templates/subSilver/images/spacer.gif) |
BMaxwell
Joined: 07 May 2004 Posts: 20
|
Yah |
Posted: Mon May 10, 2004 1:33 pm |
|
|
Port A is setup in the #use rs232 line, other than that no. Im using standard io, i thought the compiler would handle the changes. What would be an appropriate command to set pin a2 low and then high? I have a max 233a which is doing the level conversion. So no a/d conversion.
Thanks in advance.
Bryan |
|
![](templates/subSilver/images/spacer.gif) |
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
|
Posted: Mon May 10, 2004 2:02 pm |
|
|
Show us the #USE RS232 line. What is A2? Is it the transmit data line or just a control line? |
|
![](templates/subSilver/images/spacer.gif) |
BMaxwell
Joined: 07 May 2004 Posts: 20
|
Here ya go |
Posted: Mon May 10, 2004 2:07 pm |
|
|
#use rs232(baud=19200, xmit=PIN_A1, rcv=PIN_A0)
I do not set up port A anywhere else. PIN A2 is suppose to be my cts control line for my computer. Thanks in advance
Bryan |
|
![](templates/subSilver/images/spacer.gif) |
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
|
Posted: Mon May 10, 2004 2:11 pm |
|
|
Next, look at the assembly listing (.LST) and see if the assembler is trying to set the pin high. |
|
![](templates/subSilver/images/spacer.gif) |
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
|
Posted: Mon May 10, 2004 2:24 pm |
|
|
Let the pin float and see if it goes high/low then connect to the line level converter and see if the pin acts different.
I compiled your routines on 3.188 compiler and here is a snippet of the .LST code:
Code: | .................... void recievebyte()
.................... {
.................... output_low(PIN_A2);
002B: BSF 03.5
002C: BCF 05.2
002D: BCF 03.5
002E: BCF 05.2
.................... charbyte=getc();
002F: GOTO 004
0030: MOVF 78,W
0031: MOVWF 20
.................... output_high(PIN_A2);
0032: BSF 03.5
0033: BCF 05.2
0034: BCF 03.5
0035: BSF 05.2
.................... }
0036: GOTO 072 (RETURN) |
The GOTO 004 is a routine to receive a character then there is a GOTO 30 at the end of that routine to return. Make sure your code flows correctly. The code to change the output pin is there. |
|
![](templates/subSilver/images/spacer.gif) |
prwatCCS
Joined: 10 Dec 2003 Posts: 67 Location: West Sussex, UK
|
|
Posted: Mon May 10, 2004 2:31 pm |
|
|
I always explicity init my ports with code like
Code: |
#use fast_io( A )
#use fast_io( B )
#use fast_io( C )
#define PORTA_DIR 0b11101111 // declared in binary easy to read!!
#define PORTB_DIR 0b11000000
#define PORTC_DIR 0b10000000
output_a(0);
output_b(0);
output_c(0);
set_tris_a(PORTA_DIR); // a4 outputs a5,a3-a0 analog inputs
set_tris_b(PORTB_DIR); // b7,b6 inputs b5-b0 outputs
set_tris_c(PORTC_DIR); // c7 input, c6-c0 outputs
|
in your case I would make sure
#define PORTA_DIR 0bxxxxx001 // RA0 Input RxData
// RA2 Output - CTS
// RA1 Output - TXData
// x = 0 or 1 as appropriate
set_tris_a(PORTA_DIR);
as an aside - why not us 16F628 whihc has an internal UART ? _________________ Peter Willis
Development Director
Howard Eaton Lighting Ltd UK |
|
![](templates/subSilver/images/spacer.gif) |
BMaxwell
Joined: 07 May 2004 Posts: 20
|
Still not working |
Posted: Mon May 10, 2004 2:40 pm |
|
|
I tried unplugging the PIN from my level converter and it still goes low, i even put in a delay_us(500); and still get the same response. My list files is the same as yours except at the end mine does a returnlw 00 at the end of all my functions. Man im tearing my hair out now, I shall be now known as baldy rofl. Thanks for any advice in advance.
Bryan |
|
![](templates/subSilver/images/spacer.gif) |
BMaxwell
Joined: 07 May 2004 Posts: 20
|
BMaxwell |
Posted: Mon May 10, 2004 3:04 pm |
|
|
I tried explicity setting Port A and it still does not work? Bad chip? Would you like me to send you my code prawtCCS. It would be a huge post if i put it here. I tried it with fast_io and without neither worked. Thanks in advance.
Bryan |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 10, 2004 3:08 pm |
|
|
Quote: | void recievebyte()
{
output_low(PIN_A2);
charbyte=getc();
output_high(PIN_A2);
} |
The getc() function will wait forever, until it gets a character.
I'm assuming that you call this function continuosly, from
a while(1) loop. (Since you didn't post a test program).
So, suppose you send 10 chars to the PIC. Each time the
receivebyte() function is called, it will set Pin A2 low for a
few usec until it gets the char, and then it will set pin A2
high again.
But after those 10 chars have been received, if you call the
receivebyte() function again, it will sit there forever at
the getc() line. Pin A2 will appear to be "stuck" low. |
|
![](templates/subSilver/images/spacer.gif) |
prwatCCS
Joined: 10 Dec 2003 Posts: 67 Location: West Sussex, UK
|
|
Posted: Mon May 10, 2004 3:21 pm |
|
|
I suspect PCM Programmer is on the right track with this one.
I hardly ever use getc(), and all my comms is interrupt driven and
uses direct register access, buffers etc, so I never "wait" on character reception ... _________________ Peter Willis
Development Director
Howard Eaton Lighting Ltd UK |
|
![](templates/subSilver/images/spacer.gif) |
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Mon May 10, 2004 8:10 pm |
|
|
How about something simple like this:
Code: |
#include <16F819.h>
#FUSES HS,NOWDT,PUT,NOMCLR,NOBROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG,NOPROTECT,NOBROWNOUT
#use delay (clock=8000000)
#use rs232 (baud=19200,xmit=PIN_A1,rcv=PIN_A0,parity=N,bits=8)
#byte TRISA = 0x85
char charbyte;
int8 dirA;
void main()
{
dirA = ( TRISA & 0b11111001 ) | 0b00000001;
set_tris_A( dirA ); // set RA1-2 to outputs, all others remain
setup_adc_ports( NO_ANALOGS );
while ( 1 )
{
output_low( PIN_A2 ); // clear CTS
charbyte=getc(); // receive comms
putc( charbyte ); // echo comms
output_high( PIN_A2 ); // set CTS
delay_ms( 500 ); // delay to debug CTS
}
}
|
You may want to tweak the #FUSES. |
|
![](templates/subSilver/images/spacer.gif) |
|