Libstock
It is currently 23 Oct 2014 07:56

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: 25 Feb 2009 06:38 
Offline

Joined: 08 Apr 2008 19:30
Posts: 48
Location: United States
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


Top
 Profile  
 
 Post subject:
PostPosted: 25 Feb 2009 19:51 
Offline

Joined: 16 Apr 2008 07:45
Posts: 239
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


Top
 Profile  
 
 Post subject:
PostPosted: 27 Feb 2009 11:07 
Offline

Joined: 16 Jan 2009 00:18
Posts: 16
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


Top
 Profile  
 
 Post subject:
PostPosted: 27 Feb 2009 12:20 
Offline

Joined: 14 Feb 2008 11:04
Posts: 71
Location: Russia, Voronezh
May be read about RMW (read-modify-write) for PIC16 in part I/O Port datasheet? And read help MikroC.


Top
 Profile  
 
 Post subject:
PostPosted: 27 Feb 2009 23:43 
Offline

Joined: 08 Apr 2008 19:30
Posts: 48
Location: United States
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


Top
 Profile  
 
 Post subject:
PostPosted: 28 Feb 2009 02:38 
Offline

Joined: 05 Jul 2008 06:05
Posts: 608
Location: Thailand
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.


Top
 Profile  
 
 Post subject:
PostPosted: 28 Feb 2009 03:07 
Offline

Joined: 18 Jan 2007 15:49
Posts: 197
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


Top
 Profile  
 
 Post subject:
PostPosted: 12 Mar 2009 22:32 
Offline

Joined: 02 Mar 2009 17:52
Posts: 53
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?


Top
 Profile  
 
 Post subject:
PostPosted: 13 Mar 2009 12:19 
Offline

Joined: 18 Jan 2007 15:49
Posts: 197
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


Top
 Profile  
 
 Post subject:
PostPosted: 13 Mar 2009 16:00 
Offline

Joined: 02 Mar 2009 17:52
Posts: 53
That was the question thanks

Greetz
S


Top
 Profile  
 
 Post subject:
PostPosted: 13 Mar 2009 16:02 
Offline

Joined: 02 Mar 2009 17:52
Posts: 53
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,


Top
 Profile  
 
PostPosted: 12 Apr 2010 09:46 
Offline

Joined: 10 Aug 2008 18:40
Posts: 3
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group