  | 
	  | 
		 
	 
	
		| View previous topic :: View next topic   | 
	 
	
	
		| Author | 
		Message | 
	 
	
		
			dongseong Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Bit control | 
			 
			
				 Posted: Sun Oct 06, 2002 11:45 am     | 
				     | 
			 
			
				
  | 
			 
			
				Hello,
 
 
I modified my code, but it doesn't work at all.
 
Could you please whay the problem is?
 
 
Before)
 
output_high(PIN_C2);
 
output_high(PIN_C5);
 
output_high(PIN_B0);
 
output_high(PIN_B1); // all these worked well.
 
 
After)
 
int *LED[4];
 
int i;
 
 
LED[0] = 58; //actual bit address of PIN_C2
 
LED[1] = 61; //actual bit address of PIN_C5
 
LED[2] = 48; //actual bit address of PIN_B0
 
LED[3] = 49; //actual bit address of PIN_B1
 
 
for(i=0; i<4; i++)
 
{ *LED[i] = 1; } // This doesn't work.
 
 
If my trial is fundermantally wrong, what will the way
 
to control each bits by relative addressing?
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 7481 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			matt maberino Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: Bit control | 
			 
			
				 Posted: Sun Oct 06, 2002 2:16 pm     | 
				     | 
			 
			
				
  | 
			 
			
				:=Hello,
 
:=
 
:=I modified my code, but it doesn't work at all.
 
:=Could you please whay the problem is?
 
:=
 
:=Before)
 
:=output_high(PIN_C2);
 
:=output_high(PIN_C5);
 
:=output_high(PIN_B0);
 
:=output_high(PIN_B1); // all these worked well.
 
:=
 
:=After)
 
:=int *LED[4];
 
:=int i;
 
:=
 
:=LED[0] = 58; //actual bit address of PIN_C2
 
:=LED[1] = 61; //actual bit address of PIN_C5
 
:=LED[2] = 48; //actual bit address of PIN_B0
 
:=LED[3] = 49; //actual bit address of PIN_B1
 
:=
 
:=for(i=0; i<4; i++)
 
:={ *LED[i] = 1; } // This doesn't work.
 
:=
 
:=If my trial is fundermantally wrong, what will the way
 
:=to control each bits by relative addressing?
 
:=
 
:=
 
 
i like this code, i haven't had a chance to check it, but my first instinct is to suspect the tris register's
 
- matt
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 7490 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			dongseong Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: Bit control | 
			 
			
				 Posted: Sun Oct 06, 2002 2:34 pm     | 
				     | 
			 
			
				
  | 
			 
			
				:=:=Hello,
 
:=:=
 
:=:=I modified my code, but it doesn't work at all.
 
:=:=Could you please explaine me what the problem is?
 
:=:=
 
:=:=Before)
 
:=:=output_high(PIN_C2);
 
:=:=output_high(PIN_C5);
 
:=:=output_high(PIN_B0);
 
:=:=output_high(PIN_B1); // all these worked well.
 
:=:=
 
:=:=After)
 
:=:=int *LED[4];
 
:=:=int i;
 
:=:=
 
:=:=LED[0] = 58; //actual bit address of PIN_C2
 
:=:=LED[1] = 61; //actual bit address of PIN_C5
 
:=:=LED[2] = 48; //actual bit address of PIN_B0
 
:=:=LED[3] = 49; //actual bit address of PIN_B1
 
:=:=
 
:=:=for(i=0; i<4; i++)
 
:=:={ *LED[i] = 1; } // This doesn't work.
 
:=:=
 
:=:=If my trial is fundermantally wrong, what will the way
 
:=:=to control each bits by relative addressing?
 
:=:=
 
:=:=
 
:=
 
:=i like this code, i haven't had a chance to check it, but my first instinct is to suspect the tris register's
 
:=- matt
 
 
Thanks for quick response!
 
 
My set_tris() are for all output
 
 
set_tris_b(0);
 
set_tris_c(0);
 
 
Regards
 
Dong
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 7492 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			R.J.Hamlett Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: Bit control | 
			 
			
				 Posted: Sun Oct 06, 2002 2:48 pm     | 
				     | 
			 
			
				
  | 
			 
			
				:=Hello,
 
:=
 
:=I modified my code, but it doesn't work at all.
 
:=Could you please whay the problem is?
 
:=
 
:=Before)
 
:=output_high(PIN_C2);
 
:=output_high(PIN_C5);
 
:=output_high(PIN_B0);
 
:=output_high(PIN_B1); // all these worked well.
 
:=
 
:=After)
 
:=int *LED[4];
 
:=int i;
 
:=
 
:=LED[0] = 58; //actual bit address of PIN_C2
 
:=LED[1] = 61; //actual bit address of PIN_C5
 
:=LED[2] = 48; //actual bit address of PIN_B0
 
:=LED[3] = 49; //actual bit address of PIN_B1
 
:=
 
:=for(i=0; i<4; i++)
 
:={ *LED[i] = 1; } // This doesn't work.
 
:=
 
:=If my trial is fundermantally wrong, what will the way
 
:=to control each bits by relative addressing?
 
Start with the simple statement from the manual:
 
"Arrays of SHORT, and pointers to SHORT are not permitted". The bits are shorts, and you are trying to use the numbers as pointer, so what you have will not work. You would end up setting the memory addresses 58,61,48 & 49 to 1...
 
There are several ways to get close to this, but none with the array quite as shown. One method, would be something like:
 
#define SET_BIT(x) = BIT_SET(*(x >> 3),x & 7)
 
 
Then:
 
   SET_BIT(LED[i]);
 
 
should work.
 
This is based on the fact that the memory address of the port register is stored shifted left 3 bits in the numbers given by the normal defines, and the bit number, is the low three bits. Hence the 'SET_BIT' declaration, will remove the bottom three bits, and use this as the address of the register to be updated, then get the bit number from the low three bits, and do the actual 'set'.
 
 
Best Wishes
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 7493 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			johnpcunningham Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: Bit control | 
			 
			
				 Posted: Sun Oct 06, 2002 2:54 pm     | 
				     | 
			 
			
				
  | 
			 
			
				<font face="Courier New" size=-1>:=Hello,
 
:=
 
:=I modified my code, but it doesn't work at all.
 
:=Could you please whay the problem is?
 
:=
 
:=Before)
 
:=output_high(PIN_C2);
 
:=output_high(PIN_C5);
 
:=output_high(PIN_B0);
 
:=output_high(PIN_B1); // all these worked well.
 
:=
 
:=After)
 
:=int *LED[4];
 
:=int i;
 
:=
 
:=LED[0] = 58; //actual bit address of PIN_C2
 
:=LED[1] = 61; //actual bit address of PIN_C5
 
:=LED[2] = 48; //actual bit address of PIN_B0
 
:=LED[3] = 49; //actual bit address of PIN_B1
 
:=
 
:=for(i=0; i<4; i++)
 
:={ *LED[i] = 1; } // This doesn't work.
 
:=
 
:=If my trial is fundermantally wrong, what will the way
 
:=to control each bits by relative addressing?
 
:=
 
:=
 
 
You are modifying a register, not the output pin. WHen you did this:
 
 
LED[0] = 58; 
 
LED[1] = 61; 
 
LED[2] = 48; 
 
LED[3] = 49; 
 
 
All you did was initialize 4 indexed variables to 58, 61, 48, and 49........not the addresses
 
 
If you want to output to the port directly, then you need to write to the PORTB register itself.  Use a #byte statement to define the PICs register map and then you can address it directly.  Here is an example for you:
 
 
// MEMORY LOCATIONS FOR EACH REGISTER (if needed)//
 
#byte   INDF    =     0x0000
 
#byte   TMR0    =     0x0001
 
#byte   PCL     =     0x0002
 
#byte   STATUS  =     0x0003
 
#byte   FSR     =     0x0004
 
#byte   PORTA   =     0x0005
 
#byte   PORTB   =     0x0006
 
#byte   PORTC   =     0x0007
 
#byte   PORTD   =     0x0008
 
#byte   PORTE   =     0x0009
 
#byte   PCLATH  =     0x000A
 
#byte   INTCON  =     0x000B
 
#byte   PIR1    =     0x000C
 
#byte   PIR2    =     0x000D
 
#byte   TMR1L   =     0x000E
 
#byte   TMR1H   =     0x000F
 
#byte   T1CON   =     0x0010
 
#byte   TMR2    =     0x0011
 
#byte   T2CON   =     0x0012
 
#byte   SSPBUF  =     0x0013
 
#byte   SSPCON  =     0x0014
 
#byte   CCPR1L  =     0x0015
 
#byte   CCPR1H  =     0x0016
 
#byte   CCP1CON =     0x0017
 
#byte   RCSTA   =     0x0018
 
#byte   TXREG   =     0x0019
 
#byte   RCREG   =     0x001A
 
#byte   CCPR2L  =     0x001B
 
#byte   CCPR2H  =     0x001C
 
#byte   CCP2CON =     0x001D
 
#byte   ADRESH  =     0x001E
 
#byte   ADCON0  =     0x001F
 
 
#byte   OPTION_REG  =     0x0081
 
#byte   TRISA       =     0x0085
 
#byte   TRISB   =     0x0086
 
#byte   TRISC   =     0x0087
 
#byte   TRISD   =     0x0088
 
#byte   TRISE   =     0x0089
 
#byte   PIE1    =     0x008C
 
#byte   PIE2    =     0x008D
 
#byte   PCON    =     0x008E
 
#byte   SSPCON2 =     0x0091
 
#byte   PR2     =     0x0092
 
#byte   SSPADD  =     0x0093
 
#byte   SSPSTAT =     0x0094
 
#byte   TXSTA   =     0x0098
 
#byte   SPBRG   =     0x0099
 
#byte   ADRESL  =     0x009E
 
#byte   ADCON1  =     0x009F
 
 
#byte   EEDATA  =     0x010C
 
#byte   EEADR   =     0x010D
 
#byte   EEDATH  =     0x010E
 
#byte   EEADRH  =     0x010F
 
 
#byte   EECON1  =     0x018C
 
#byte   EECON2  =     0x018D
 
 
//PORT B conntections//
 
#define LED0     PIN_B0
 
#define LED1     PIN_B1
 
#define LED2     PIN_B2
 
 
 
void main (){
 
//init the port
 
set_tris_b(0x00);
 
PORTB = 0xFF;
 
delay_us(100);
 
 
//turn off leds with direct port access (lower bits)
 
PORTB = (PORTB & 0xFF);
 
delay_us(100);
 
 
//turn on leds with direct port access (lower bits)
 
PORTB = (PORTB | 0xF8);
 
 
//turn off leds with direct bit access 
 
output_high(LED0);
 
output_high(LED1); 
 
output_high(LED2); 
 
delay_us(100);
 
 
//turn off leds with direct bit access 
 
output_low(LED0);
 
output_low(LED1); 
 
output_low(LED2); 
 
delay_us(100);
 
 
while(1){}
 
}
 
 
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 7495 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			dongseong Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: Bit control | 
			 
			
				 Posted: Sun Oct 06, 2002 7:13 pm     | 
				     | 
			 
			
				
  | 
			 
			
				:=:=Hello,
 
:=:=
 
:=:=I modified my code, but it doesn't work at all.
 
:=:=Could you please whay the problem is?
 
:=:=
 
:=:=Before)
 
:=:=output_high(PIN_C2);
 
:=:=output_high(PIN_C5);
 
:=:=output_high(PIN_B0);
 
:=:=output_high(PIN_B1); // all these worked well.
 
:=:=
 
:=:=After)
 
:=:=int *LED[4];
 
:=:=int i;
 
:=:=
 
:=:=LED[0] = 58; //actual bit address of PIN_C2
 
:=:=LED[1] = 61; //actual bit address of PIN_C5
 
:=:=LED[2] = 48; //actual bit address of PIN_B0
 
:=:=LED[3] = 49; //actual bit address of PIN_B1
 
:=:=
 
:=:=for(i=0; i<4; i++)
 
:=:={ *LED[i] = 1; } // This doesn't work.
 
:=:=
 
:=:=If my trial is fundermantally wrong, what will the way
 
:=:=to control each bits by relative addressing?
 
:=Start with the simple statement from the manual:
 
:="Arrays of SHORT, and pointers to SHORT are not permitted". The bits are shorts, and you are trying to use the numbers as pointer, so what you have will not work. You would end up setting the memory addresses 58,61,48 & 49 to 1...
 
:=There are several ways to get close to this, but none with the array quite as shown. One method, would be something like:
 
:=#define SET_BIT(x) = BIT_SET(*(x >> 3),x & 7)
 
:=
 
:=Then:
 
:=   SET_BIT(LED[i]);
 
:=
 
:=should work.
 
:=This is based on the fact that the memory address of the port register is stored shifted left 3 bits in the numbers given by the normal defines, and the bit number, is the low three bits. Hence the 'SET_BIT' declaration, will remove the bottom three bits, and use this as the address of the register to be updated, then get the bit number from the low three bits, and do the actual 'set'.
 
:=
 
:=Best Wishes
 
 
Hi, Thanks for the answer.
 
 
However, my problem has'n been solved yet.
 
 
To isolate other effects, I worte
 
 
BIT_SET(*(7 >> 3),1 & 7); //in order to turn on PORTC bit 1,
 
                          //but it didn't work, and 
 
 
BIT_SET(*7, 1); // as manual recommends, but
 
                // din't work either. Manual didn't talk about
 
                // 3 bits shifting
 
 
Since 
 
output_high(PIN_C1); always work, I believe others,
 
including my hardware and TRIS are OK.
 
 
The purpose of this is to use bit controls inside
 
for loop, without repeating output_high() function.
 
 
Is there any other way to do it?
 
 
Best regards
 
Dong
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 7509 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			Mark
 
 
  Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA 
			
			 
			 
			 
			
			
			
			
			
			
  
		  | 
		
			
				| Re: Bit control | 
			 
			
				 Posted: Sun Oct 06, 2002 7:44 pm     | 
				     | 
			 
			
				
  | 
			 
			
				:=:=:=Hello,
 
:=:=:=
 
Take a look at the following listings.  The first uses fast_io.
 
 
.................... #device PIC16F876 
 
.................... #list 
 
.................... 
 
....................  
 
.................... #use fast_io(C) 
 
....................  
 
.................... void main(void) 
 
.................... { 
 
0004:  CLRF   04
 
*
 
0007:  SLEEP
 
....................   bit_set(*7,1); 
 
*
 
0005:  BSF    07,1
 
....................   output_high(PIN_C1); 
 
0006:  BSF    07,1
 
.................... } 
 
 
 
The next one does not use fast_io
 
 
.................... #device PIC16F876 
 
.................... #list 
 
.................... 
 
....................  
 
....................  
 
.................... void main(void) 
 
.................... { 
 
0004:  CLRF   04
 
0005:  MOVLW  FF
 
0006:  MOVWF  20
 
*
 
000E:  SLEEP
 
....................   bit_set(*7,1); 
 
*
 
0007:  BSF    07,1
 
....................   output_high(PIN_C1); 
 
0008:  BCF    20,1
 
0009:  MOVF   20,W
 
000A:  BSF    03,5
 
000B:  MOVWF  07
 
000C:  BCF    03,5
 
000D:  BSF    07,1
 
.................... } 
 
 
 
Notice in the second one, the compiler handles setting of the tris register.  If output_high(PIN_C1) does not function the same as bit_set(*7,1) then you probably do not have the tris registers setup correctly.  You can prove/disprove this by adding the #use fast_io(C) to you code and see if the output_high(PIN_C1) still functions.  You should post more of you code (including the setting up of the tris registers) for more help.
 
 
If you are trying to save code space by using a for loop to set a few pins high, then take a look at this listing.  It takes less code just to set them.
 
 
....................   for(i=0;1<4;i++) 
 
*
 
0005:  CLRF   21
 
....................   { 
 
....................     bit_set(*7,i); 
 
0006:  MOVLW  01
 
0007:  MOVWF  77
 
0008:  MOVF   21,W
 
0009:  MOVWF  78
 
000A:  BTFSC  03,2
 
000B:  GOTO   010
 
000C:  BCF    03,0
 
000D:  RLF    77,F
 
000E:  DECFSZ 78,F
 
000F:  GOTO   00C
 
0010:  MOVF   77,W
 
0011:  IORWF  07,F
 
....................   } 
 
0012:  INCF   21,F
 
0013:  GOTO   006
 
....................  
 
....................   output_high(PIN_C0); 
 
0014:  BSF    07,0
 
....................   output_high(PIN_C1); 
 
0015:  BSF    07,1
 
....................   output_high(PIN_C2); 
 
0016:  BSF    07,2
 
....................   output_high(PIN_C3); 
 
0017:  BSF    07,3
 
 
 
 
regards,
 
Mark
 
 
 
 
 
 
 
 
:=:=:=I modified my code, but it doesn't work at all.
 
:=:=:=Could you please whay the problem is?
 
:=:=:=
 
:=:=:=Before)
 
:=:=:=output_high(PIN_C2);
 
:=:=:=output_high(PIN_C5);
 
:=:=:=output_high(PIN_B0);
 
:=:=:=output_high(PIN_B1); // all these worked well.
 
:=:=:=
 
:=:=:=After)
 
:=:=:=int *LED[4];
 
:=:=:=int i;
 
:=:=:=
 
:=:=:=LED[0] = 58; //actual bit address of PIN_C2
 
:=:=:=LED[1] = 61; //actual bit address of PIN_C5
 
:=:=:=LED[2] = 48; //actual bit address of PIN_B0
 
:=:=:=LED[3] = 49; //actual bit address of PIN_B1
 
:=:=:=
 
:=:=:=for(i=0; i<4; i++)
 
:=:=:={ *LED[i] = 1; } // This doesn't work.
 
:=:=:=
 
:=:=:=If my trial is fundermantally wrong, what will the way
 
:=:=:=to control each bits by relative addressing?
 
:=:=Start with the simple statement from the manual:
 
:=:="Arrays of SHORT, and pointers to SHORT are not permitted". The bits are shorts, and you are trying to use the numbers as pointer, so what you have will not work. You would end up setting the memory addresses 58,61,48 & 49 to 1...
 
:=:=There are several ways to get close to this, but none with the array quite as shown. One method, would be something like:
 
:=:=#define SET_BIT(x) = BIT_SET(*(x >> 3),x & 7)
 
:=:=
 
:=:=Then:
 
:=:=   SET_BIT(LED[i]);
 
:=:=
 
:=:=should work.
 
:=:=This is based on the fact that the memory address of the port register is stored shifted left 3 bits in the numbers given by the normal defines, and the bit number, is the low three bits. Hence the 'SET_BIT' declaration, will remove the bottom three bits, and use this as the address of the register to be updated, then get the bit number from the low three bits, and do the actual 'set'.
 
:=:=
 
:=:=Best Wishes
 
:=
 
:=Hi, Thanks for the answer.
 
:=
 
:=However, my problem has'n been solved yet.
 
:=
 
:=To isolate other effects, I worte
 
:=
 
:=BIT_SET(*(7 >> 3),1 & 7); //in order to turn on PORTC bit 1,
 
:=                          //but it didn't work, and 
 
:=
 
:=BIT_SET(*7, 1); // as manual recommends, but
 
:=                // din't work either. Manual didn't talk about
 
:=                // 3 bits shifting
 
:=
 
:=Since 
 
:=output_high(PIN_C1); always work, I believe others,
 
:=including my hardware and TRIS are OK.
 
:=
 
:=The purpose of this is to use bit controls inside
 
:=for loop, without repeating output_high() function.
 
:=
 
:=Is there any other way to do it?
 
:=
 
:=Best regards
 
:=Dong
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 7510 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			dongseong Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: Bit control | 
			 
			
				 Posted: Sun Oct 06, 2002 10:38 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Hello,
 
 
Finally, bit_set() started to work, and I successfully
 
controled 8 LEDs on PORTC with for-loop as follows;
 
(I don't know the difference of previous and now...anyway)
 
 
for(i=0; i<8, i++)
 
{ bit_set(*7,i);
 
  delay_ms(500);
 
  bit_clear(*7,i);
 
  delay_ms(500); }
 
 
I appreciated your very detailed explanation.
 
 
Thanks so much...
 
Dong
 
 
 
 
:=:=:=:=Hello,
 
:=:=:=:=
 
:=Take a look at the following listings.  The first uses fast_io.
 
:=
 
:=.................... #device PIC16F876 
 
:=.................... #list 
 
:=.................... 
 
:=....................  
 
:=.................... #use fast_io(C) 
 
:=....................  
 
:=.................... void main(void) 
 
:=.................... { 
 
:=0004:  CLRF   04
 
:=*
 
:=0007:  SLEEP
 
:=....................   bit_set(*7,1); 
 
:=*
 
:=0005:  BSF    07,1
 
:=....................   output_high(PIN_C1); 
 
:=0006:  BSF    07,1
 
:=.................... } 
 
:=
 
:=
 
:=The next one does not use fast_io
 
:=
 
:=.................... #device PIC16F876 
 
:=.................... #list 
 
:=.................... 
 
:=....................  
 
:=....................  
 
:=.................... void main(void) 
 
:=.................... { 
 
:=0004:  CLRF   04
 
:=0005:  MOVLW  FF
 
:=0006:  MOVWF  20
 
:=*
 
:=000E:  SLEEP
 
:=....................   bit_set(*7,1); 
 
:=*
 
:=0007:  BSF    07,1
 
:=....................   output_high(PIN_C1); 
 
:=0008:  BCF    20,1
 
:=0009:  MOVF   20,W
 
:=000A:  BSF    03,5
 
:=000B:  MOVWF  07
 
:=000C:  BCF    03,5
 
:=000D:  BSF    07,1
 
:=.................... } 
 
:=
 
:=
 
:=Notice in the second one, the compiler handles setting of the tris register.  If output_high(PIN_C1) does not function the same as bit_set(*7,1) then you probably do not have the tris registers setup correctly.  You can prove/disprove this by adding the #use fast_io(C) to you code and see if the output_high(PIN_C1) still functions.  You should post more of you code (including the setting up of the tris registers) for more help.
 
:=
 
:=If you are trying to save code space by using a for loop to set a few pins high, then take a look at this listing.  It takes less code just to set them.
 
:=
 
:=....................   for(i=0;1<4;i++) 
 
:=*
 
:=0005:  CLRF   21
 
:=....................   { 
 
:=....................     bit_set(*7,i); 
 
:=0006:  MOVLW  01
 
:=0007:  MOVWF  77
 
:=0008:  MOVF   21,W
 
:=0009:  MOVWF  78
 
:=000A:  BTFSC  03,2
 
:=000B:  GOTO   010
 
:=000C:  BCF    03,0
 
:=000D:  RLF    77,F
 
:=000E:  DECFSZ 78,F
 
:=000F:  GOTO   00C
 
:=0010:  MOVF   77,W
 
:=0011:  IORWF  07,F
 
:=....................   } 
 
:=0012:  INCF   21,F
 
:=0013:  GOTO   006
 
:=....................  
 
:=....................   output_high(PIN_C0); 
 
:=0014:  BSF    07,0
 
:=....................   output_high(PIN_C1); 
 
:=0015:  BSF    07,1
 
:=....................   output_high(PIN_C2); 
 
:=0016:  BSF    07,2
 
:=....................   output_high(PIN_C3); 
 
:=0017:  BSF    07,3
 
:=
 
:=
 
:=
 
:=regards,
 
:=Mark
 
:=
 
:=
 
:=
 
:=
 
:=
 
:=
 
:=
 
:=:=:=:=I modified my code, but it doesn't work at all.
 
:=:=:=:=Could you please whay the problem is?
 
:=:=:=:=
 
:=:=:=:=Before)
 
:=:=:=:=output_high(PIN_C2);
 
:=:=:=:=output_high(PIN_C5);
 
:=:=:=:=output_high(PIN_B0);
 
:=:=:=:=output_high(PIN_B1); // all these worked well.
 
:=:=:=:=
 
:=:=:=:=After)
 
:=:=:=:=int *LED[4];
 
:=:=:=:=int i;
 
:=:=:=:=
 
:=:=:=:=LED[0] = 58; //actual bit address of PIN_C2
 
:=:=:=:=LED[1] = 61; //actual bit address of PIN_C5
 
:=:=:=:=LED[2] = 48; //actual bit address of PIN_B0
 
:=:=:=:=LED[3] = 49; //actual bit address of PIN_B1
 
:=:=:=:=
 
:=:=:=:=for(i=0; i<4; i++)
 
:=:=:=:={ *LED[i] = 1; } // This doesn't work.
 
:=:=:=:=
 
:=:=:=:=If my trial is fundermantally wrong, what will the way
 
:=:=:=:=to control each bits by relative addressing?
 
:=:=:=Start with the simple statement from the manual:
 
:=:=:="Arrays of SHORT, and pointers to SHORT are not permitted". The bits are shorts, and you are trying to use the numbers as pointer, so what you have will not work. You would end up setting the memory addresses 58,61,48 & 49 to 1...
 
:=:=:=There are several ways to get close to this, but none with the array quite as shown. One method, would be something like:
 
:=:=:=#define SET_BIT(x) = BIT_SET(*(x >> 3),x & 7)
 
:=:=:=
 
:=:=:=Then:
 
:=:=:=   SET_BIT(LED[i]);
 
:=:=:=
 
:=:=:=should work.
 
:=:=:=This is based on the fact that the memory address of the port register is stored shifted left 3 bits in the numbers given by the normal defines, and the bit number, is the low three bits. Hence the 'SET_BIT' declaration, will remove the bottom three bits, and use this as the address of the register to be updated, then get the bit number from the low three bits, and do the actual 'set'.
 
:=:=:=
 
:=:=:=Best Wishes
 
:=:=
 
:=:=Hi, Thanks for the answer.
 
:=:=
 
:=:=However, my problem has'n been solved yet.
 
:=:=
 
:=:=To isolate other effects, I worte
 
:=:=
 
:=:=BIT_SET(*(7 >> 3),1 & 7); //in order to turn on PORTC bit 1,
 
:=:=                          //but it didn't work, and 
 
:=:=
 
:=:=BIT_SET(*7, 1); // as manual recommends, but
 
:=:=                // din't work either. Manual didn't talk about
 
:=:=                // 3 bits shifting
 
:=:=
 
:=:=Since 
 
:=:=output_high(PIN_C1); always work, I believe others,
 
:=:=including my hardware and TRIS are OK.
 
:=:=
 
:=:=The purpose of this is to use bit controls inside
 
:=:=for loop, without repeating output_high() function.
 
:=:=
 
:=:=Is there any other way to do it?
 
:=:=
 
:=:=Best regards
 
:=:=Dong
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 7512 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			R.J.Hamlett Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: Bit control | 
			 
			
				 Posted: Mon Oct 07, 2002 2:17 am     | 
				     | 
			 
			
				
  | 
			 
			
				:=:=:=Hello,
 
:=:=:=
 
:=:=:=I modified my code, but it doesn't work at all.
 
:=:=:=Could you please whay the problem is?
 
:=:=:=
 
:=:=:=Before)
 
:=:=:=output_high(PIN_C2);
 
:=:=:=output_high(PIN_C5);
 
:=:=:=output_high(PIN_B0);
 
:=:=:=output_high(PIN_B1); // all these worked well.
 
:=:=:=
 
:=:=:=After)
 
:=:=:=int *LED[4];
 
:=:=:=int i;
 
:=:=:=
 
:=:=:=LED[0] = 58; //actual bit address of PIN_C2
 
:=:=:=LED[1] = 61; //actual bit address of PIN_C5
 
:=:=:=LED[2] = 48; //actual bit address of PIN_B0
 
:=:=:=LED[3] = 49; //actual bit address of PIN_B1
 
:=:=:=
 
:=:=:=for(i=0; i<4; i++)
 
:=:=:={ *LED[i] = 1; } // This doesn't work.
 
:=:=:=
 
:=:=:=If my trial is fundermantally wrong, what will the way
 
:=:=:=to control each bits by relative addressing?
 
:=:=Start with the simple statement from the manual:
 
:=:="Arrays of SHORT, and pointers to SHORT are not permitted". The bits are shorts, and you are trying to use the numbers as pointer, so what you have will not work. You would end up setting the memory addresses 58,61,48 & 49 to 1...
 
:=:=There are several ways to get close to this, but none with the array quite as shown. One method, would be something like:
 
:=:=#define SET_BIT(x) = BIT_SET(*(x >> 3),x & 7)
 
:=:=
 
:=:=Then:
 
:=:=   SET_BIT(LED[i]);
 
:=:=
 
:=:=should work.
 
:=:=This is based on the fact that the memory address of the port register is stored shifted left 3 bits in the numbers given by the normal defines, and the bit number, is the low three bits. Hence the 'SET_BIT' declaration, will remove the bottom three bits, and use this as the address of the register to be updated, then get the bit number from the low three bits, and do the actual 'set'.
 
:=:=
 
:=:=Best Wishes
 
:=
 
:=Hi, Thanks for the answer.
 
:=
 
:=However, my problem has'n been solved yet.
 
:=
 
:=To isolate other effects, I worte
 
:=
 
:=BIT_SET(*(7 >> 3),1 & 7); //in order to turn on PORTC bit 1,
 
:=                          //but it didn't work, and 
 
:=
 
:=BIT_SET(*7, 1); // as manual recommends, but
 
:=                // din't work either. Manual didn't talk about
 
:=                // 3 bits shifting
 
:=
 
:=Since 
 
:=output_high(PIN_C1); always work, I believe others,
 
:=including my hardware and TRIS are OK.
 
:=
 
:=The purpose of this is to use bit controls inside
 
:=for loop, without repeating output_high() function.
 
:=
 
:=Is there any other way to do it?
 
:=
 
:=Best regards
 
That won't work, because '7', is not the full address of bit C1. C1, is 57 from the defines. Try it with the values as given in your code allready (58, 59 etc.), and it will work. :-)
 
 
Best Wishes
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 7515 | 
			 
		  | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
	 
	    
	   | 
	
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
  
		 |