Blinky() version 0.48 notes

Blinky() was good.  So I refactored it to Blink01().  The new version does not work.  So I went back to the old version.  But even the once working old version now is not working.  I must have made a careless mistake somewhere.

Anyway, I call it a day.

// ***********************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.48
// Date - 2013jul13hkt2232
// Hardware - Somy ARM Cortex M0 LPC1114/301 Learning Board 
// Software - Keil uVision 4.71.2.0 ARM CC
// Somy Configuration -
//   LED1 - P1.8
// Function structure
//   main()
//     blinky()
//       setPortPinOutput()
//       setPortPinLow()
//       setPortPinHigh()
//       delayTenthSecond()
// ***********************************************************************

// ***********************************************************************
// Include header files
// ***********************************************************************
#include <stdio.h>
#include "LPC11xx.h"
#include "timer.h"

// ***********************************************************************
// Global constants and variables
// ***********************************************************************

typedef const int logicLevel;
logicLevel LogicLevelLow = 0;
logicLevel LogicLevelHigh = 1;

typedef const int portNumber;
portNumber Port0 = 0;
portNumber Port1 = 1;
portNumber Port2 = 2;
portNumber Port3 = 3;
portNumber Port4 = 4;
portNumber Port5 = 5;
portNumber Port6 = 6;
portNumber Port7 = 7;

typedef const int pinNumber;
pinNumber Pin0 = 0;
pinNumber Pin1 = 1;
pinNumber Pin2 = 2;
pinNumber Pin3 = 3;
pinNumber Pin4 = 4;
pinNumber Pin5 = 5;
pinNumber Pin6 = 6;
pinNumber Pin7 = 7;
pinNumber Pin8 = 8;
pinNumber Pin9 = 9;
pinNumber Pin10 = 10;
pinNumber Pin11 = 11;

typedef int ledNumber;
ledNumber Led0 = 0;
ledNumber Led1 = 1;

typedef int tenthSecond;
tenthSecond HalfSecond = 5;
tenthSecond OneSecond = 10;

typedef int repeatCount;
repeatCount FourTimes = 4;
repeatCount TwentyTimes = 20;

typedef int ledPortPinArrayArray[4][2];
ledPortPinArrayArray Lppaa = {{Port1, Pin8},{Port1, Pin8}, {Port1, Pin8}, {Port1, Pin8}};

// ***********************************************************************
// GPIO Functions
// ***********************************************************************

portNumber getLedPortNumber(ledNumber ledNumber, ledPortPinArrayArray lppaa)
{
  int portNumber;
  portNumber = lppaa [ledNumber][0];
  return portNumber;
}

pinNumber getLedPinNumber(ledNumber ledNumber, ledPortPinArrayArray lppaa)
{
  int ledPinNumber;
  ledPinNumber = lppaa [ledNumber][1];
  return ledPinNumber;
}

LPC_GPIO_TypeDef *getGpioStructPointer(int gpioPortNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;

  switch(gpioPortNumber)
    {
    case 0:
      gpioStructPointer = LPC_GPIO0;
break;
    case 1:
      gpioStructPointer = LPC_GPIO1;
break;    
default:
 break;
 }
return gpioStructPointer;
}

void setPortPinInput(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);
  gpioStructPointer->DIR &= ~(1 << pinNumber);
}

void setPortPinOutput(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);
  gpioStructPointer->DIR |= (1 << pinNumber);
}

void setPortPinLow(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);  
  gpioStructPointer->DATA &= ~(1 << pinNumber);    
}  

void setPortPinHigh(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);  
  gpioStructPointer->DATA |= (1 << pinNumber);    
}

// ***********************************************************************
// Time Delay Functions
// ***********************************************************************
void delayTenthSecond(int count)
  {
int i, j, k;
for (i = 0; i < count; i++)
    {
for (j = 0; j < 0x4; j++)
 {
        for (k = 0; k < 0x000BB00; k++)
          {
       }
}
     }
}
  
// ***********************************************************************
// Blinky
// ***********************************************************************

void blinky(ledNumber ledNumber, int pinNumber, int onTime, int offTime, int blinkCount)
{
  int count;
setPortPinOutput(ledNumber, pinNumber);
for (count = 0; count < blinkCount; count--)
{
    setPortPinHigh(ledNumber, pinNumber);
    delayTenthSecond(onTime);    
    setPortPinLow(ledNumber, pinNumber);
    delayTenthSecond(offTime);
  }  
}

// ***********************************************************************
// Blinky01
// ***********************************************************************

void blinky01(ledNumber ledNumber, int onTime, int offTime, int blinkCount)
{
  int count;
  int portNumber;
  int pinNumber;
  
  portNumber = getLedPortNumber(ledNumber, Lppaa);
  pinNumber = getLedPinNumber(ledNumber, Lppaa);
  
setPortPinOutput(portNumber, pinNumber);
  
for (count = 0; count < blinkCount; count--)
{
    setPortPinHigh(ledNumber, pinNumber);
    delayTenthSecond(onTime);    
    setPortPinLow(ledNumber, pinNumber);
    delayTenthSecond(offTime);
  }  
}

// ***********************************************************************
// Test Tunctions
// ***********************************************************************

void testBlinky()
{
  blinky(Port0, Pin8, HalfSecond, OneSecond, TwentyTimes); 
}  

void testBlinky01()
{
  blinky(Led0, Pin8, HalfSecond, OneSecond, FourTimes); 
}  

int main()
{
  testBlinky();
  //testBlinky01();
}

// ***********************************************************************
// End of Program
// ***********************************************************************

.END

blinky 0.47

// ****************************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.47
// Date - 2013jul13hkt1304
// Hardware - Somy ARM Cortex M0 LPC1114/301 Learning Board 
// Software - Keil uVision 4.71.2.0 ARM CC
// Somy Configuration -
//   LED1 - P1.8
// Function structure
//   main()
//     blinky()
//       setPortPinOutput()
//       setPortPinLow()
//       setPortPinHigh()
//       delayTenthSecond()
// ****************************************************************************

#include <stdio.h>
#include "LPC11xx.h"
#include "timer.h"

typedef const int logicLevel;
logicLevel LogicLevelLow = 0;
logicLevel LogicLevelHigh = 1;


LPC_GPIO_TypeDef *getGpioStructPointer(int gpioPortNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;

  switch(gpioPortNumber)
    {
    case 0:
      gpioStructPointer = LPC_GPIO0;
break;
    case 1:
      gpioStructPointer = LPC_GPIO1;
break;    
default:
 break;
 }
return gpioStructPointer;
}

void setPortPinInput(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);
  gpioStructPointer->DIR &= ~(1 << pinNumber);
}

void setPortPinOutput(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);
  gpioStructPointer->DIR |= (1 << pinNumber);
}

void setPortPinLow(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);  
  gpioStructPointer->DATA &= ~(1 << pinNumber);    
}  

void setPortPinHigh(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);  
  gpioStructPointer->DATA |= (1 << pinNumber);    
}
  
void blinky(int ledNumber, int pinNumber, int onTime, int offTime, int blinkCount)
{
  int count;
setPortPinOutput(ledNumber, pinNumber);
for (count = 0; count < blinkCount; count--)
{
    setPortPinHigh(ledNumber, pinNumber);
    delayTenthSecond(onTime);    
    setPortPinLow(ledNumber, pinNumber);
    delayTenthSecond(offTime);
  }  
}

int main()
  {
blinky(1, 8, 5, 10, 20); // LED off 0.5 sec, on 1 sec, 20 times
  }

// ****************************************************************************
// End of Program
// ****************************************************************************

blinky 0.46

// ****************************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.46
// Date - 2013jul13hkt1214
// Hardware - Somy ARM Cortex M0 LPC1114/301 Learning Board 
// Software - Keil uVision 4.71.2.0 ARM CC
// Somy Configuration -
//   LED1 - P1.8
// ****************************************************************************

#include <stdio.h>
#include "LPC11xx.h"
#include "timer.h"

LPC_GPIO_TypeDef *getGpioStructPointer(int gpioNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;

  switch(gpioNumber)
    {
    case 0:
      gpioStructPointer = LPC_GPIO0;
break;
    case 1:
      gpioStructPointer = LPC_GPIO1;
break;    
default:
 break;
 }
return gpioStructPointer;
}

void setPortPinDirection03(int gpioNumber, int pinNumber)
  {
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioNumber);
  gpioStructPointer->DIR |= (1 << pinNumber);
  }

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 setPortPinValue03(int gpioNumber, int pinNumber, int pinValue)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioNumber);  
  if (pinValue == 1)
      gpioStructPointer->DATA &= ~(1 << pinNumber);        
  else
      gpioStructPointer->DATA |= (1 << pinNumber);  
}

void blinky(int ledNumber, int pinNumber, int onTime, int offTime, int blinkCount)
{
  int count;
setPortPinDirection03(ledNumber, pinNumber);

for (count = 0; count < blinkCount; count--)
{
    setPortPinValue03(ledNumber, pinNumber, 0);
    delayTenthSecond(onTime);    
    setPortPinValue03(ledNumber, pinNumber, 1);
    delayTenthSecond(offTime);
  }  
}

int main()
  {
setPortPinDirection03(1, 8); // LED 1 = gpioStructure 1, pin 8
blinky(1, 8, 5, 10, 20); // LED off 0.5 sec, on 1 sec, 20 times
  }

// ****************************************************************************
// End of Program
// ****************************************************************************

Blinky 0.45

// ****************************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.45
// Date - 2013jul13hkt1200
// Hardware - Somy ARM Cortex M0 LPC1114/301 Learning Board 
// Software - Keil uVision 4.71.2.0 ARM CC
// Somy Configuration -
//   LED1 - P1.8
// ****************************************************************************

#include <stdio.h>
#include "LPC11xx.h"
#include "timer.h"

LPC_GPIO_TypeDef *getGpioStructPointer(int gpioNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;

  switch(gpioNumber)
    {
    case 0:
      gpioStructPointer = LPC_GPIO0;
break;
    case 1:
      gpioStructPointer = LPC_GPIO1;
break;    
default:
 break;
 }
return gpioStructPointer;
}

void setPortPinDirection03(int gpioNumber, int pinNumber)
  {
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioNumber);
  gpioStructPointer->DIR |= (1 << pinNumber);
  }

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 blinky(int ledNumber, int pinNumber, int onTime, int offTime, int blinkCount)
{
  int count;
setPortPinDirection03(ledNumber, pinNumber);

for (count = 0; count < blinkCount; count--)
{
    setPortPinValue(ledNumber, pinNumber, 0);
    delayTenthSecond(onTime);    
    setPortPinValue(ledNumber, pinNumber, 1);
    delayTenthSecond(offTime);
  }  
}

int main()
  {
setPortPinDirection03(1, 8); // LED 1 = gpioStructure 1, pin 8
blinky(1, 8, 5, 10, 20); // LED off 0.5 sec, on 1 sec, 20 times
  }

// ****************************************************************************
// End of Program
// ****************************************************************************

Blinky v0.42 writing notes

// ****************************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.44
// Date - 2013jul13hkt1153
// Hardware - Somy ARM Cortex M0 LPC1114/301 Learning Board 
// Software - Keil uVision 4.71.2.0 ARM CC
// Somy Configuration -
//   LED1 - P1.8
// ****************************************************************************

#include <stdio.h>
#include "LPC11xx.h"
#include "timer.h"

LPC_GPIO_TypeDef *getGpioStructPointer(int gpioStructNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;

  switch(gpioStructNumber)
    {
    case 0:
      gpioStructPointer = LPC_GPIO0;
break;
    case 1:
      gpioStructPointer = LPC_GPIO1;
break;    
default:
 break;
 }
return gpioStructPointer;
}

void setPortPinDirection03(int gpioStructNumber, int pinNumber)
  {
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioStructNumber);
  gpioStructPointer->DIR |= (1 << pinNumber);
  }

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 blinky(int ledNumber, int onTime, int offTime, int blinkCount)
{
int count;

switch( ledNumber )
{
case 1:
setPortPinDirection03(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()
  {
setPortPinDirection03(1, 8); // LED 1 = gpioStructure 1, pin 8
blinky(1, 5, 10, 20); // LED off 0.5 sec, on 1 sec, 20 times
  }

// ****************************************************************************
// End of Program
// ****************************************************************************

LPC800 ¥8.00 - TaoBao

LPC800 Cortex-M0+ LPC812 LPC810 NXP - TaoBao ¥8.00

Available in low-pin-count packages, the LPC800 offers easy-to-use peripherals addressing 8-bit application requirements while providing the 32-bit capabilities and exceptional power efficiency of the ARM® Cortex™-M0+ processor.

The LPC800 is available with up to 16 kB of Flash and up to 4 kB of SRAM, and can be used with a 3.3 VDD power supply (1.8 V to 3.6 V).

8-Bit Simplicity: Scalable, Efficient and Easy to Use

NXP has re-designed the LPC800 serial peripherals to be as lean as possible, making them more responsive and efficient. For example, the new SPI can operate as a slave at frequencies independent of the processor clock, solving the common frustration of having to over-sample 4-to-n times the SPI just to receive data. The I2C has also been re-engineered to allow the LPC800 to lie and wait at near-zero power consumption, even without a system clock, and wake up upon an address match.

Game-Changing Peripherals: Flexible Switch Matrix and State Configurable

Timer Introducing a new level of flexibility without adding complexity, the LPC800 includes game-changing features such as a switch matrix that enables designers to assign on-chip peripherals to any pin with a single line of code or a single click in the configuration tool. Another important peripheral on the LPC800 is the state configurable timer (SCT), which can be customized to meet the user’s specific application requirements. The basic SCT configuration is simply two 16-bit PWMs that have 4 capture inputs and 4 match outputs where each of the match registers are shadowed. The LPC800 can deliver virtually any timing or PWM function found on popular 8-bit MCUs

On-chip ROM driver support:

To match the innovation in hardware, the LPC800 provides simple, driver-free operations. Low-level drivers for I2C and UART no longer take up Flash space and only simple API calls are required to operate these peripherals

Packages: The LPC800 is available in a range of low-pin-count packages, including SO20, TSSOP20, TSSOP16 and DIP8. Popular with 8-bit developers, these packages help to streamline prototyping, ease of assembly, and simplify high-volume, low-cost manufacturing。

.END

Getting started with the LPC810 - Kevin Townsend

Getting started with the LPC810 - Created by Kevin Townsend

http://learn.adafruit.com/getting-started-with-the-lpc810/

Introduction

The LPC810 is a new microcontroller from NXP, a super fast little controller has only 8 pins but packs a lot of punch with a high speed processor and 32 bit instructions. This learning guide will show you everything you need to know to get started with the ARM Cortex M0+ based LPC810 microcontroller. It will cover:

Setting up a cross-compiling toolchain for ARM

Creating and compiling your first blinky program

Programming the LPC810 using free and open source tools


Blinky!Created by Kevin Townsend

http://learn.adafruit.com/getting-started-with-the-lpc810/blinky

Now that we have our project imported, we can get start creating our own projects.

By default, the LPC810_CodeBase you downloaded is setup to run a blinky example on pin 0.2, and it spits out 'Hello, LPC810!' on the default UART pins, which we can see in the 'while(1)' super-loop in main.c, shown below:

  while(1)
  {
    #if !defined(USE_SWD)
      /* Turn LED Off by setting the GPIO pin high */
      LPC_GPIO_PORT->SET0 = 1 << LED_LOCATION;
      mrtDelay(500);

      /* Turn LED On by setting the GPIO pin low */
      LPC_GPIO_PORT->CLR0 = 1 << LED_LOCATION;
      mrtDelay(500);
    #else
      /* Just insert a 1 second delay */
      mrtDelay(1000);
    #endif

    /* Send some text (printf is redirected to UART0) */
    printf("Hello, LPC810!\n");
  }

"LPC_GPIO_PORT->CLR0 = 1 << LED_LOCATION" will clear whatever pin is at the 'LED_LOCATION' bit on GPIO bank 0.

'LPC_GPIO_PORT->SET0' does the opposite.

This is how you turn the LED on or off, but for those changes to be visible, we need to insert a delay between state changes, which is accomplished with the mrtDelay(500) lines, which causes a 500ms delay.

Blinky is following by our printf() statement, and by default all printf output is redirect to UART0 on the LPC810.


USB to TTL Serial Cable - Debug / Console Cable for Raspberry Pi 

http://www.adafruit.com/products/954

The cable is easiest way ever to connect to your microcontroller/Raspberry Pi/WiFi router serial console port.

Inside the big USB plug is a USB<->Serial conversion chip and at the end of the 36" cable are four wire - red power, black ground, white RX into USB port, and green TX out of the USB port. The power pin provides the 5V @ 500mA direct from the USB port and the RX/TX pins are 3.3V level for interfacing with the most common 3.3V logic level chipsets.

Because of the separated pin plugs, this cable is ideal for powering and connecting up to the debug/login console on the Raspberry Pi or BeagleBone Black. Connect the pins as shown to power the Pi or BBB and establish the RX/TX link. Then install the Windows XP/Vista/7 or MacOS X PL2303HX.A drivers on your computer and connect with a terminal program at 115200 baud. Windows 8 is not supported.

Also handy for hacking WiFi routers to install alternate OS's, or nearly any other TTL port. This is easier to use than an FTDI cable in many cases because the wires are separated .

This cable is not good for Arduino re-programming such as a Boarduino, MENTA, Monochron, etc. because it does not have the DTR/RTS wire necessary for initiating the bootloader reboot sequence. For that we suggest an FTDI cable or FTDI friend.



OK ... But why the LPC810 at Adafruit? Created by Kevin Townsend

http://learn.adafruit.com/getting-started-with-the-lpc810/ok-dot-dot-dot-but-why-the-lpc810-at-adafruit

I'll be honest ... I just thought this was an incredibly interesting chip. I've been using NXP's LPC series of MCUs since, oh, forever ... but this particular chip in DIP8 really jumped out at me since it's so different than what people usually think of when they hear 'ARM'.

The DIP8 LPC810 is still somewhat of a challenge to use precisely because it's so small (by ARM standards, anyway): 4KB flash and 1KB SRAM. That doesn't go far, and in reality you only have about 3KB flash to play with once you add in your startup code and get everything setup.

But that's actually part of what I found so fun about this chip! It's a genuine challenge but a fun one to do something creative and interesting with so much performance in such a small space!

'Small is Beautiful' Warning: Shameless, unadulterated, highly-personal rant!

Really ... small is where it's at if you care about writing clean, efficient code and really learning how to do something properly and understanding what you're doing!

I always start my new projects with the smallest chip I can, rather than the biggest one available.

Why?

Because it forces me to keep size in mind, to try to write better, more efficient code, and to get the most out of the limited resources I have.

Why do I always start with ARM chips with 32KB flash and 8-12KB SRAM when I could get something with 512KB flash and 100KB+ SRAM for not much more?

Because if I started with those big chips I'd write even sloppier code that took more space than I needed, and I'd be stuck with bigger and more expensive chips and even worse code forever!

One of the biggest difficulties in deeply embedded systems is keeping things lean, without compromising on stability and reliability. That means error checking, data validation, etc., which takes space and time to implement, but you need to keep space in check, so it's an endless series of trade offs, decisions and optimisations.

Deeply embedded development has a lot more in common with mechanical watch-making than it does with traditional SW development: you're always trying to fit an impossible seeming number of gears and components into a ridiculously small package, and everything has to fit in in just the right manner to work at all. To throw some oil on the fire, it also needs to hold up to all manner of abuse and mistreatment that will get thrown at it, and keep smiling back at you day after day!

Something embedded SW engineers understand better than almost anyone else -- except maybe those crazy mechanical watch makers -- is the huge satisfaction in writing clean, concise, efficient code that solves real problems in concrete, elegant, reliable ways. Writing bloated code is easy ... writing elegant code and creating tiny solutions for big ambitions is harder, but also infinitely more satisfying!

Why the LPC810 with it's tiny package, and limited resources? Because it's a fun challenge and a really interesting way to learn ARM!

I really wanted to get this chip in people's hand just to see what people can do with 4KB flash and 1KB SRAM, and a reasonably limited set of peripherals. It's the kind of fun challenge that I enjoy working on, and I'm sure I'm not alone in that!


uv4 code size limit is only 32K!Saturday, 6 July 2013

http://fongeye.blogspot.hk/2013/07/uv4-code-size-limit-is-only-32k.html

hen I tried the debug thing.  I found a big problem.

The evaluation mode code size limit is only 32K!

I guess 32K is very small, not that useful.  Perhaps I should consider forgetting uv4 and start looking for other free tools more generous than uv4.

How disappointing!

I call it a day.

Posted by TL Fong at 22:10

.END