Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
/*-- [COLOR="Green"]
Company:.... AtomSoft
Author:..... Jason Lopez
[/COLOR] --*/
/*-- [COLOR="Green"] Please download --- UM10139: Volume 1: LPC214x User Manual [/COLOR] --*/
/*-- [COLOR="Green"] As i will refer to it for more info here... [/COLOR] --*/
#include <LPC214x.h>
/*-- [COLOR="Green"] We use defines to make the code easy to see and change in the future [/COLOR] --*/
/*-- [COLOR="Green"] Here i am defining 1 LED as a number. The number is the bit/pin that [/COLOR] --*/
/*-- [COLOR="Green"] the LED is connect to on the IC. [/COLOR] --*/
#define LED1 10 /*-- [COLOR="Green"] Replace LED1 with 10 [/COLOR] --*/
/*-- [COLOR="Green"] This will Return (0/1) the value of the bit number specified in the variable [/COLOR] --*/
/*-- [COLOR="Green"] This is done by getting the current value of the VAR and AND'ing it with [/COLOR] --*/
/*-- [COLOR="Green"] the value of 1 shifted to the left by the bit number.
EX: GETBIT(someVar,1)
Where someVar is originally 0x03 aka 0b00000011
Would Produce: 0x01
[/COLOR] --*/
#define GETBIT(var,bit) (((var)>>(bit))&1)
/*-- [COLOR="Green"] This will SET (1) the value of the specified bit in the variable [/COLOR] --*/
/*-- [COLOR="Green"] This is done by getting the current value of the VAR and OR'ing it with [/COLOR] --*/
/*-- [COLOR="Green"] the value of 1 shifted to the left by the bit number.
EX: SETBIT(someVar,2)
Where someVar is originally 0x03 aka 0b00000011
Would Produce: 0x07 aka 0b00000111
[/COLOR] --*/
#define SETBIT(var,bit) ((var)|=(1<<(bit)))
/*-- [COLOR="Green"] This will Clear (0) the value of the specified bit in the variable [/COLOR] --*/
/*-- [COLOR="Green"] This is done by getting the current value of the VAR and AND'ing it with [/COLOR] --*/
/*-- [COLOR="Green"] the "opposite" (~) value of 1 shifted to the left by the bit number.
EX: CLRBIT(someVar,2)
Where someVar is originally 0x07 aka 0b00000111
Would Produce: 0x03 aka 0b00000011
[/COLOR] --*/
#define CLRBIT(var,bit) ((var)&=(~(1<<(bit))))
/*-- [COLOR="Green"] Prototypes [/COLOR] --*/
void Initialize(void);
int main(void);
/*-- [COLOR="Green"] Initialize is used to set the speed of the CPU and any other init. settings[/COLOR] --*/
/*-- [COLOR="Green"] This can be named anything but Initialize is a standard [/COLOR] --*/
void Initialize(void) {
PLL0CON=0x0; /*-- [COLOR="Green"] Disable the PLL [/COLOR] --*/
PLL0FEED=0xAA; /*-- [COLOR="Green"] These 2 lines are the feed lines [/COLOR] --*/
PLL0FEED=0x55; /*-- [COLOR="Green"] These are a REQUIRED part of the PLL SETUP [/COLOR] --*/
VPBDIV=0x00; /*-- [COLOR="Green"] Setting peripheral Clock (pclk) to System Clock (cclk) [/COLOR] --*/
}
/*-- [COLOR="Green"] Main is the program start. This is where you start it all [/COLOR] --*/
int main(void){
int x; /*-- [COLOR="Green"] Local Variable. Using this one for local loops [/COLOR] --*/
Initialize(); /*-- [COLOR="Green"] Call our Initialize Function/Prototype [/COLOR] --*/
/*-- [COLOR="Green"] PINSELx is used to setup the pins usage. [/COLOR] --*/
/*-- [COLOR="Green"] In the manual starting on page: 76 [/COLOR] --*/
/*-- [COLOR="Green"] You will see for each pin in the PINSELx register there are 2 bits to set its purpose [/COLOR] --*/
/*-- [COLOR="Green"] For example on page 76 you will see that pin ( P0.1 ) can be used for 4 different things [/COLOR] --*/
/* [COLOR="Green"]
00 = GPIO Port........ is general Input or Ouput Pin...On most if not all this is always 00
01 = RxD (UART0)...... is UART0 Recieve Data Pin
10 = PWM3............. is Pulse Width Modulation Pin #3
11 = EINT0............ is External Interrupt Pin #0
*/ [/COLOR]
/*-- [COLOR="Green"] Knowing this you can easily set the bits in the register [/COLOR] --*/
/*-- [COLOR="Green"] Since all we need for this lesson is to blink a LED then GPIO for all [/COLOR] --*/
PINSEL0=0x00000000; /*-- [COLOR="Green"] Set all pins as GPIO pins [/COLOR] --*/
/*-- [COLOR="Green"] IODIRx is used to setup the pins direction. Input/Output [/COLOR] --*/
/*-- [COLOR="Green"] Page 83 refers to this as: [/COLOR] --*/
/* [COLOR="Green"]
8.4.1 GPIO port Direction register (IODIR, Port 0: IO0DIR - 0xE002 8008 and
Port 1: IO1DIR - 0xE002 8018; FIODIR, Port 0: FIO0DIR - 0x3FFF C000
and Port 1:FIO1DIR - 0x3FFF C020)
*/ [/COLOR]
/*-- [COLOR="Green"] One of the cool things is that the header LPC214x.h lets you use IOxDIR or IODIRx [/COLOR] --*/
/*-- [COLOR="Green"] Where x is the port aka 0 or 1 [/COLOR] --*/
/*-- [COLOR="Green"] You can see how confusing it would be to use IO0DIR instead of IODIR0 hence the below code [/COLOR] --*/
/*-- [COLOR="Green"] Note that when you set a 1 to any bit in this variable it sets the coresponding pin to output [/COLOR] --*/
/*-- [COLOR="Green"] and when you set it to a 0 you can guess what will happen... its a input. [/COLOR] --*/
IODIR0=0xFFFFFFFF; /*-- [COLOR="Green"] Set all pins as output pins [/COLOR] --*/
/*-- [COLOR="Green"] Almost all programs have this while(1) loop. This is a endless loop. [/COLOR] --*/
while(1){
SETBIT(IOPIN0,LED1); /*-- [COLOR="Green"] This will set the pin/bit LED1 (10) on IOPIN0 hence sending a 1 (HIGH) [/COLOR] --*/
for(x=0;x<100000;x++); /*-- [COLOR="Green"] This is a loop for xxxx ticks. Its a rough count [/COLOR] --*/
CLRBIT(IOPIN0,LED1); /*-- [COLOR="Green"] This will clear the pin/bit LED1 (10) on IOPIN0 hence sending a 0 (LOW) [/COLOR] --*/
for(x=0;x<100000;x++); /*-- [COLOR="Green"] This is a loop for xxxx ticks. Its a rough count [/COLOR] --*/
}
}
hey guys im trying something here... do you think this is helpful at all?
**broken link removed**
[COLOR="Green"] /*--
Company:.... AtomSoft
Author:..... Jason Lopez
--*/ [/COLOR]
[COLOR="Green"] /*-- Please download --- UM10139: Volume 1: LPC214x User Manual --*/ [/COLOR]
[COLOR="Green"] /*-- As i will refer to it for more info here... --*/ [/COLOR]
#include <LPC214x.h>
[COLOR="Green"] /*-- We use defines to make the code easy to see and change in the future --*/ [/COLOR]
[COLOR="Green"] /*-- Here i am defining 1 LED as a number. The number is the bit/pin that --*/ [/COLOR]
[COLOR="Green"] /*-- the LED is connect to on the IC. --*/ [/COLOR]
#define LED1 10 [COLOR="Green"] /*-- Replace LED1 with 10 --*/ [/COLOR]
[COLOR="Green"] /*-- This will Return (0/1) the value of the bit number specified in the variable --*/ [/COLOR]
[COLOR="Green"] /*-- This is done by getting the current value of the VAR and AND'ing it with --*/ [/COLOR]
[COLOR="Green"] /*-- the value of 1 shifted to the left by the bit number.
EX: GETBIT(someVar,1)
Where someVar is originally 0x03 aka 0b00000011
Would Produce: 0x01
--*/ [/COLOR]
#define GETBIT(var,bit) (((var)>>(bit))&1)
[COLOR="Green"] /*-- This will SET (1) the value of the specified bit in the variable --*/ [/COLOR]
[COLOR="Green"] /*-- This is done by getting the current value of the VAR and OR'ing it with --*/ [/COLOR]
[COLOR="Green"] /*-- the value of 1 shifted to the left by the bit number.
EX: SETBIT(someVar,2)
Where someVar is originally 0x03 aka 0b00000011
Would Produce: 0x07 aka 0b00000111
--*/ [/COLOR]
#define SETBIT(var,bit) ((var)|=(1<<(bit)))
[COLOR="Green"] /*-- This will Clear (0) the value of the specified bit in the variable --*/ [/COLOR]
[COLOR="Green"] /*-- This is done by getting the current value of the VAR and AND'ing it with --*/ [/COLOR]
[COLOR="Green"] /*-- the "opposite" (~) value of 1 shifted to the left by the bit number.
EX: CLRBIT(someVar,2)
Where someVar is originally 0x07 aka 0b00000111
Would Produce: 0x03 aka 0b00000011
--*/ [/COLOR]
#define CLRBIT(var,bit) ((var)&=(~(1<<(bit))))
[COLOR="Green"] /*-- Prototypes --*/ [/COLOR]
void Initialize(void);
int main(void);
[COLOR="Green"] /*-- Initialize is used to set the speed of the CPU and any other init. settings--*/ [/COLOR]
[COLOR="Green"] /*-- This can be named anything but Initialize is a standard --*/ [/COLOR]
void Initialize(void) {
PLL0CON=0x0; [COLOR="Green"] /*-- Disable the PLL --*/ [/COLOR]
PLL0FEED=0xAA; [COLOR="Green"] /*-- These 2 lines are the feed lines --*/ [/COLOR]
PLL0FEED=0x55; [COLOR="Green"] /*-- These are a REQUIRED part of the PLL SETUP --*/ [/COLOR]
VPBDIV=0x00; [COLOR="Green"] /*-- Setting peripheral Clock (pclk) to System Clock (cclk) --*/ [/COLOR]
}
[COLOR="Green"] /*-- Main is the program start. This is where you start it all --*/ [/COLOR]
int main(void){
int x; [COLOR="Green"] /*-- Local Variable. Using this one for local loops --*/ [/COLOR]
Initialize(); [COLOR="Green"] /*-- Call our Initialize Function/Prototype --*/ [/COLOR]
[COLOR="Green"] /*-- PINSELx is used to setup the pins usage. --*/ [/COLOR]
[COLOR="Green"] /*-- In the manual starting on page: 76 --*/ [/COLOR]
[COLOR="Green"] /*-- You will see for each pin in the PINSELx register there are 2 bits to set its purpose --*/ [/COLOR]
[COLOR="Green"] /*-- For example on page 76 you will see that pin ( P0.1 ) can be used for 4 different things --*/ [/COLOR]
[COLOR="Green"] /*
00 = GPIO Port........ is general Input or Ouput Pin...On most if not all this is always 00
01 = RxD (UART0)...... is UART0 Recieve Data Pin
10 = PWM3............. is Pulse Width Modulation Pin #3
11 = EINT0............ is External Interrupt Pin #0
*/ [/COLOR]
[COLOR="Green"] /*-- Knowing this you can easily set the bits in the register --*/ [/COLOR]
[COLOR="Green"] /*-- Since all we need for this lesson is to blink a LED then GPIO for all --*/ [/COLOR]
PINSEL0=0x00000000; [COLOR="Green"] /*-- Set all pins as GPIO pins --*/ [/COLOR]
[COLOR="Green"] /*-- IODIRx is used to setup the pins direction. Input/Output --*/ [/COLOR]
[COLOR="Green"] /*-- Page 83 refers to this as: --*/ [/COLOR]
[COLOR="Green"] /*
8.4.1 GPIO port Direction register (IODIR, Port 0: IO0DIR - 0xE002 8008 and
Port 1: IO1DIR - 0xE002 8018; FIODIR, Port 0: FIO0DIR - 0x3FFF C000
and Port 1:FIO1DIR - 0x3FFF C020)
*/ [/COLOR]
[COLOR="Green"] /*-- One of the cool things is that the header LPC214x.h lets you use IOxDIR or IODIRx --*/ [/COLOR]
[COLOR="Green"] /*-- Where x is the port aka 0 or 1 --*/ [/COLOR]
[COLOR="Green"] /*-- You can see how confusing it would be to use IO0DIR instead of IODIR0 hence the below code --*/ [/COLOR]
[COLOR="Green"] /*-- Note that when you set a 1 to any bit in this variable it sets the coresponding pin to output --*/ [/COLOR]
[COLOR="Green"] /*-- and when you set it to a 0 you can guess what will happen... its a input. --*/ [/COLOR]
IODIR0=0xFFFFFFFF; [COLOR="Green"] /*-- Set all pins as output pins --*/ [/COLOR]
[COLOR="Green"] /*-- Almost all programs have this while(1) loop. This is a endless loop. --*/ [/COLOR]
while(1){
SETBIT(IOPIN0,LED1); [COLOR="Green"] /*-- This will set the pin/bit LED1 (10) on IOPIN0 hence sending a 1 (HIGH) --*/ [/COLOR]
[COLOR="Green"] /*-- A for loop like: for(x=0;x<1;x++); with 1 takes approx 12 cycles to complete.............. --*/ [/COLOR]
[COLOR="Green"] /*-- A loop with 2 takes 25 Cycles know this we can calculate how long it will take for 500ms.. --*/ [/COLOR]
[COLOR="Green"] /*-- Since we are at 12 MHz thats 12,000,000 Cycles for 1 second. So it would take............. --*/ [/COLOR]
[COLOR="Green"] /*-- 6,000,000 cycles for 500mSaka 1/2 second delay and since the loop takes 12-13 cycles for 1 --*/ [/COLOR]
[COLOR="Green"] /*-- 6,000,000 / 12 = 500000..... So we will use 500000 for our loop........................... --*/ [/COLOR]
[COLOR="Green"] /*-- If you should need exact timing i suggest you create a delay function and make sure........--*/ [/COLOR]
[COLOR="Green"] /*-- that it is delaying 6,000,000 cycles. This will do about 4,500,009 cycles due to the.......--*/ [/COLOR]
[COLOR="Green"] /*-- compiler optimizing the code it will run the empty loop quicker ........--*/ [/COLOR]
[COLOR="Green"] /*-- You have to manually ajust the number. I found that 666666 would gibe me 6,000,003 cycles..--*/ [/COLOR]
for(x=0;x<666666;x++); [COLOR="Green"] /*-- This is a loop for 666666 cycles aka instructions. 500mS --*/ [/COLOR]
CLRBIT(IOPIN0,LED1); [COLOR="Green"] /*-- This will clear the pin/bit LED1 (10) on IOPIN0 hence sending a 0 (LOW) --*/ [/COLOR]
for(x=0;x<666666;x++); [COLOR="Green"] /*-- This is a loop for 666666 cycles aka instructions. 500mS --*/ [/COLOR]
}
}
Matt's connection solution
void lcd_reset (void)
{
RST = 0 ; // I previously defined RST as the relevant pin on my PIC
delay (14000) ; // Wait some time (this number is specific to my own delay function)
RST = 1 ; // Return RST high
delay (14000) ;
}