Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] LPC2119 Pushbutton LEDs interface problems

Status
Not open for further replies.

karlwr

Newbie level 4
Joined
Nov 14, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
46
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 Register
 
int 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 input
while(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


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
include <LPC21xx.H>   // LPC2119 MPU Register
int main(void)
 {  
 PINSEL2 &= ~0x0000000C; // Makesure GPIO1.16-1.31 = GPIO Function, 
 PINSEL0 &= ~0x0000C000;  //GPIO P0.7,  
 IODIR1 |=((1<<16)|(1<<18));  // GPIO p1.18 and p1.16 as output
 IODIR0  &=~((1<<7)); // Set GPIO0.7 AS input
 
while(1) // Loop Continue
 {
if(!(IOPIN0 & (1<<7))) // When button is pressed 
{
  IOSET1 |=(1<<18);
  IOCLR1 |=(1<<16);
 }
  else 
 {
  IOSET1 |=(1<<16);
  IOCLR1 <=(1<<18); 
 }
}  
}



BR
 
Last edited by a moderator:

In the second code,in line(s) 12 and 15,you have written:
Code:
{
  IOSET1 |=(1<<18);
  IOCLR1 |=(1<<16);
 }

And in line(s) 17 and 20,you have written
Code:
{
  IOSET1 |=(1<<16);
  IOCLR1 <=(1<<18); 
 }

Instead of using <= in line no. 19,you should write it as:
Code:
IOCLR1 |=(1<<18);
That should work.Make this change,and try compiling the program again.
 

Not only. The IOCLR1 and IOSET1 are write only registers. You can't modify them after reading.
Code:
  IOSET1 = (1<<18);
  IOCLR1 = (1<<16);
 

In the second code,in line(s) 12 and 15,you have written:
Code:
{
  IOSET1 |=(1<<18);
  IOCLR1 |=(1<<16);
 }

And in line(s) 17 and 20,you have written
Code:
{
  IOSET1 |=(1<<16);
  IOCLR1 <=(1<<18); 
 }

Instead of using <= in line no. 19,you should write it as:
Code:
IOCLR1 |=(1<<18);
That should work.Make this change,and try compiling the program again.

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

But!! this still does not WORK!!!
Thanks anyway
 

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.
 

Hi guys and thanks for all the replies

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!?
 

so your telling me that Im not able to write to the register and clear the register at the same time?
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.
 

According to the datasheet page 135 https://www.keil.com/dd/docs/datashts/philips/user_manual_lpc2119_2129_2194_2292_2294.pdf

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.

There is no point to do a read-modify-write operation, just write ones to the bits you want to alter.
 

Oki guys, so you are telling me that insted of using

IO1SET |= (1<<16); I should use
IO1SET = 0x00010000;

I Think I tryed this but with the same results!
Im going to try this again when I get home and let you know!
Thanks for all the help guys
 
Last edited:

Hi guys, so i tried the pointers that you gave me and this does not work :(

This works
Code:
	if(!(IOPIN0 & (0x00000080)))	 // When button is pressed => IOPIN0 7 =1;
	    {
			IOCLR1 = (1<<16)|(1<<18);
	     }
	else 
	 	 {
		    IOSET1 = (1<<16)|(1<<18); 
		 }
But this does not work!!

Code:
if(!(IOPIN0 & (0x00000080)))	        // When button is pressed => IOPIN0 7 =1;
	    {
			IOSET1 = (1<<16)|(1<<18);
	     }
	else 
	 	 {
		    IOCLR1 = (1<<16)|(1<<18); 
		 }
This results in that both LEDs are allays on! apparently I cant do a IOSET in my if statement ?!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top