unsigned int volatile * const lpc_gpio1_dir_ptr = (unsigned int *) LPC_GPIO1->DIR
*lpc_gpio1_dir_ptr|= (1 << pinNumber);
But it does not work.
// ****************************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.40
// Date - 2013jul12hkt2040
// License - Free
// Hardware - Somy ARM Cortex M0 LPC1114/301 Learning Board
// Software - Keil uVision 4.71.2.0 ARM CC
// Method - Incremental testing
// Hardware configuration notes
// 1. LED1 is connected to PIO1-8
// ****************************************************************************
#include <stdio.h>
#include "LPC11xx.h"
#include "timer.h"
void setPortPinDirection(int portNumber, int pinNumber)
{
unsigned int volatile * const lpc_gpio1_dir_ptr = (unsigned int *) LPC_GPIO1-
>DIR;
switch( portNumber )
{
case 1:
LPC_GPIO1->DIR |= (1 << pinNumber);
// *lpc_gpio1_dir_ptr|= (1 << pinNumber);
break;
case 2:
LPC_GPIO2->DIR |= (1 << pinNumber);
break;
default:
break;
}
}
// #define PORTBASE 0x40000000
// unsigned int volatile * const port = (unsigned int *) PORTBASE;
// The variable port is a constant pointer to a volatile unsigned integer, so we can access the memory-mapped register using:
// *port = value; /* write to port */
// value = *port; /* read from port */
void setPortPinValue(int portNumber, int pinNumber, int pinValue)
{
switch( portNumber )
{
case 1:
if (pinValue == 1)
LPC_GPIO1->DATA &= ~(1 << pinNumber);
else
LPC_GPIO1->DATA |= (1 << pinNumber);
break;
case 2:
;
break;
default:
break;
}
}
void blinkLed(int ledNumber, int onTime, int offTime, int blinkCount)
{
int count;
switch( ledNumber )
{
case 1:
setPortPinDirection(1, 8);
for (count = 0; count < blinkCount; count--)
{
setPortPinValue(1, 8, 0);
delayTenthSecond(onTime);
setPortPinValue(1, 8, 1);
delayTenthSecond(offTime);
}
break;
case 2:
;
break;
default:
break;
}
}
int main()
{
setPortPinDirection(1, 8);
blinkLed(1, 5, 10, 20); // Led 1, off 0.5 sec, on 1 sec, blink 20 times
}
// ****************************************************************************
// End of Program
// ****************************************************************************
No comments:
Post a Comment