is there any quick way to access PINs except doing each on its owen?
like
for (i = 0; i < 6; i++)
RB_bit = 0xFF; ?
insted of
RB[1]_Bit = 0xFF;
RB[2]_Bit = 0xFF;
RB[3]_Bit = 0xFF;
RB[4]_Bit = 0xFF;
RB[5]_Bit = 0xFF;
........
i also tried to make a function to do that for me
but i couldnt decalre a bit array
bit arry[7];
compiler said "array of bit type objects is not allowed"
cheers;
is there a PIN Array by default?
-
- Posts: 619
- Joined: 05 Jul 2008 06:05
- Location: Thailand
Re: is there a PIN Array by default?
I can understand the logic behind your question but the compiler answered it very well! Bits can only be either 1 or 0, ports can only be In or Out, therefore you use these commands:
TRISB = (0b11110000) //Set Port B pin directions (4 input, 4 output)
//LATB = (0b11110000) //Set Port B pin directions (4 input, 4 output) //PIC18 series+
PORTB = (0b00001111) //Set Port B output values
Each binary bit corresponds to a Port pin.
These instances can be declared in hex, decimal or binary. Generally you use these commands at the beginning of your program but you can still change them in-program, not advisable though.
TRISB = (0b11110000) //Set Port B pin directions (4 input, 4 output)
//LATB = (0b11110000) //Set Port B pin directions (4 input, 4 output) //PIC18 series+
PORTB = (0b00001111) //Set Port B output values
Each binary bit corresponds to a Port pin.
These instances can be declared in hex, decimal or binary. Generally you use these commands at the beginning of your program but you can still change them in-program, not advisable though.
Re: is there a PIN Array by default?
thank you for ur reply
but i meant writing to pins, like light a LED on a pin or turn it off
but i meant writing to pins, like light a LED on a pin or turn it off
- ranko.rankovic
- Posts: 433
- Joined: 11 Jun 2010 09:22
Re: is there a PIN Array by default?
Hello Nameless,
You should consider our new compiler, mikroC PRO, and find explanation for sbit's in Help, those are meant exactly for your needs.
The mikroC PRO for PIC compiler has sbit data type which provides access to registers, SFRs, variables, etc.
You can declare a sbit varible in a unit in such way that it points to a specific bit in SFR register:In the main program you have to specify to which register this sbit points to, for example:
In this way the variable Abit will actually point to PORTB.0. Please note that we used the keyword sfr for declaration of Abit, because we are pointing it to PORTB which is defined as a sfr variable.
In case we want to declare a bit over a variable which is not defined as sfr, then the keyword sfr is not necessary, for example:
Also you could consider Migration Documents for easier adaption to our new compiler and its IDE. You will see how it's easy to use now compared to old one!
Hope this helped.
Best regards
You should consider our new compiler, mikroC PRO, and find explanation for sbit's in Help, those are meant exactly for your needs.
The mikroC PRO for PIC compiler has sbit data type which provides access to registers, SFRs, variables, etc.
You can declare a sbit varible in a unit in such way that it points to a specific bit in SFR register:
Code: Select all
extern sfr sbit Abit; // Abit is precisely defined in some external
// file, for example in the main program unit
Code: Select all
sbit Abit at PORTB.F0; // this is where Abit is fully defined
...
void main() {
...
}
In case we want to declare a bit over a variable which is not defined as sfr, then the keyword sfr is not necessary, for example:
Code: Select all
extern sbit AnotherBit; // AnotherBit is precisely defined in some external file,
//for example in the main program unit
char MyVar;
sbit AnotherBit at MyVar.F0; // this is where AnotherBit is fully defined
...
void main() {
...
}
Hope this helped.
Best regards
Ranko Rankovic
mikroElektronika [Support Department]
mikroElektronika [Support Department]
Re: is there a PIN Array by default?
im not sure if ur answer is even close to my question
i need a loop to go through all pins, and set the leds connected to them either to on or off
i need a loop to go through all pins, and set the leds connected to them either to on or off
- ranko.rankovic
- Posts: 433
- Joined: 11 Jun 2010 09:22
Re: is there a PIN Array by default?
Hello Nameless,
All I wanted with my previous post is to tell you how easier and more elegant is now with usage of sbits.
i.e.
RB1_bit instead of PORTB.F1
You can access individual bits like this:
Best regards
All I wanted with my previous post is to tell you how easier and more elegant is now with usage of sbits.
i.e.
RB1_bit instead of PORTB.F1
You can access individual bits like this:
Code: Select all
int i;
void main(){
TRISB = 0;
PORTB = 0;
for (i = 0; i < 8; i++){
PORTB |= 0x01 << i;
}
}
Ranko Rankovic
mikroElektronika [Support Department]
mikroElektronika [Support Department]