TRIS AND PORT PROBLEMS HELP NEEDED

General discussion on mikroC.
Post Reply
Author
Message
mr_anderson
Posts: 48
Joined: 08 Apr 2008 19:30
Location: United States

TRIS AND PORT PROBLEMS HELP NEEDED

#1 Post by mr_anderson » 25 Feb 2009 06:38

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

womai
Posts: 239
Joined: 16 Apr 2008 07:45

#2 Post by womai » 25 Feb 2009 19:51

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

troubadour_996
Posts: 16
Joined: 16 Jan 2009 00:18

#3 Post by troubadour_996 » 27 Feb 2009 11:07

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

petrd
Posts: 82
Joined: 14 Feb 2008 11:04
Location: Russia, Voronezh

#4 Post by petrd » 27 Feb 2009 12:20

May be read about RMW (read-modify-write) for PIC16 in part I/O Port datasheet? And read help MikroC.

mr_anderson
Posts: 48
Joined: 08 Apr 2008 19:30
Location: United States

#5 Post by mr_anderson » 27 Feb 2009 23:43

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

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

#6 Post by Sobrietytest » 28 Feb 2009 02:38

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.

fabim
Posts: 197
Joined: 18 Jan 2007 15:49

#7 Post by fabim » 28 Feb 2009 03:07

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

mcu_chip
Posts: 53
Joined: 02 Mar 2009 17:52

#8 Post by mcu_chip » 12 Mar 2009 22:32

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?

fabim
Posts: 197
Joined: 18 Jan 2007 15:49

#9 Post by fabim » 13 Mar 2009 12:19

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

mcu_chip
Posts: 53
Joined: 02 Mar 2009 17:52

#10 Post by mcu_chip » 13 Mar 2009 16:00

That was the question thanks

Greetz
S

mcu_chip
Posts: 53
Joined: 02 Mar 2009 17:52

#11 Post by mcu_chip » 13 Mar 2009 16:02

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,

LOLsim
Posts: 3
Joined: 10 Aug 2008 18:40

Re: TRIS AND PORT PROBLEMS HELP NEEDED

#12 Post by LOLsim » 12 Apr 2010 09:46

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?

Post Reply

Return to “mikroC General”