Doubt in basic techniques

Hi to all, I am new to ARM world. Now i am trying with lpc2148. I have to write program for 4x4 keypad. So i thought to start with a single push button. i have written code for 16x2 LCD display. Now i am trying to type any char on keypad and display it on LCD. My LCD is working fine. I have written a code for single key. i ran that program and got no error. But when i debugging it the control does not enter in the coding. its stopped on SWI_Handler B SWI_Handler line.
Using my code i am trying to read
Here's my code

#include<lpc214x.h>
#include<stdio.h>

void delay(void);
//void keydetection(void);
unsigned int i,j,k;

int main()
{
IODIR0=0x00000000;//make all pins as input
PINSEL0=0x00000000;//make all pins as GPIO's
k=0x00000000;//make k as 32 bit variable

while(1)
{
IOSET0=0x00000001;//setting P0.0 pin as high
k=IOPIN0;//reading the states of P0.0 pin nd storn to k
printf("%d",k);
if(IOPIN0 && 0x00000001)//checkin P0.0 as high or not
IOSET0=0x00000011;//if its correct then P0.1 as high
delay();
IOCLR0=0x00000001;
k=IOPIN0;
printf("%d",k);
if(IOPIN0 && 0x00000000)
IOSET0=0x00000000;
delay();
}
}

void delay(void)
{
for(i=0;i<40000;i++)
{
;
}
}


Not only for this coding i am asking this doubt. My friends used to get this problem somany time. What this error exactly trying to say? What should i commenly do if i get this error? and whats the commen way to avoid this error?

Parents
  • This will always be true:

    if(IOPIN0 && 0x00000001)//checkin P0.0 as high or not
    


    If you want to test if a bit is set, then you do (note single & for bit-and instead of && for logic-and):

    if (IOPIN0 & 1) { ... }
    


    Where you replace 1 with (depending of bit to test) any of:
    1 or (1<<0) or 0x00000001
    2 or (1<<1) or 0x00000002
    4 or (1<<2) or 0x00000004
    ...

    This does not just set P0.1, it sets both P0.4 and P0.0.

    IOSET0=0x00000011;//if its correct then P0.1 as high
    


    Instead, you should just write:

    IOSET0 = 0x00000002;
    


    or

    IOSET0 = 2;
    


    or

    IOSET0 = 1<<1;
    

    This will never be true:

    if(IOPIN0 && 0x00000000)
    


    If you want to check if a bit is zero, do write:

    if ((IOPIN0 & 1) == 0) { ... }
    


    Where you replace 1 with (depending of bit to test) any of:
    1 or (1<<0) or 0x00000001
    2 or (1<<1) or 0x00000002
    4 or (1<<2) or 0x00000004
    ...

    You are aware that 0x is the start of a hexadecimal number, where each digit position can take the values 0..9 and a..f (or A..F). It is not the start of a binary number, where each digit is just 0 or 1.

    Your example above: 0x00000011 is the binary number
    0000 0000 0000 0000 0000 0000 0001 0001 or shorter
    10001 which is decimal 17 (1*(1<<4) + 1*(1<<0) = 1*16 + 1*1).

Reply
  • This will always be true:

    if(IOPIN0 && 0x00000001)//checkin P0.0 as high or not
    


    If you want to test if a bit is set, then you do (note single & for bit-and instead of && for logic-and):

    if (IOPIN0 & 1) { ... }
    


    Where you replace 1 with (depending of bit to test) any of:
    1 or (1<<0) or 0x00000001
    2 or (1<<1) or 0x00000002
    4 or (1<<2) or 0x00000004
    ...

    This does not just set P0.1, it sets both P0.4 and P0.0.

    IOSET0=0x00000011;//if its correct then P0.1 as high
    


    Instead, you should just write:

    IOSET0 = 0x00000002;
    


    or

    IOSET0 = 2;
    


    or

    IOSET0 = 1<<1;
    

    This will never be true:

    if(IOPIN0 && 0x00000000)
    


    If you want to check if a bit is zero, do write:

    if ((IOPIN0 & 1) == 0) { ... }
    


    Where you replace 1 with (depending of bit to test) any of:
    1 or (1<<0) or 0x00000001
    2 or (1<<1) or 0x00000002
    4 or (1<<2) or 0x00000004
    ...

    You are aware that 0x is the start of a hexadecimal number, where each digit position can take the values 0..9 and a..f (or A..F). It is not the start of a binary number, where each digit is just 0 or 1.

    Your example above: 0x00000011 is the binary number
    0000 0000 0000 0000 0000 0000 0001 0001 or shorter
    10001 which is decimal 17 (1*(1<<4) + 1*(1<<0) = 1*16 + 1*1).

Children
More questions in this forum