CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

open / close ports on 16F84a
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Michel
Guest







open / close ports on 16F84a
PostPosted: Tue Feb 07, 2006 9:09 am     Reply with quote

If i want to be totaly sure that all of the ports are opened and after that, that all of the opened ports are closed, what should i do?.

Is this just it or ?:
output_high (PIN_B1);
output_low (PIN_B1);

It is importent to me becuse after i shut down /close the selected ports i must be sure that there is no power on the closed ports....
Ttelmah
Guest







PostPosted: Tue Feb 07, 2006 9:32 am     Reply with quote

If driven, either high or low, the port can deliver power. There is no such thing really as 'closing' a port. Whether it is 'right' to drive a pin high, or low, (or to change the pin to an input, which turns off the output drive), will depend on what is connected. Obviously, if there is a load connected, which draws power when driven high, then driving the pin 'low', is the answer to save power. Similarly, if there is a load that draws power, when driven low, then you would need to drive the pin 'high'. Leaving a pin 'undriven' (you read the pin, which changes it to an input), is only 'right', if there is an enternal signal that will drive the pin either high or low. An input pin, can draw significant power inside the PIC, if it is sitting floating, and not either high or low...
So, there is no 'single' answer, to how to set a pin for the least power consumption. It depends totally on the circuitry attached.

Best Wishes
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 07, 2006 9:33 am     Reply with quote

Open? Closed? Do you mean a HIGH or LOW CMOS signal? Or do you mean input vs. output vs. floating?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








PostPosted: Tue Feb 07, 2006 10:06 am     Reply with quote

I meen input vs output.

What happens:
I got timer which open 3 ports , waits 10 secs, closes opened ports, and open NEW ones ( not the old ).

This opened ports will trigger 5V circuit and so on...
So i must be sure that only the opened port are working, and that they are the only ones with some power on the pins..

I don't know if i explained best, but this is it...
Ttelmah
Guest







PostPosted: Tue Feb 07, 2006 10:55 am     Reply with quote

'Open', and 'close', make no sense. I suspect you have an output multiplexer, which connects the signals 'to' something. If so, you need the signals to be driven, and _you_ need to work out which is the 'off' direction for the signals, and set them to this. You are the only person, who can tell what the 'idle' state of the signals is.

Best Wishes
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 07, 2006 1:19 pm     Reply with quote

Anonymous wrote:
I meen input vs output....


Then use INPUT or OUTPUT, not OPEN or CLOSED.

OPEN and CLOSED generally refer to the state of a switch, INPUT or OUTPUT is much different.

OPEN = contacts open (mechanical switch or relay) or very high impedance path (MOSFET not conducting for example).

CLOSED = contacts closed (mechanical switch or relay) or low impedance path (MOSFET conducting)

INPUT = high impedance CMOS input, very little current flows to produce HIGH or LOW in PIC's PORTx register. May or may not use internal pull-up resistor to VDD rail.

OUTPUT = low impedance CMOS output, upto 25ma sink or source on single pin when writing bits to LATCHx registers.

Try explaining your situation again using more appropriate terms. If possible, post a schematic or link to the schematic.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








PostPosted: Mon Feb 13, 2006 5:58 am     Reply with quote

we are still in HW design but this is what i know so far:

There will be some micro switch connected to MCU. There are four microswitches in line ( in package ) and you can make different combinations. Like: one on- rest off, two on - rest off, three on - one off...

How should i solve this thru program?
Should i scan each pin and write the value into memory or something else.


IMPOTRENT:
Microswitch positions are set before first run.
You can set them again (different ) if you shut down the device and make restart. Depending on position i set some delay (2,4,6,8 seconds ) and then i start other operations. When the delay is over motor starts to run.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Feb 13, 2006 8:26 am     Reply with quote

Here you can find how to connect a switch to a PIC input.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/7_03chapter.htm

1) Wire the four switches in the same fashion as shown in this figure, (following this schematic
you will wired it from A0 to A3)

2) Then write a code to sense the switches state (OPEN or CLOSE) and trigger the delays accordingly.

3) Post your code and we will help you until it run.


Humberto
Guest








PostPosted: Tue Feb 14, 2006 6:25 am     Reply with quote

Code:
#include <16F84a.h>
#fuses XT, NOWDT, NOPROTECT
#use delay (clock=4000000)
#include "gumbi.c"

#define A0 PIN_A0
#define A1 PIN_A1
#define A2 PIN_A2
#define A3 PIN_A3

/*
#int_TIMER1
TIMER1_isr()
{
  if(++count >= 75)
  {   
  }
}
*/

void main()
{
   int state;
   //tipkaINIT();
   output_high(PIN_B0);            // starting B0
   delay_ms(500);
   output_high(PIN_B1);            // starting B1
   //----------------------------------------------------------   *
   output_high(A0);               // starting 0 switch      *
   output_high(A1);               // starting 1 switch      *
   output_high(A2);               // starting 2 switch      *   switch simulation thru LED's
   output_high(A3);               // starting 3 switch      *
   //-----------------------------------------------------------   *
   if (input(A0==0)&&(input(A1==0)&&(input(A2==0)&&(input(A3==0) ))))   // full
      state = 1;
      break;
   if (input(A0==0)&&(input(A2==0)&&(input(A3==0) )))               // three
      state = 8;
      output_high(PIN_B2);
      break;
   if (input(A0==0)&&(input(A2==0) ))                           // two
      state = 6;
      break;
   if (input(A0==0)&&(input(A1==0) ))                            // two   
      state = 4;
      break;      
   if (input(A0==0))                                       // one
      state = 2;
      break;      
      
   //************ check switch state ****************************
   switch (state){
       case 1:   delay_ms(1000);
             output_low(PIN_B0);
            output_low(PIN_B1);
            delay_ms(500);
            output_high(PIN_B2);
             break;
      case 2:   delay_ms(2000);
            output_low(PIN_B0);
            output_low(PIN_B1);
              delay_ms(500);
            output_high(PIN_B2);
             break;
      case 4:   delay_ms(4000);
            output_low(PIN_B0);
            output_low(PIN_B1);
            delay_ms(500);
            output_high(PIN_B2);
             break;
      case 6:   delay_ms(6000);
            output_low(PIN_B0);
            output_low(PIN_B1);
            delay_ms(500);
            output_high(PIN_B2);
             break;
       case 8:   delay_ms(8000);
            output_low(PIN_B0);
            output_low(PIN_B1);
              delay_ms(500);
            output_high(PIN_B2);
             break;
      }
      
}

Quote:
/*
If i use this aproach i get this errors:
1.) output_high(PIN_B2) is triggered in each switch combination ( in the if loop)(?) There is no checking...
2.) B0 and B1 are lighted all the time ( and they should be off when programs run into switch case ).

Problems:
1.) I must change delay_ms with timer countdown ( how to implement this in switch case ?).
2.) The timer is importent becuse, when i start first motor, timer will countdown and then he will start second motor.
3.) I must intergrate a main switch interrupt to trigger restart( not the 4 microswitches ).
The main switch is used for restart and i have made the switch routine + debouncing, but i didnt make implementation in main code.

4.) can i use this four outputs high/low in array ? To simple this code...
*/
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 8:06 am     Reply with quote

1) How do you connect the switches and the LED's.
2) What pins are INPUTS.
3) What pins are OUTPUTS.

Quote:

If i use this aproach i get this errors:
1.) output_high(PIN_B2) is triggered in each switch combination ( in the if loop)(?) There is no checking...
2.) B0 and B1 are lighted all the time ( and they should be off when programs run into switch case ).


The circuit is doing what you coded. It doesn't show anything that will change PIN_Bx state.
The statements:
output_high(PIN_B2);
output_low(PIN_B0);
output_low(PIN_B1);


are the same in all the 'switch cases'

This code does not do what you want
Code:

 if (input(A0==0)&&(input(A1==0)&&(input(A2==0)&&(input(A3==0) ))))   // full


For example using this code:
Code:

int microswitch_state, turn_on;

   microswitch_state = input_a();      // Read all inputs at once

   if(microswitch_state & 0B00000001)  // Read input(A0)
     {
     }

The compiler is 'clever enough' to generate the following code:
Code:

BTFSS  microswitch_state.0


Quote:

output_high(A0); // starting 0 switch *
output_high(A1); // starting 1 switch *


If you connected the switches to this inputs, why do you toggle them HIGH like outputs?
Unless some specific cases where you can share a PIN, if you connect a switch to a PIN,
this PIN must be defined as INPUT.


Humberto
Guest








PostPosted: Tue Feb 14, 2006 11:48 am     Reply with quote

Quote:
1.) How do you connect the switches and the LED's.
**Im still waiting for microswitches so im simulating switches with LED

2.) Whole A port (a0 - A4 ) are switches

3.) B0,B1,B2 --> relays

4.) B5 --> main switch



First relay will be triggered when you hit the main switch and after that i have to do that what i have described before.
The device is under power and when you hit main switch then you start all operation ( i take a look into microswitches positions, i set countdown time and then i start to triger rest of the relays)

Depending on microswitches positions, delay is arranged (1,2,4,8 seconds )...

I hope i have give you the main picture what i have to do until my HW is fully done...but please if you need additional infos let me know.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 12:09 pm     Reply with quote

Quote:

**Im still waiting for microswitches so im simulating switches with LED


I think you still do not understand what's the difference between an INPUT and an OUTPUT.
If you do not have a real switch, -for testing purposes- you can replace it with a single jumper
NOT with a LED.(unless you are short-circuiting the LEDīs)

Quote:

1.) How do you connect the switches and the LED's.


You didn't answer this yet.


Humberto
Guest








PostPosted: Wed Feb 15, 2006 2:50 am     Reply with quote

I think you still do not understand what's the difference between an INPUT and an OUTPUT. ** Yes, im not in the hardware part :-). Sorry :-)

Quote:
How do you connect the switches and the LED's.
*Thre wasn't switches AND LED. I have used LED instead of switches , and like you say... i didn't understand the difference between those two end states.

------------------------
Quote:
unless you are short-circuiting the LEDīs
* I have changed the LED with jumpers.



Humberto, i know that this are newbee questions for you, so thank you for you patience...
Guest








PostPosted: Fri Feb 17, 2006 10:33 am     Reply with quote

can please, anyone take a look into my post ?
Guest








PostPosted: Tue Feb 21, 2006 6:01 am     Reply with quote

Well after understanding how the open / close ports are operating i have problems with code form mr. Humberto.
Code:

int microswitch_state, turn_on;

   microswitch_state = input_a();      // Read all inputs at once

   if(microswitch_state & 0B00000001)  // Read input(A0)
     {
     }

This part of code is working when you want to check just A0.
but
if i run
Code:

   if(microswitch_state & 0B00000010)  // Read input(A1)
     {
     }

and if the jumper is set at A1, there is no check.
Same goes for some combination... Why?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group