Arm Development - GPIO tutorial
Sat Dec 22 2007, 11:33 pm
consider the following example replace wait() with any delay routine....
this is a very simple code but tells the main differences between 51 and arm.....
we will discuss it further till then waiting for ur querries...... :bye
int main (void) { unsigned int j; /* LED var */ IODIR1 = 0xFF0000; /* P1.16..23 defined as Outputs */ init_timer(); while (1) { /* Loop forever */ for (j = 0x010000; j < 0x800000; j <<= 1) { /* Blink LED 0,1,2,3,4,5,6 */ IOSET1 = j; /* Turn on LED */ wait (); /* call wait function */ IOCLR1 = j; /* Turn off LED */ } for (j = 0x800000; j > 0x010000; j > > =1 ) { /* Blink LED 7,6,5,4,3,2,1 */ IOSET1 = j; /* Turn on LED */ wait (); /* call wait function */ IOCLR1 = j; /* Turn off LED */ } } }
this is a very simple code but tells the main differences between 51 and arm.....
we will discuss it further till then waiting for ur querries...... :bye
[ Edited Sun Dec 23 2007, 12:40 am ]
ajay_bhargav like this.
Sat Dec 22 2007, 11:38 pm
would you refer anything to read? anything specific..
about compiler and stuff..
about compiler and stuff..
Sat Dec 22 2007, 11:47 pm
Also i do not understand this...
and
code is really confusing.. :-s
can you give a little insight of various macros like
"IOSET1", "IOCLR1" what other options are there..
for (j = 0x010000; j < 0x800000; j <<= 1)
and
for (j = 0x800000; j > 0x010000; j > > =1 )
code is really confusing.. :-s
can you give a little insight of various macros like
"IOSET1", "IOCLR1" what other options are there..
Sat Dec 22 2007, 11:47 pm
is there any thing in the above code that u feel problem in....
if not then relax......
else practice bitwise operations... :-)
imp:
just download lpc2148 usermanual user.manual.lpc2141.lpc2142.lpc2144.lpc2146.lpc2148.pdf :-)
n
lpc-arm-book_srn.pdf
if not then relax......
else practice bitwise operations... :-)
imp:
just download lpc2148 usermanual user.manual.lpc2141.lpc2142.lpc2144.lpc2146.lpc2148.pdf :-)
n
lpc-arm-book_srn.pdf
ajay_bhargav, MATHIVANAN like this.
Sat Dec 22 2007, 11:52 pm
IOSETx
x can be 0 1 ur choice of port
x can be 0 1 ur choice of port
GPIO Port Output Set register. This register
controls the state of output pins in
conjunction with the IOCLR register. Writing
ones produces highs at the corresponding
port pins. Writing zeroes has no effect.
IOCLR GPIO Port Output Clear register. This
register controls the state of output pins.
Writing ones produces lows at the
corresponding port pins and clears the
corresponding bits in the IOSET register.
Writing zeroes has no effect.
Sat Dec 22 2007, 11:59 pm
so.. if i first make
IOCLR1 = 1; // this will make IO pin as 0
and then i make
IOSET1 = 1; // this will make IO pin as 1
So the status of IOCLR1 will also change? after writing 1 to IOSET1?
and vise-versa?
also in your code..
IODIR1 = 0xFF0000; //makes port 1 as o.p
but.. why last 2 byyes are kept 0? i mean..
why 0xFF0000 why not 0xFFFFFF
IOCLR1 = 1; // this will make IO pin as 0
and then i make
IOSET1 = 1; // this will make IO pin as 1
So the status of IOCLR1 will also change? after writing 1 to IOSET1?
and vise-versa?
also in your code..
IODIR1 = 0xFF0000; //makes port 1 as o.p
but.. why last 2 byyes are kept 0? i mean..
why 0xFF0000 why not 0xFFFFFF
Sun Dec 23 2007, 12:05 am
now for
well ARM do not have bit addressable registers
so u'll have to address the complete 32 bit registers.......
IOSET n IOCLR are both 32 bit registers....
the above code snippet says value of j will be sent to IOSET now in the IOSET register wherever there is a 1 there will be a high on the corresponding bit of the corresponding port...
ex.
IOSET1 =0x01 => P1.0 is high
IOSET1 = 0x02 => P1.1 high
IOSET1 = 0x03 => P1.0 and P1.1 are high
IOSET1 = 0x80000000 => P1.31 high ...........
important point.......
suppose the following sequence
IOSET1=0x01;
IOSET1 =0x00;
what is the output??
P1.1 is still high because Writing zeroes has no effect.
for (j = 0x010000; j < 0x800000; j <<= 1)
well ARM do not have bit addressable registers
so u'll have to address the complete 32 bit registers.......
IOSET n IOCLR are both 32 bit registers....
the above code snippet says value of j will be sent to IOSET now in the IOSET register wherever there is a 1 there will be a high on the corresponding bit of the corresponding port...
ex.
IOSET1 =0x01 => P1.0 is high
IOSET1 = 0x02 => P1.1 high
IOSET1 = 0x03 => P1.0 and P1.1 are high
IOSET1 = 0x80000000 => P1.31 high ...........
important point.......
suppose the following sequence
IOSET1=0x01;
IOSET1 =0x00;
what is the output??
P1.1 is still high because Writing zeroes has no effect.
ajay_bhargav like this.
Sun Dec 23 2007, 12:16 am
nope...........
change in IOSET has no effect in IOCLR or IODIR....
gud that u noticed.....
cause
when i say IODIR1 =0x001; => the last bit has been declared output...
so now IOSET1 = 0x0F; => only the last bit is high..... no effect on others.....
thus IODIR1 = 0xFF0000 => pins P1.24 - P1.31 are configured as output
interesting??? now we will discuss on one more 32 bit register IOPIN
before that ur doubts... :bye
MERGE:
yes u can read them any time in your code.....
change in IOSET has no effect in IOCLR or IODIR....
also in your code..
IODIR1 = 0xFF0000; //makes port 1 as o.p
but.. why last 2 byyes are kept 0? i mean..
why 0xFF0000 why not 0xFFFFFF
gud that u noticed.....
cause
when i say IODIR1 =0x001; => the last bit has been declared output...
so now IOSET1 = 0x0F; => only the last bit is high..... no effect on others.....
thus IODIR1 = 0xFF0000 => pins P1.24 - P1.31 are configured as output
interesting??? now we will discuss on one more 32 bit register IOPIN
before that ur doubts... :bye
MERGE:
yes u can read them any time in your code.....
[ Edited Sun Dec 23 2007, 12:32 am ]
ajay_bhargav like this.
Sun Dec 23 2007, 12:34 am
as you said about IODIR1..
so the number loaded has to be 4bytes..
i.e. 0xFF000000
instead of 0xFF0000
so the number loaded has to be 4bytes..
i.e. 0xFF000000
instead of 0xFF0000
Powered by e107 Forum System