Page 1 of 1

TRIS AND PORT PROBLEMS HELP NEEDED

Posted: 25 Feb 2009 06:38
by mr_anderson
Hi
i am using mikroC 8.2.0.0 to program PIC16F84A, it works just fine when i use the built-in libraries, but when i access the individual bits, it starts to function incorrectly, the code below should make RB3 OUT and RA2 IN, and when a "1" is applied on RA2, RB3 should blink, but it doesnot, instead it blinks when i apply the 5V to the PIC, i.e. it doesnot care whether a 1 is applied to PORTA or not, can any one tell me why?
void main()
{
TRISB.f3=0;// make RB3 out
TRISA.f2=1;// make RA2 in
PORTA=0;//clear PORTA
while(1)
{
if (PORTA.f2)
{
PORTB.f3=1;// on
Delay_ms(1000);
PORTB.f3=0;
Delay_ms(1000);
}
}
the code shown above works just fine when i replace
TRISB.f3=0 with TRISB=0;
and
TRISA.f2=1 with TRISA=0

can any one tell me why?
Best Regards

Posted: 25 Feb 2009 19:51
by womai
Did you make sure you have pulldowns enabled on PORTA (on the develeopment board), and the jumper for the keypad is set to pullup (VCC)? Otherwise your input is floating when you don't press a key and results will be unpredictable. That could explain what you see.

No sure why you set PORTA to zero - after all you only use it as an input.

I notice if portB.f1 initiall happens to be 1 and you don't press a key, it will stay on forever. I'd suggest adding an else clause to your code that turns it off when your input isn't high.

Wolfgang

Posted: 27 Feb 2009 11:07
by troubadour_996
Hi!

That special, some time ago I have also problem with individual bit access. I do a program working fine on a PIC16F887 accessing the bit individualy but when I try to adjust and work on a PIC 16F877A then I had to work also with the full PORT... I don't really know how work PORTx.Fx... maybe somebody have the ansewr...

bye

Posted: 27 Feb 2009 12:20
by petrd
May be read about RMW (read-modify-write) for PIC16 in part I/O Port datasheet? And read help MikroC.

Posted: 27 Feb 2009 23:43
by mr_anderson
Thank you all for your information.
I have tried different ways and it didnot work.
Any way i hope that they fix it in the next version.
Best Regards

Posted: 28 Feb 2009 02:38
by Sobrietytest
Have you tried:

TRISB = 0xF7 //11110111, all inputs except RB3
TRISA = 0x4 //00000100, all outputs except RA2

I think the idea is that you should setup the entire port, not just individual bits. Individual bit accessing is for reading/writing as opposed to setting direction.

Posted: 28 Feb 2009 03:07
by fabim
hey boy,,,
PIC16F84A ?? << ?
OOOO my GOD... \0/

must be as old in the stock, because this no working .. rsrs

PUT her, the asm generated from mikroC.. plz

Posted: 12 Mar 2009 22:32
by mcu_chip
Fabim what wrong here can I use this with the PIC16877A?

TRISA = 0x7F by example

What the different from TRIS and PORT for setup the port?

Posted: 13 Mar 2009 12:19
by fabim
well.
TRISX ,, refering to latch for "input or output"
1 = 1nput
0 = 0utput

port is for writing to real world or read from real world.
1 = 5V
0 = 0V

is this ? your question ?

fabim.brazil

Posted: 13 Mar 2009 16:00
by mcu_chip
That was the question thanks

Greetz
S

Posted: 13 Mar 2009 16:02
by mcu_chip
Fabim,

Hi,

Is it possible to work in microC with seperate c and h files, coz i would like to put the interrupt routine in a seperate file in the project and place further ISR routines that i call from the interrupt() functions also in seperate modules (c files), so modulair and structured programming.

How can i do that without having to deal with compile time errors when i start the main() method.

Now i'm doing the following with my project:

bodeplotter.c (main program)
int_handler.c (onlyl interrupt() ) with call from the ISR functions
adc_isr.c (all functions that deal with adc)
uart_isr.c
spi_isr.c

How can i resolve that and If possible with a example.

yours cincerely,

Re: TRIS AND PORT PROBLEMS HELP NEEDED

Posted: 12 Apr 2010 09:46
by LOLsim
I was wondering, what if a pin is the input and output? Can you make it so that when u declare TRISx that one of the pin is don't care? I probably can do this by declaring TRISx.0 to TRISx.7 as the input or output and just ignore the pin that is both. What is the don't care symbol?