thb2
Joined: 25 Aug 2010 Posts: 2
|
PIC18F1320: TX goes low when setting B-port output |
Posted: Wed Aug 25, 2010 2:02 pm |
|
|
Hi,
I'm using the following code on a 18F1320. After reset the TX pin is high. Then the "Startup...." is send and TX toggles a few times and then goes high again for 200 ms.
Then as soon as I set or clear PIN B3 the TX pin goes down. Can you tell me why, what am I doing wrong? There is no hardware connection between TX(B1) and B3.
My compiler is version 3.150.
Thanks in advance for any help!
Thomas
Code: |
#include <18F1320.h>
#device adc=8
#use delay(clock=20000000)
#fuses HS,PUT,NOWDT,NOEBTRB,NOEBTR,NOFCMEN,NOCPD,NOPROTECT,MCLR,NOWRTB,NOWRTC,NOLVP,NOWRT,NOWRTD,NOBROWNOUT,NODEBUG,NOIESO,NOSTVREN
#use rs232(baud=9600,parity=N,xmit=PIN_B1,rcv=PIN_B4,bits=8)
#bit PINB3 = 0xF81.3 //PIC18F1220, PIN_B3
void main()
{
set_tris_a(0b00000000);
set_tris_b(0b00010000); // B4: RS232-RX
//PINB3=0;
delay_ms(3000); //don't remove (bootloader)
printf("Startup........");
delay_ms(200);
while(1)
{
PINB3=1;
delay_ms(10);
PINB3=0;
delay_ms(10);
}
}
|
|
|
thb2
Joined: 25 Aug 2010 Posts: 2
|
|
Posted: Wed Aug 25, 2010 2:12 pm |
|
|
OK, I replaced the
#bit PINB3 = 0xF81.3 //PIC18F1220, PIN_B3
PINB3=1;
with
output_high(PIN_B3);
and it works. Output_high is translated to
BCF F93.3 (TRISB)
BSF F8A.3 (LATB)
Is it necessary to clear the TRISB? I think I have to read the datasheet to find out what PORT, LAT and TRIS mean. |
|