Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 22nd June 2009, 10:51 PM   #46
Default

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, .
millwood is offline  
Old 22nd June 2009, 10:52 PM   #47
Default

Code:
IOCLR = 0xFFFF FFFE    ;P0.0 goes LOW
that will clear all pins other than p0.0.
millwood is offline  
Old 22nd June 2009, 10:56 PM   #48
Default

Ill try to make a nice loop now lol
AtomSoft is offline  
Old 22nd June 2009, 10:56 PM   #49
Default

Quote:
Originally Posted by millwood View Post
Code:
IOCLR = 0xFFFF FFFE    ;P0.0 goes LOW
that will clear all pins other than p0.0.
oops lol backwards me lol
AtomSoft is offline  
Old 22nd June 2009, 10:58 PM   #50
Default

"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.
AtomSoft is offline  
Old 22nd June 2009, 11:01 PM   #51
Default

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;
    }
}

Last edited by AtomSoft; 22nd June 2009 at 11:03 PM.
AtomSoft is offline  
Old 22nd June 2009, 11:07 PM   #52
Default

millwood:
Quote:
Writing to IOSET/IOCLR .vs. IOPIN
Write to the IOSET/IOCLR register allows easy change of the port’s selected output pin(s)
to high/low level at a time. Only pin/bit(s) in the IOSET/IOCLR written with 1 will be set to
high/low level, while those written as 0 will remain unaffected. However, by just writing to
either IOSET or IOCLR register it is not possible to instantaneously output arbitrary binary
data containing mixture of 0s and 1s on a GPIO port.
maybe you where talking about :
Quote:
Write to the IOPIN register enables instantaneous output of a desired content on the
parallel GPIO. Binary data written into the IOPIN register will affect all output configured
pins of that parallel port: 0s in the IOPIN will produce low level pin outputs and 1s in IOPIN
will produce high level pin outputs. In order to change output of only a group of port’s pins,
application must logically AND readout from the IOPIN with mask containing 0s in bits
corresponding to pins that will be changed, and 1s for all others. Finally, this result has to
be logically ORred with the desired content and stored back into the IOPIN register.
Example 2 from above illustrates output of 0xA5 on PORT0 pins 15 to 8 while preserving
all other PORT0 output pins as they were before.
AtomSoft is offline  
Old 22nd June 2009, 11:15 PM   #53
Default

"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.
millwood is offline  
Old 22nd June 2009, 11:17 PM   #54
Default

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;
}
And doing that i can split the port into 4...

Page 92 : "8.5.2 Example 2: an immediate output of 0s and 1s on a GPIO port"

LPC214x manual

Last edited by AtomSoft; 22nd June 2009 at 11:17 PM.
AtomSoft is offline  
Old 22nd June 2009, 11:17 PM   #55
Default

Quote:
Originally Posted by AtomSoft View Post
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;
    }
}
yea. you meant to use IO0CLR, I think.
millwood is offline  
Old 22nd June 2009, 11:23 PM   #56
Default

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);
    }
}
Attached Thumbnails
ARM Cortex-clipboard02.jpg  

Last edited by AtomSoft; 22nd June 2009 at 11:24 PM.
AtomSoft is offline  
Old 22nd June 2009, 11:43 PM   #57
Default

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
DirtyLude is online now  
Old 22nd June 2009, 11:53 PM   #58
Default

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);
		}
	
	}

}
but doent seem to do anything...

Last edited by AtomSoft; 23rd June 2009 at 12:03 AM.
AtomSoft is offline  
Old 23rd June 2009, 12:05 AM   #59
Default

This works nice!
Code:
		for(x=0;x<31;x++){
			IOPIN  = (0x00000001 << x);
			DelayMs(500);
		}
im so dumb lol this works 100% ( i had it like "&&" and "||" lol
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);
}
This is nice because you can ultimately define and create your own ports. if you have a LCD with 6 pins then you can create the port with that and then not worry about OR'ing later

Last edited by AtomSoft; 23rd June 2009 at 12:10 AM.
AtomSoft is offline  
Old 23rd June 2009, 12:06 AM   #60
Default

unrolling a short loop will definitely make it faster.
millwood is offline  
Reply

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



All times are GMT. The time now is 07:34 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker