// Program - TurnLedOn
// Description - To turn one LED on
// Author - TL Fong
// Version - 0.1
// Date - 2013jul09
// Copyright - No copyright, free for everybody
// Hardware - Somy ARM Cortex M0 LPC1114 Learning Board
// Software Keil uVision 4.71.2.0
// Hardware configuration notes
// 1. LED1 is connected to PIO1-8
// Program development notes
// 1. This is the very first program I am writing for the LPC1114 learning board.
// 2. LED1 is connection to PIO1-8
// 3. The program has built without errors, but I have no confidence it will run
// the first time. There is a risk that this program might corrupt the
// auto start self test LED display program stored in the flash. So I dare not // to download and run it. I guess I need to first make sure a couple of
// things.
// (a) If I upload this program, will the old program in flash got replaced?
// (b) Can I upload this program in a spare space in flash, so not to overwrite
// the original program there?
// 4. I remember that when I played with Arduino, there is no such worry, because // there is no self test LED display message in Arduino.
// 5. Since I am new to this PLC1114 learning board, I think I better play safe and
// and read more about flash downloading etc before running this first program.
// Another think I should also do is to first run this program in simulation
// mode, to check out if the PIO1-8 pin is indeed going high and low.
// 6. One more thing I need to find out the the time delay function. I wonder
// if Keil C has any delay function like delayMilliseconds()
// 7. For Raspberry Pi Python I can easily google the Python to give answers for
// the above questions. But for this Keil C, I have no idea where to start.
// Perhaps I should try the uVision Help first.
#include <stdio.h>
#include "LPC11xx.h"
void enableGpioClock()
{
LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 6);
LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 16);
}
void setPort1Pin8ToOutput() // PIO1_8 for LED1 pin set to output
{
LPC_GPIO1->DIR |= (1<<7);
}
void setPort1Pin8Low() // PIO1_8 set Low to turn on LED1
{
LPC_GPIO0->DATA &= ~(1<<8);
}
void setPort1Pin8High() // PIO1_8 set High to turn on LED1
{
LPC_GPIO0->DATA |= (1<<8);
}
void delay()
{
for (i = 0; i < 0x000FFFFF; i++)
{
}
int main()
{
int i;
setPort1Pin8ToOutput(); // PIO1_8 for LED1 pin set to output
while (1)
{
setPort1Pin8Low(); // Turn on LED1
delay();
setPort1Pin8Low(); // Turn off LED1
delay();
}
}
// *** Build output ***
// Build target 'Blinky'
// linking...
// Program Size: Code=1372 RO-data=288 RW-data=4 ZI-data=612
// "blinky.axf" - 0 Error(s), 0 Warning(s).
// .END
No comments:
Post a Comment