This is some basic stuffs, regarding Registers class, that I am learning a few days ago.
Using the LPC23xx datasheet as the reference.
I like to post it on Fezzer, but want to make sure that this is the right way of coding it.
And to avoid any mistake before someone could come and say that this code were not corrected, and to prevent that the code might do some damage to the microcontroller.
So, if anyone, who has the experience on the Registers, can tell me that this is OK code, or
if you can give me some comment on this, I would be really appreaciated!
Thanks,
sam
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware.LowLevel;
namespace FEZ_Panda_Application1
{
public class Program
{
// LED pin (IO43) or P0.16 on Panda
private static uint LED = 0x10000;
// Port0 Direction Base Address
private static Register FIO0DIR = new Register(0x3FFFC000);
// Port0 Mask Base Address
private static Register FIO0MASK = new Register(0x3FFFC010);
// Port0 Pin Base Address
private static Register FIO0PIN = new Register(0x3FFFC014);
public static void Main()
{
// read Direction, Mask, and Pin values from Panda
uint dirValue = FIO0DIR.Read();
uint maskValue = FIO0MASK.Read();
uint pinValue = FIO0PIN.Read();
// set direction for the LED pin to OUTPUT
FIO0DIR.Write(dirValue | LED);
//set Mask to allow only LED pin (P0.16) on PORT0 to be actived
// 1111 1111 1111 1110 1111 1111 1111 1111
FIO0MASK.Write(0xFFFEFFFF);
// To turn off LED, do:
//FIO0PIN.ClearBits(LED);
while (true)
{
// turn On LED
FIO0PIN.ToggleBits(LED);
// Sleep for 500 milliseconds
Thread.Sleep(500);
}
}
}
}
here is the video, of the blinking LED using Registers
Here is an ( my personal) answers to the question “Why would anyone want to blink LED that way?”
Things that led me to do the blinking LED with Register were:
That is the first thing I usually learned to do (blink the LED) with another type of microController (i.e, PIC, ATmel’s ATMEGA, etc)
There should have more than one way to do thing (doesn’t matter if there is a better way to do the same thing)
To learn how to use GHI’s NETMF Drivers/ibralies, specifically on the Registers Class.
It is the ‘cheapest way’ to learn about pin configuration of USBizi/LPC23xx microprocesser, with the provided LED on board.
And here, what I gained
So I know that GPIO stands for General Purpose Input/Output ports
So I learned that LED (AKA IO43) is on pin 16 of Port 0 (P0.16) on Usbizi 100 Chipset.
So I learned that each Port of USBizi/LPC23xx consists of 32 pin, but some of the pin might not be utilized)
I learned more about the HEX, Binary, and Decimal equivalent in 32-bit term.
I learned and understand more on how to use the 2’s compliment bit to configure the USBizi/LPC23xx
And I learn that this is not the only way to switch on and off the led, I could also do this,
IO0PIN = (IO0PIN && 0xFFFF7FFF) || 0x8000
Then, I have some confident in the Registers Class, and got the OK confirmation from you.
I can step up to control/manipulate more than one pin (LED) at the time.
I read through this page again the other day: [url]http://informatix.miloush.net/microframework/Articles/MeepMeep.aspx[/url], towards the bottom of the page he describes an interesting approach to quickly toggling pins. The rest of the page about tips for speeding up NETMF programs is far more valuable though, IMHO.