Content originally posted in LPCWare by PrakashPrasad on Wed Apr 02 02:00:00 MST 2014
Below is my code for which I have generated the hex file:
#include "lpc214x.h"
#define LED1 (1 << 10)
#define LED2 (1 << 11)
#define BUTTON1 (1 << 15)
#define BUTTON2 (1 << 16)
// Method prototypes
int getPinState(int pinNumber);
int main(void)
{
// Set buttons as input
PINSEL0 &= ~(BUTTON1 | BUTTON2);
// Set LEDs as output
PINSEL0 |= (LED1 | LED2);
// Turn both LEDS off (set them 'high')
IO0SET |= (LED1 | LED2);
while (1)
{
// Check if button 1 is pressed
// Released = 'High' (1)
// Pressed = 'Low' (1)
if (getPinState(15))
{
// Button1 is currently 'high'
// Turn LED1 off
IO0SET |= LED1;
}
else
{
// Button1 is currently 'Low'
// Turn LED1 on
IO0CLR |= LED1;
}
}
}
int getPinState(int pinNumber)
{
// Read the current state of all pins in GPIO block 0
int pinBlockState = IO0PIN;
// Read the value of 'pinNumber'
int pinState = (pinBlockState & (1 << pinNumber)) ? 1 : 0;
// Return the value of pinState
return pinState;
}
Also attached is my PROTEUS simulation model. But in PROTEUS I am getting error?