Hi all, I have a Little problem getting my LPC2119 to work as I want it to.
This is a very basic thing that I'm trying to do but I can't get it working
Im running a ET-ARM et-arm stamp lpc2119 with GNU arm compiler in µVision3
Im trying to interface a push button with 2LEDs. Using one LED works but not 2.
The compiler does not complain or give me an error.
Here is the code that works, a push button to p0.7 and a LED to p1.18
!
Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
include <LPC21xx.H>// LPC2119 MPU Registerint main(void){
PINSEL2 &= ~0x0000000C;// Makesure GPIO1.16-1.31 = GPIO Function,
PINSEL0 &= ~0x0000C000;//GPIO P0.7,
IODIR1 |=(1<<18);// GPIO 1.18 as output
IODIR0 &=~((1<<7));// Set GPIO0.7 AS inputwhile(1)// Loop Continue{if(!(IOPIN0 &(1<<7)))// When button is pressed {
IOSET1 |=(1<<18);}else{
IOCLR1 |=(1<<18);}
Here is the code that does not work, 2 LEDs on p1.16 and p1.18, and the push button on p0.7
Im trying to set that when the button is pressed LED1 on and LED2 off, when button not pressed then LED2 on and LED2 off but it only works as Before with one LED turning on and off, the second LED never turns off.!! . What is it that I'm missing
Hi Braw, I wrote the code from memory and did not coppy the real code so therefore i wrote wrong on IOCLR1 <=(1<<18), My code already has IOCLR1 |=(1<<18);
My compiler woldent had accepted <=(1<<18);
BitBang is a future that allow us to save at least 3 cycles while changing the register value. Direct write to BitBang register equal to read-modify-write usual register.
I don't get it, so your telling me that Im not able to write to the register and clear the register at the same time?
I have done this same exercise on other processors and it allays works!?
Who told you this? At the same time nothing can happens. You should understand how bitbang access works.
You can't use read-modify-write methode for bitbang register because you can't read them. It works only because reading them will give zeroes. So, logical 'or' with zeroes gives the same result.
IOSET:
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.