![]() | ![]() | ![]() |
| | #46 |
|
Jason: you can use a loop or for statement for that. But what it doesn't do is the flexibility of NOT setting / clearing any of the pins. IOSET = 0b10 for example doesn't change the value of the 0th pin. with your function, it will set the 0th pin to 0. now, that may or may not be the way you want it to be. for your code to work, you will have to know a) the pins you want to change, and b) the current value of the pins you do NOT wish to change. that means you need a read, an operation, and then your port write. it may be more pain than it is worth, .
| |
| |
| | #47 |
| Code: IOCLR = 0xFFFF FFFE ;P0.0 goes LOW | |
| |
| | #48 |
|
Ill try to make a nice loop now lol
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #49 |
| oops lol backwards me lol
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #50 |
|
"IOSET = 0b10 for example doesn't change the value of the 0th pin. with your function, it will set the 0th pin to 0." That wont change the 0th pin.
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #51 |
|
Wouldnt this just set or clear the pins from p0.0 to p0.7 Code: void ChangePortA(unsigned char NewVal){
char x;
char y;
for(x=0;x<8;x++){
y = 0x00000001 << x;
if(NewVal & 0x01)
IO0SET = y; //P0.y goes HIGH
else
IOCLR = y; //P0.y goes LOW
NewVal >>= 1;
}
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 22nd June 2009 at 11:03 PM. | |
| |
| | #52 | ||
|
millwood: Quote:
Quote:
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |||
| |
| | #53 |
|
"That wont change the 0th pin." you are right and i was wrong: it would set the 1st pin to 1 and do nothing to the 0th pin. yes, the port latency (from the time you write tot he port to the time the port actually changes value) is about 14+ cycles, as I read somewhere. | |
| |
| | #54 |
|
yeah so i was reading more and found out i can do this: Code: void ChangePortA(char port, unsigned char NewVal){
if(port == 0)
IO0PIN = (IO0PIN && 0xFFFFFF00 ) || NewVal;
if(port == 1)
IO0PIN = (IO0PIN && 0xFFFF00FF ) || NewVal;
if(port == 2)
IO0PIN = (IO0PIN && 0xFF00FFFF ) || NewVal;
if(port == 3)
IO0PIN = (IO0PIN && 0x00FFFFFF ) || NewVal;
}
Page 92 : "8.5.2 Example 2: an immediate output of 0s and 1s on a GPIO port" LPC214x manual
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 22nd June 2009 at 11:17 PM. | |
| |
| | #55 |
| yea. you meant to use IO0CLR, I think.
| |
| |
| | #56 |
|
I can also just do this for faster: Code: void ChangePortA(char port, unsigned long NewVal){
if(port == 0){
FIO0MASK = 0xFFFFFF00;
FIO0PIN = NewVal;
}
if(port == 1){
FIO0MASK = 0xFFFF00FF;
FIO0PIN = (NewVal << 8);
}
if(port == 2){
FIO0MASK = 0xFF00FFFF;
FIO0PIN = (NewVal << 16);
}
if(port == 3){
FIO0MASK = 0x00FFFFFF;
FIO0PIN = (NewVal << 24);
}
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 22nd June 2009 at 11:24 PM. | |
| |
| | #57 |
|
The SAM7 has got different names for everything, but ya, you can directly set the GPIO pins as well, as long as you manage the associated mask not to set anything else as well.
__________________ Mark Higgins | |
| |
| | #58 |
|
i tried this for the 2106 but no luck i get a CPU error in Protues: Code: #include <LPC210x.h>
void ChangePortA(char port, unsigned long NewVal){
if(port == 0)
IOPIN = (IOPIN && 0xFFFFFF00 ) || NewVal;
if(port == 1)
IOPIN = (IOPIN && 0xFFFF00FF ) || (NewVal << 8);
if(port == 2)
IOPIN = (IOPIN && 0xFF00FFFF ) || (NewVal << 16);
if(port == 3)
IOPIN = (IOPIN && 0x00FFFFFF ) || (NewVal << 24);
}
void DelayUs(int us) {
for (; us>0; us--);
}
void DelayMs(int ms) {
for (; ms>0; ms--)
DelayUs(1000);
}
int main(void){
unsigned char x;
PINSEL0=0x00;
IODIR=0xff;
while(1){
for(x=0;x<8;x++){
ChangePortA(0,x);
DelayMs(1000);
}
}
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 23rd June 2009 at 12:03 AM. | |
| |
| | #59 |
|
This works nice! Code: for(x=0;x<31;x++){
IOPIN = (0x00000001 << x);
DelayMs(500);
}
Code: void ChangePortA(char port, unsigned long NewVal){
if(port == 0)
IOPIN = ((IOPIN & 0xFFFFFF00 ) | NewVal);
if(port == 1)
IOPIN = (IOPIN & 0xFFFF00FF ) | (NewVal << 8);
if(port == 2)
IOPIN = (IOPIN & 0xFF00FFFF ) | (NewVal << 16);
if(port == 3)
IOPIN = (IOPIN & 0x00FFFFFF ) | (NewVal << 24);
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 23rd June 2009 at 12:10 AM. | |
| |
| | #60 |
|
unrolling a short loop will definitely make it faster.
| |
| |
|
| Tags |
| arm, cortex |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| ARM Cortex Microcontrollers? | dknguyen | Micro Controllers | 0 | 10th February 2009 12:37 AM |
| ARM Cortex-M3 DSP | dknguyen | Micro Controllers | 1 | 2nd February 2009 04:47 PM |