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
TRIS AND PORT PROBLEMS HELP NEEDED
-
- Posts: 48
- Joined: 08 Apr 2008 19:30
- Location: United States
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
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
-
- Posts: 16
- Joined: 16 Jan 2009 00:18
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
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
-
- Posts: 48
- Joined: 08 Apr 2008 19:30
- Location: United States
-
- Posts: 619
- Joined: 05 Jul 2008 06:05
- Location: Thailand
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,
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
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?