| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			ali6094
 
 
  Joined: 31 Jan 2007 Posts: 18
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| port A as data pins and ANO as analague input pins 16F877A | 
			 
			
				 Posted: Tue Mar 27, 2007 11:59 am     | 
				     | 
			 
			
				
  | 
			 
			
				i am presently working with PIC 16F877A
 
 
currently iam using pin#2  ANO as analogue input
 
 
i need to have 4 trigger pulses and dont have any other port available
 
can i do so like pin A.2 to A.5 and just define them as fallows... will that work
 
 
 
#bit TRIGGER1 = PORTA.2
 
#bit TRIGGER 2= PORTA.3
 
#bit TRIGGER 3= PORTA.4
 
#bit TRIGGER 4= PORTA.5
 
 
Regards
 
Ali | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Mar 27, 2007 12:03 pm     | 
				     | 
			 
			
				
  | 
			 
			
				What is meant by a trigger pulse ?   Is this an input to the PIC
 
or an output pulse from the PIC ?
 
 
You can configure Port A so pin A0 is analog, and the rest of
 
the pins on Port A are digitial i/o.  Example:     
 
 	  | Code: | 	 		  | setup_adc_ports(AN0); | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			ali6094
 
 
  Joined: 31 Jan 2007 Posts: 18
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Mar 27, 2007 12:18 pm     | 
				     | 
			 
			
				
  | 
			 
			
				with the trigger pulse i mean its an input to the PIC
 
 
i need to have 4 push switched basically it will act as scroll pin's for the Graphic LCD
 
if 1st is pushed it should move the courser up and like the same for all down, left and right.
 
i hope u get my point | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Mar 27, 2007 12:35 pm     | 
				     | 
			 
			
				
  | 
			 
			
				You could use the button.c code that I posted in the Code Library.
 
http://www.ccsinfo.com/forum/viewtopic.php?t=23837
 
It's one possible way to do it.
 
 
Assuming that four tactile switches (push-buttons) are attached
 
to pins D0-D3 on the PIC with a 10K pull-up on each one, here
 
is some sample code:
 
 	  | Code: | 	 		  
 
// Button definitions.
 
 
// This enum statement assigns consecutive numbers
 
// from 0 to 3 to these constants.
 
enum button_pins {UP_BUTTON, DOWN_BUTTON, EXIT_BUTTON, MENU_BUTTON};
 
 
// Define the pin used for each button.
 
#define UP_BUTTON_PIN    PIN_D0
 
#define DOWN_BUTTON_PIN  PIN_D1
 
#define EXIT_BUTTON_PIN  PIN_D2
 
#define MENU_BUTTON_PIN  PIN_D3
 
 | 	  
 
 
Here's a while loop that waits for one of the buttons to be pressed.
 
When it's pressed, the appropriate 'case' statement is executed.
 
You have to fill in the application code for each 'case' statement.
 
 	  | Code: | 	 		  
 
while(1)
 
  {
 
   button = wait_for_button_press();     
 
 
   switch(button)
 
     {
 
      case UP_BUTTON:
 
        // Put your code for the 'up button' here.
 
        // Or call a routine.
 
        break;
 
        
 
      case DOWN_BUTTON:
 
        // Etc.
 
        break;
 
 
      case MENU_BUTTON:
 
        // Etc.
 
        break;
 
 
      case EXIT_BUTTON:
 
        // Etc.
 
        break;
 
 
      default:        
 
        break; 
 
     }  
 
 
 
  }
 
 | 	  
 
 
 	  | Code: | 	 		  
 
// This routine waits until a button is pressed and then
 
// it returns the specific button that was pressed.
 
int8 wait_for_button_press(void)
 
{     
 
static int8 bvar1 = 0;
 
static int8 bvar2 = 0;
 
static int8 bvar3 = 0;
 
static int8 bvar4 = 0;
 
 
while(1) 
 
  { 
 
   if(button(UP_BUTTON_PIN, 0, 50, 10, bvar1, 1)) 
 
      return(UP_BUTTON); 
 
 
   if(button(DOWN_BUTTON_PIN, 0, 50, 10, bvar2, 1)) 
 
      return(DOWN_BUTTON); 
 
 
   if(button(EXIT_BUTTON_PIN, 0, 50, 10, bvar3, 1)) 
 
      return(EXIT_BUTTON); 
 
 
   if(button(MENU_BUTTON_PIN, 0, 50, 10, bvar4, 1)) 
 
      return(MENU_BUTTON); 
 
 
   delay_ms(10);   // Debounce delay
 
  }
 
 
}  | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			ali6094
 
 
  Joined: 31 Jan 2007 Posts: 18
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Mar 27, 2007 12:43 pm     | 
				     | 
			 
			
				
  | 
			 
			
				well thanx for alot of codes they are really helpfull...
 
just one last ques If i use (for 16F877A) pin 2 as analogue input and pin 3,4,5 and 6 as input triggers will it be fine .. i mean it is allowed or if i use one pin of the portA as analogue input the rest pin cannot be used as trigger pins thats all or i can use | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Mar 27, 2007 12:51 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Quote: | 	 		  
 
If i use (for 16F877A) pin 2 as analogue input and pin 3,4,5 and 6
 
as input triggers will it be fine .. i mean it is allowed  | 	  
 
Look at the 16F877A.H file, near the end of the file, in the section called:
 
"Constants used in setup_adc_ports()".
 
 
That section lists all the available combinations of Analog and Digital pins.
 
Look on the right side in the comments, and it gives a list of all the pins
 
used and their purpose (for example, some pins are assigned to Vref
 
in some modes). | 
			 
		  | 
	
	
		  | 
	
	
		
			Guest
 
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Mar 27, 2007 2:09 pm     | 
				     | 
			 
			
				
  | 
			 
			
				this section just gives the combination of analogue ports only
 
 
 
// Constants used in SETUP_ADC_PORTS() are:
 
#define NO_ANALOGS                           7    // None
 
#define ALL_ANALOG                           0    // A0 A1 A2 A3 A5 E0 E1 E2
 
#define AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_VREF 1    // A0 A1 A2 A5 E0 E1 E2 VRefh=A3
 
#define AN0_AN1_AN2_AN3_AN4                  2    // A0 A1 A2 A3 A5
 
#define AN0_AN1_AN2_AN4_VSS_VREF             3    // A0 A1 A2 A5 VRefh=A3
 
#define AN0_AN1_AN3                          4    // A0 A1 A3
 
#define AN0_AN1_VSS_VREF                     5    // A0 A1 VRefh=A3
 
#define AN0_AN1_AN4_AN5_AN6_AN7_VREF_VREF 0x08    // A0 A1 A5 E0 E1 E2 VRefh=A3 VRefl=A2
 
#define AN0_AN1_AN2_AN3_AN4_AN5           0x09    // A0 A1 A2 A3 A5 E0
 
#define AN0_AN1_AN2_AN4_AN5_VSS_VREF      0x0A // A0 A1 A2 A5 E0 VRefh=A3
 
#define AN0_AN1_AN4_AN5_VREF_VREF         0x0B    // A0 A1 A5 E0 VRefh=A3 VRefl=A2
 
#define AN0_AN1_AN4_VREF_VREF             0x0C    // A0 A1 A5 VRefh=A3 VRefl=A2
 
#define AN0_AN1_VREF_VREF          0x0D    // A0 A1 VRefh=A3 VRefl=A2
 
#define AN0                               0x0E    // A0
 
#define AN0_VREF_VREF             0x0F    // A0 VRefh=A3 VRefl=A2
 
 
 
i will consider that for 
 
#define AN0                               0x0E    // A0
 
 
only pin 2 is used as analogue port rest are digital ... i hope am right
 
 
thanx for the help | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Mar 27, 2007 2:24 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Quote: | 	 		  | Only pin 2 is used as analogue port rest are digital  | 	  
 
That's right.   That's a list of the combinations of pins that
 
can be configured as analog pins. In each #define statement,
 
any pins that are not list will be configured as digital pins.
 
 
Also, when we talk about the analog pins, we normally refer to
 
them by their name:  AN0, AN1, AN2, etc.    That's because the
 
actual pin number may vary, depending upon the package used,
 
or the PIC that you're using. | 
			 
		  | 
	
	
		  | 
	
	
		
			ali6094
 
 
  Joined: 31 Jan 2007 Posts: 18
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Mar 27, 2007 3:44 pm     | 
				     | 
			 
			
				
  | 
			 
			
				| thanx my friend that was a real help | 
			 
		  | 
	
	
		  | 
	
	
		 |