| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			40inD
 
 
  Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| how to define pins as array? | 
			 
			
				 Posted: Thu Apr 24, 2008 1:44 am     | 
				     | 
			 
			
				
  | 
			 
			
				How to define pins as array? I want to declare pins like
 
 
 	  | Code: | 	 		  A[0]=pin_A0;
 
....
 
A[15]=pin_B7;
 
 | 	  
 
and work with pins in array style i.e. On or Off the pin by this command:  | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Apr 24, 2008 2:04 am     | 
				     | 
			 
			
				
  | 
			 
			
				You could declare an array of bits, and then set the base address of the
 
array to the address of PortA with the #locate directive.  Note that you
 
must also set the TRIS for the Ports, to make all pins be outputs.
 
Also, on the 16F877, PortA outputs A6 and A7 don't exist.   On other
 
PICs, one pin on PortA might be an input-only pin.
 
 	  | Code: | 	 		  
 
#include <16F877.H> 
 
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
 
#use delay(clock=4000000) 
 
 
int1 array_of_bits[16];
 
#locate array_of_bits = 0x05  // Address of PortA on 16F877
 
 
//====================================
 
void main() 
 
{
 
int8 i;
 
 
set_tris_a(0x00);
 
set_tris_b(0x00);
 
 
array_of_bits[0] = 1;
 
array_of_bits[1] = 0;
 
array_of_bits[2] = 1;
 
array_of_bits[3] = 0;
 
array_of_bits[4] = 1;
 
array_of_bits[5] = 0;
 
array_of_bits[6] = 1;
 
array_of_bits[7] = 0;
 
array_of_bits[8] = 1;
 
array_of_bits[9] = 0;
 
array_of_bits[10] = 1;
 
array_of_bits[11] = 0;
 
array_of_bits[12] = 1;
 
array_of_bits[13] = 0;
 
array_of_bits[14] = 1;
 
array_of_bits[15] = 0;
 
 
while(1);
 
} | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			40inD
 
 
  Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Apr 24, 2008 3:28 am     | 
				     | 
			 
			
				
  | 
			 
			
				Hmmm. I tried to make this:
 
 	  | Code: | 	 		  
 
#include <16F877A.h>
 
#device adc=8
 
 
#FUSES NOWDT                    //No Watch Dog Timer
 
#FUSES XT                       //Crystal osc <= 4mhz
 
#FUSES NOPUT                    //No Power Up Timer
 
#FUSES NOPROTECT                //Code not protected from reading
 
#FUSES NODEBUG                  //No Debug mode for ICD
 
#FUSES NOBROWNOUT               //No brownout reset
 
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
 
#FUSES NOCPD                    //No EE protection
 
#FUSES WRT_50%                  //Lower half of Program Memory is Write Protected
 
 
#use delay(clock=4000000)
 
byte R[24]; // relays array
 
 
 
void main()
 
{int i;
 
R[0]=pin_A4;
 
R[1]=pin_A5;
 
R[2]=pin_E0;
 
R[3]=pin_E1;
 
R[4]=pin_E2;
 
R[5]=pin_C0;
 
R[6]=pin_C1;
 
R[7]=pin_C2;
 
R[8]=pin_C3;
 
R[9]=pin_D0;
 
R[10]=pin_D1;
 
R[11]=pin_D2;
 
R[12]=pin_D3;
 
R[13]=pin_C4;
 
R[14]=pin_C5;
 
R[15]=pin_C6;
 
R[16]=pin_C7;
 
R[17]=pin_D4;
 
R[18]=pin_D5;
 
R[19]=pin_D6;
 
R[20]=pin_D7;
 
R[21]=pin_B1;
 
R[22]=pin_B2;
 
R[23]=pin_B4;
 
 
 
  setup_adc_ports(NO_ANALOGS);
 
   setup_adc(ADC_OFF);
 
   setup_psp(PSP_DISABLED);
 
   setup_spi(SPI_SS_DISABLED);
 
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
 
   setup_timer_1(T1_DISABLED);
 
   setup_timer_2(T2_DISABLED,0,1);
 
   setup_comparator(NC_NC_NC_NC);
 
   setup_vref(FALSE);
 
 for (i=0; i<=23; i++)
 
 {
 
   output_high(R[i]);
 
 delay_ms(250);
 
 
 
 }
 
 
}
 
 | 	  
 
And in Proteus it works fine. | 
			 
		  | 
	
	
		  | 
	
	
		
			Matro Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Apr 24, 2008 3:41 am     | 
				     | 
			 
			
				
  | 
			 
			
				Yes, it will work.
 
It's simpler to implement than PCM programmer's method, but definitely less efficient.
 
 
Matro | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		 | 
	
	
		  | 
	
	
		 |