Sign in

username:

password:



Not a member?

Search lpc2000



Search tips

Subscribe to lpc2000



lpc2000 by Keywords

2106 | ADC | ARM7 | Atmel | Bootloader | CAN | CrossStudio | CrossWorks | DDS | ECos | Ethernet | ETM | FIFO | FLASH | FPGA | GCC | GDB | GNU | GNUARM | GPIO | I2C | IAP | IAR | JTAG | Kickstart | LCD | Linux | LPC | LPC-E2294 | LPC2000 | LPC2100 | LPC2104 | Lpc2106 | Lpc210x | LPC2114 | LPC2119 | LPC2124 | LPC2129 | Lpc2138 | LPC213x | LPC21xx | LPC2210 | LPC2212 | LPC2214 | LPC2292 | LPC2294 | LPC2xxx | LPC3128 | MCB2100 | Olimex | Philips | PWM | Rowley | RTC | RTOS | SPI | SSP | UART | UART0 | UART1 | ULINK | USB | Watchdog | Wiggler

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | LPC2000 | LPC2148 Blink Tutorial


Advertise Here

Discussion group dedicated to the Philips LPC2000 family of ARM MCUs

LPC2148 Blink Tutorial - atomsoftlive - Aug 4 4:13:44 2009

Hey guys i finally got around to making a blink.c file i hope will help a lot of users learn some ARM. This will explain how to set/clear pins and the PINSELx, IOxDIR/IODIRx, and delay loops. Even though most people here seem to think delays are bad and a timer is better.

There are many cases where a timer isnt needed at all. And is a waste of coding space and time....

Here is my blink.c and please comment on it:

/*--
Company:.... AtomSoft
Author:..... Jason Lopez
--*/
/*-- Please download --- UM10139: Volume 1: LPC214x User Manual --*/
/*-- As i will refer to it for more info here... --*/

#include

/*-- We use defines to make the code easy to see and change in the future --*/
/*-- Here i am defining 1 LED as a number. The number is the bit/pin that --*/
/*-- the LED is connect to on the IC. --*/
#define LED1 10 /*-- Replace LED1 with 10 --*/

/*-- This will Return (0/1) the value of the bit number specified in the variable --*/
/*-- This is done by getting the current value of the VAR and AND'ing it with --*/
/*-- 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
--*/
#define GETBIT(var,bit) (((var)>>(bit))&1)

/*-- This will SET (1) the value of the specified bit in the variable --*/
/*-- This is done by getting the current value of the VAR and OR'ing it with --*/
/*-- 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
--*/
#define SETBIT(var,bit) ((var)|=(1<<(bit)))

/*-- This will Clear (0) the value of the specified bit in the variable --*/
/*-- This is done by getting the current value of the VAR and AND'ing it with --*/
/*-- 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
--*/
#define CLRBIT(var,bit) ((var)&=(~(1<<(bit))))

/*-- Prototypes --*/
void Initialize(void);
int main(void);

/*-- Initialize is used to set the speed of the CPU and any other init. settings--*/
/*-- This can be named anything but Initialize is a standard --*/
void Initialize(void) {

PLL0CON=0x0; /*-- Disable the PLL --*/
PLL0FEED=0xAA; /*-- These 2 lines are the feed lines --*/
PLL0FEED=0x55; /*-- These are a REQUIRED part of the PLL SETUP --*/

VPBDIV=0x00; /*-- Setting peripheral Clock (pclk) to System Clock (cclk) --*/
}

/*-- Main is the program start. This is where you start it all --*/
int main(void){
int x; /*-- Local Variable. Using this one for local loops --*/

Initialize(); /*-- Call our Initialize Function/Prototype --*/

/*-- PINSELx is used to setup the pins usage. --*/
/*-- In the manual starting on page: 76 --*/
/*-- You will see for each pin in the PINSELx register there are 2 bits to set its purpose --*/
/*-- For example on page 76 you will see that pin ( P0.1 ) can be used for 4 different things --*/
/*
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
*/
/*-- Knowing this you can easily set the bits in the register --*/
/*-- Since all we need for this lesson is to blink a LED then GPIO for all --*/

PINSEL0=0x00000000; /*-- Set all pins as GPIO pins --*/

/*-- IODIRx is used to setup the pins direction. Input/Output --*/
/*-- Page 83 refers to this as: --*/
/*
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)
*/
/*-- One of the cool things is that the header LPC214x.h lets you use IOxDIR or IODIRx --*/
/*-- Where x is the port aka 0 or 1 --*/
/*-- You can see how confusing it would be to use IO0DIR instead of IODIR0 hence the below code --*/

/*-- Note that when you set a 1 to any bit in this variable it sets the coresponding pin to output --*/
/*-- and when you set it to a 0 you can guess what will happen... its a input. --*/

IODIR0=0xFFFFFFFF; /*-- Set all pins as output pins --*/

/*-- Almost all programs have this while(1) loop. This is a endless loop. --*/
while(1){
SETBIT(IOPIN0,LED1); /*-- This will set the pin/bit LED1 (10) on IOPIN0 hence sending a 1 (HIGH) --*/

/*-- A for loop like: for(x=0;x<1;x++); with 1 takes approx 12 cycles to complete.............. --*/
/*-- A loop with 2 takes 25 Cycles know this we can calculate how long it will take for 500ms.. --*/
/*-- Since we are at 12 MHz thats 12,000,000 Cycles for 1 second. So it would take............. --*/
/*-- 6,000,000 cycles for 500mSaka 1/2 second delay and since the loop takes 12-13 cycles for 1 --*/
/*-- 6,000,000 / 12 = 500000..... So we will use 500000 for our loop........................... --*/

/*-- If you should need exact timing i suggest you create a delay function and make sure........--*/
/*-- that it is delaying 6,000,000 cycles. This will do about 4,500,009 cycles due to the.......--*/
/*-- compiler optimizing the code it will run the empty loop quicker ........--*/
/*-- You have to manually ajust the number. I found that 666666 would gibe me 6,000,003 cycles..--*/

for(x=0;x<666666;x++); /*-- This is a loop for 666666 cycles aka instructions. 500mS --*/

CLRBIT(IOPIN0,LED1); /*-- This will clear the pin/bit LED1 (10) on IOPIN0 hence sending a 0 (LOW) --*/
for(x=0;x<666666;x++); /*-- This is a loop for 666666 cycles aka instructions. 500mS --*/
}

}

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )


Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 4:15:37 2009

I forgot to post the link to the c file .... sorry
http://atomsofttech.info/cross/blinkMain.c

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - Pete Vidler - Aug 4 4:37:45 2009

Just a few comments -- see below.

atomsoftlive wrote:
> There are many cases where a timer isnt needed at all. And is a waste of
> coding space and time....

Use of timers provides vastly improved accuracy and robustness against
change (even something as simple as the optimisation setting will break
your code), along with the power savings associated with the use of idle
modes.

Delay loops as you are using them are only really useful in toy example
code; in a real application they are far more trouble than they are worth.

Also, in this day and age I much prefer to make use of the available C99
features. Inline functions over macros, variables declared just-in-time
(instead of at the top of the function only) and at much narrower scope
(inside the 'for' loop), amongst many others.

Too many comments made the code itself difficult to read (especially
from a web page without syntax highlighting). This is a problem when so
few of the comments say anything useful -- some examples:

"We use defines to make the code easy to see and change in the future"
"This can be named anything but Initialize is a standard"
"One of the cool things is that the..."
"Main is the program start. This is where you start it all"

Pete
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 5:17:29 2009

Thanks for the comments.

I think the use of a timer for blinking a led is a overkill dont you?
This is a blink tutorial so its the basics. Since the basics is what i know.

I write a ton of comments so people can learn. No one wants to read a uptight comment without some human emotion involved.

Useless comment is a overstatement. Just because it doesnt explain the code doesnt mean it is useless. Thats like saying ... having your name on top is useless. It doesnt help with the code or explain anything. But it has its purpose.

Thanks again.... (this isnt a argument its just my intake)

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 5:24:10 2009

I always forget to add someting :D

Ill learn how to setup timers today and post a blink with a timer tutorial. Thanks...

I do think it would be best to learn that also. But as its a first time user type thing i think the code i posted will be fine for learning the basics of how to operate the LPC2148.

When im done with the timer code ill post it and would like it if you could comment on it also....

Thank you again! :)

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: LPC2148 Blink Tutorial - Pete Vidler - Aug 4 5:37:26 2009

atomsoftlive wrote:
> I think the use of a timer for blinking a led is a overkill dont you?

If it isn't how you'd do it in the real world (and it isn't, hopefully)
then I might even consider it harmful. Sorry if this all sounds harsh,
but I have dealt with problems caused by copy-pasted code *far* too often.

As a side note: using a timer for a blinking LED is very useful. With
a known period you can easily time it (or hook it up to a scope) and see
for yourself that your timer and hardware are all set up correctly,
before going on to build the rest of the system. Delays usually lack
the precision for even this simple test.

> Thats like saying ... having your name on top is useless.

Correct. The only use a name at the top serves is as part of a
licence/copyright or as a means to find out who's to blame for what's
below it.

If you want to add character, then I suggest putting the code in
snippet-form on a website, with clearly separated text around it to
explain what's going on. That way people can scan the code and text
more easily -- comments are not a good place for this stuff.

(You might also be interested in 'literate programming' tools).

Pete
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 6:10:31 2009

Thanks. I think i might just stick to the normal comments but try to keep it to a minimum then.

I always liked the idea of showing the code then explaining the snippets online. This zeros out on the part of code you want to explain. Thanks

Since im new to this kind of stuff i have no real world use yet. I have done things with Microchip products. Like a SIRC control for my lights in the room. Which has been working for months now without any issue. And it uses the same kind of delays i did for this.

But since im trying to learn the right way ill use a timer and see what i can do. Thanks again and feel free to keep the comments coming.

btw... you dont sound harsh. You sound experienced.

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - rtstofer - Aug 4 9:03:34 2009

--- In l...@yahoogroups.com, "atomsoftlive" wrote:
> #define SETBIT(var,bit) ((var)|=(1<<(bit)))
> #define CLRBIT(var,bit) ((var)&=(~(1<<(bit))))

You probably shouldn't use those macros with IO Ports. The read-modify-write approach isn't recommended.

Use IOSET and IOCLR instead.

QUOTE

Writing to the IOPIN register stores the value in the port output register, bypassing the need to use both the IOSET and IOCLR registers to obtain the entire written value. This feature should be used carefully in an application since it affects the entire port.

END QUOTE - from LPC214x User Manual

Richard
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 9:23:54 2009

I have seen that but.... why? There is no problem with the way i use it. I understand that it modifies the entire port. I dont see why i should use IOSET/IOCLR since i know how to use IOPIN without issue.

When i run into a problem thats when ill use it.

would it be ok if i use FIOSET/FIOCLR/FIODIR

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - donhamilton2002 - Aug 4 9:28:17 2009

--- In l...@yahoogroups.com, "atomsoftlive" wrote:
> There are many cases where a timer isnt needed at all. And is a waste of coding space and time....

You are correct, with throw away code like this a timer is not needed.

For real production code, using the timer allows for a re-usable function that is accurate.

don
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - donhamilton2002 - Aug 4 9:33:38 2009

--- In l...@yahoogroups.com, "atomsoftlive" wrote:
>
> I have seen that but.... why? There is no problem with the way i use it. I understand that it modifies the entire port. I dont see why i should use IOSET/IOCLR since i know how to use IOPIN without issue.

Experience has shown that the other bits not modified but may glitch.

They added this functionality for a reason.

As a beginner you can do what ever you want.

In a real production coding environment, you may loose your job being a beginner all the time.

don
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 9:42:12 2009

you see now im learning :D (i think :D )

Would it be ok to make a few macro to use like:
#define GET0(bit) ((FIO0PIN>>bit)&1) /*-- Get FIOPIN0 Bit --*/
#define GET1(bit) ((FIO1PIN>>bit)&1) /*-- Get FIOPIN1 Bit --*/

#define HIGH0(bit) (FIO0SET |=1< #define LOW0(bit) (FIO0CLR |=1<
#define HIGHP1(bit) (FIO1SET |=1< #define LOWP1(bit) (FIO1CLR |=1<
#define SETVAR(var,bit) ((var)|=(1<<(bit))) /*-- SET a bit HIGH in a var --*/
#define CLRVAR(var,bit) ((var)&=(~(1<<(bit)))) /*-- CLR a bit to LOW in a var --*/

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 9:46:12 2009

Thanks for the below. This is the reason i am here. I want to learn how to do it right!

If there is no reason to modify or someone cant give me a reason then i have no reason to change it. Reasons like:

Experience has shown that the other bits not modified but may glitch.

thats a reason i like to see. Now i know why and understand i should use it the other way.

I will still use my "SETVAR/CLRVAR" for normal int variables.

--- In l...@yahoogroups.com, "donhamilton2002" wrote:
>
> --- In l...@yahoogroups.com, "atomsoftlive" wrote:
> >
> > I have seen that but.... why? There is no problem with the way i use it. I understand that it modifies the entire port. I dont see why i should use IOSET/IOCLR since i know how to use IOPIN without issue.
>
> Experience has shown that the other bits not modified but may glitch.
>
> They added this functionality for a reason.
>
> As a beginner you can do what ever you want.
>
> In a real production coding environment, you may loose your job being a beginner all the time.
>
> don
>
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

RE: Re: LPC2148 Blink Tutorial - Paul Curtis - Aug 4 9:46:24 2009



> #define GET0(bit) ((FIO0PIN>>bit)&1) /*-- Get FIOPIN0 Bit --*/

What happens when you use GET0(1+1)?

> #define HIGH0(bit) (FIO0SET |=3D1< */

No. Not |=3D. Just =3D.

> #define LOW0(bit) (FIO0CLR |=3D1< --*/

Ditto.

> #define HIGHP1(bit) (FIO1SET |=3D1< --*/
> #define LOWP1(bit) (FIO1CLR |=3D1< --*/

Ditto.

> #define SETVAR(var,bit) ((var)|=3D(1<<(bit))) /*-- SET a bit HIGH in =
a
> var --*/
> #define CLRVAR(var,bit) ((var)&=3D(~(1<<(bit)))) /*-- CLR a bit to
LOW in
> a var --*/

To me, SETVAR(var, bit) is a nonsense. You don't know whether SETVAR(x, 7)
will or 7 into x or or 0x80 into x. It's syntactic sugar of the worst kind=
.

--
Paul Curtis, Rowley Associates Ltd=A0=A0 http://www.rowley.co.uk
CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: LPC2148 Blink Tutorial - "J.C. Wren" - Aug 4 9:56:44 2009

A lot of inconsistency in how you're using macro arguments, too.

In some places you have parens around the 'bit' argument. A good idea.

In some places you have parens around the '(1 << [(]bit[)])' expression. A
good idea.

In some places, you have neither.

Personally, I like the parens, like in this expression: #define
SETVAR(var,bit) ((var)|=(1<<(bit))) /*-- SET a bit HIGH in a var --*/

However, as a macro, and as Paul said, it's complete syntactic sugar, and it
will rot your code.

--jc

On Tue, Aug 4, 2009 at 9:45 AM, Paul Curtis wrote:

> > #define GET0(bit) ((FIO0PIN>>bit)&1) /*-- Get FIOPIN0 Bit --*/
>
> What happens when you use GET0(1+1)?
>
> > #define HIGH0(bit) (FIO0SET |=1< >
> No. Not |=. Just =.
>
> > #define LOW0(bit) (FIO0CLR |=1< > --*/
>
> Ditto.
>
> > #define HIGHP1(bit) (FIO1SET |=1< > --*/
> > #define LOWP1(bit) (FIO1CLR |=1< > --*/
>
> Ditto.
>
> > #define SETVAR(var,bit) ((var)|=(1<<(bit))) /*-- SET a bit HIGH in a
> > var --*/
> > #define CLRVAR(var,bit) ((var)&=(~(1<<(bit)))) /*-- CLR a bit to
> LOW in
> > a var --*/
>
> To me, SETVAR(var, bit) is a nonsense. You don't know whether SETVAR(x, 7)
> will or 7 into x or or 0x80 into x. It's syntactic sugar of the worst kind.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!
>
>
>
[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 10:06:25 2009

>>What happens when you use GET0(1+1)?

Not sure, but will try.
>> No. Not |=. Just =.

Will change thanks!
>> To me, SETVAR(var, bit) is a nonsense. You don't know whether >>SETVAR(x, 7)
>> will or 7 into x or or 0x80 into x. It's syntactic sugar of the >>worst kind.
Ok i will omit that then...

Thanks again.

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 10:07:42 2009

--- In l...@yahoogroups.com, "J.C. Wren" wrote:
>
> A lot of inconsistency in how you're using macro arguments, too.
>
> In some places you have parens around the 'bit' argument. A good idea.
>
> In some places you have parens around the '(1 << [(]bit[)])' expression. A
> good idea.
>
> In some places, you have neither.
>
> Personally, I like the parens, like in this expression: #define
> SETVAR(var,bit) ((var)|=(1<<(bit))) /*-- SET a bit HIGH in a var --*/
>
> However, as a macro, and as Paul said, it's complete syntactic sugar, and it
> will rot your code.
>
> --jc
>
Ill be sure to check my parens and see what i can fix.
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 10:27:36 2009

Good and Bad news to report...

I cant use FIO0SET/FIO0CLR or the port 1 version. Not sure why but just doesnt work...

But i can use IOSET0/IOCLR0 and port 1 version pretty well...

HIGH0(9+1);

works the same as

HIGH0(10);

Thanks for making me check tho. Could have been a issue :D
This is my code for that so far:
#define GET0(bit) ((FIO0PIN>>bit)&1) /*-- Get FIOPIN0 Bit ...--*/
#define GET1(bit) ((FIO1PIN>>bit)&1) /*-- Get FIOPIN1 Bit ...--*/

#define HIGH0(bit) (IOSET0 = 1< #define LOW0(bit) (IOCLR0 = 1<
#define HIGHP1(bit) (IOSET1 = 1< #define LOWP1(bit) (IOCLR1 = 1<
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: LPC2148 Blink Tutorial - Paul Curtis - Aug 4 10:35:41 2009

On Tue, 04 Aug 2009 15:25:08 +0100, atomsoftlive
wrote:

> Good and Bad news to report...
>
> I cant use FIO0SET/FIO0CLR or the port 1 version. Not sure why but just
> doesnt work...

Check the thing called "SCS" and "Fast GPIO enable". Datasheet reading.

>
> But i can use IOSET0/IOCLR0 and port 1 version pretty well...
>
> HIGH0(9+1);
>
> works the same as
>
> HIGH0(10);

I suggest you read the following table before things bite and recast your
macros:

http://www.difranco.net/cop2220/op-prec.htm

-- Paul.
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: LPC2148 Blink Tutorial - jtd - Aug 4 10:53:35 2009

On Tuesday 04 August 2009, atomsoftlive wrote:
> Thanks for the below. This is the reason i am here. I want to learn how to
> do it right!
>
> If there is no reason to modify or someone cant give me a reason then i
> have no reason to change it. Reasons like:
>
> Experience has shown that the other bits not modified but may glitch.
>
> thats a reason i like to see. Now i know why and understand i should use it
> the other way.

When you are experimenting you use several methods to check the pros and cons.
That is what builds experience.
--
Rgds
JTD
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - rtstofer - Aug 4 11:04:41 2009

--- In l...@yahoogroups.com, "atomsoftlive" wrote:
>
> Good and Bad news to report...
>
> I cant use FIO0SET/FIO0CLR or the port 1 version. Not sure why but just doesnt work...
>
> But i can use IOSET0/IOCLR0 and port 1 version pretty well...
>
> HIGH0(9+1);
>
> works the same as
>
> HIGH0(10);
It works but only because of operator precedence. As I read the operator precedence table, the + will occur before the <<. It has been pointed out that you need to add parentheses to the expressions:

#define HIGH0(bit) IOSET0 = 1 << (bit)

Now it expands to IOSET0 = 1 << (9+1) and operator precedence is not determining the order of evaluation.

Macros are a literal textual substitution that occurs before the expression is evaluated. In fact, it is done in the C preprocessor before the compiler even gets a look at the expression.

If you don't have "The C Programming Language", you won't be able to read the discussion on macros on page 87 (1978 edition). Here is the an example

#define square(x) x * x

Now use it with square(z+1) and it will expand to:

z+1 * z+1 which is 2z+1, not (z + 1) squared.

The proper way to write the macro is:

#define square(x) (x) * (x)

This will expand to:

(z+1) * (z+1)
If you do decide to use read-modify-write (which is not an atomic operation), ask yourself what happens if an interrupt routine modifies the port right in the middle of your sequence. After the read and before the write.

IOSET and IOCLR are atomic operations and can not be interrupted.

The resulting bug of read-modify-write is VERY difficult to troubleshoot.

Richard
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - rtstofer - Aug 4 11:12:28 2009

--- In l...@yahoogroups.com, "rtstofer" wrote:

> Now it expands to IOSET0 = 1 << (9+1) and operator precedence is not determining the order of evaluation.
>

Strictly speaking, before I get flamed, operator precedence is still in control. But the parentheses force the evaluation of the expression before using it in the shift operation.

Did I mention how I NEVER want to rely on my memory of operator precedence? I can remember My Dear Aunt Sally but that's about it.

For those who miss the mnemonics, you Multiply and Divide before you Add and Subtract. But that only covers 2 of 15 rows in the table.

Richard
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 11:27:36 2009

I believe its "Please Excuse My Dear Aunt Sally"

Parenthesis
Exponent
Multiplication
Division
Addition
Subtraction
Thanks and ill remember that :)
Here is my code so far... no timer involved yet :(
/*-- Company: AtomSoft ..... Author: Jason Lopez --*/
/*-- Please download --- UM10139: Volume 1: LPC214x User Manual --*/
/*-- As i will refer to it for more info here... --*/

#include

#define LED1 10 /*-- LED1 on PIN 10 ....--*/

#define GET0(bit) ((FIO0PIN>>(bit))&1) /*-- Get FIOPIN0 Bit ...--*/
#define GET1(bit) ((FIO1PIN>>(bit))&1) /*-- Get FIOPIN1 Bit ...--*/

#define HIGH0(bit) (FIO0SET = 1<<(bit)) /*-- Set FIO0SET Bit ...--*/
#define LOW0(bit) (FIO0CLR = 1<<(bit)) /*-- Clear FIO0CLR Bit .--*/

#define HIGH1(bit) (FIO1SET = 1<<(bit)) /*-- Set FIO1SET Bit ...--*/
#define LOW1(bit) (FIO1CLR = 1<<(bit)) /*-- Clear FIO1CLR Bit .--*/

/*-- Prototypes --*/
void Initialize(void);
int main(void);

/*-- Global Variables --*/

void Initialize(void) {

PLL0CON=0x0; /*-- Disable the PLL running at 12 MHz from Crystal ..--*/
PLL0FEED=0xAA; /*-- These 2 lines are the feed lines ................--*/
PLL0FEED=0x55; /*-- These are a REQUIRED part of the PLL SETUP ......--*/

VPBDIV=0x00; /*-- Setting peripheral Clock (pclk) to System Clock (cclk) --*/
SCS = 0x01; /*-- High speed GPIO is enabled on GPIO port 0 and 1 ........--*/
}
int main(void){
int x;

Initialize(); /*-- Call our Initialize Function/Prototype .........................--*/
PINSEL0=0x00000000; /*-- Set all pins as GPIO pins ......................................--*/
FIO0MASK = ~(1< /*-- Be aware that while mask is in place you cant change other pins --*/
/*-- If many pins are changing you can just set this to 0 ...........--*/
FIO0DIR=0xFFFFFFFF; /*-- Set all pins as output pins ....................................--*/

while(1){
HIGH0(LED1); /*-- This will set the pin/bit LED1 (10) on IOPIN0 hence sending a 1 (HIGH) --*/
for(x=0;x<666666;x++); /*-- This is a loop for 666666 cycles aka instructions. 500mS ...............--*/

LOW0(LED1); /*-- This will clear the pin/bit LED1 (10) on IOPIN0 hence sending a 0 (LOW) --*/
for(x=0;x<666666;x++); /*-- This is a loop for 666666 cycles aka instructions. 500mS ................--*/
}
}
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: LPC2148 Blink Tutorial - Pete Vidler - Aug 4 11:27:37 2009

rtstofer wrote:
> The proper way to write the macro is:
>
> #define square(x) (x) * (x)

Using the expression in the macro twice is also problematic in cases
where the expression may have side effects.

square(x++)
square(func_that_alters_global_state_or_does_io())

... very contrived, but you see the point.

If you know you're going to be using a certain size and type of
variable, then you could use an inline function somewhere in a header
file (in C++ you could also template it):

static inline uint32_t square(uint32 value)
{
return value * value;
}

... which shouldn't be any less efficient than the macro, with
optimisation turned on. See also the article "An Inline Function is As
Fast As a Macro" from the GCC manual:

http://gcc.gnu.org/onlinedocs/gcc/Inline.html

If you're worried that the compiler might not inline it (I believe the
keyword is more of a guideline than a rule), then you can force it with
the 'always_inline' or 'flatten' GCC attributes. If you must.

Pete
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 11:28:16 2009

heh yeah hence why i ask alot of why questions. No experience or well not enough.

Let me thank all the people that are taking there time here to comment and fix this buggy programmer (me of course) :)

Thanks Guys/Gals!!!

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 11:31:05 2009

I changed SCS to 3 so i can do it on both ports...

Non commented version (easy on eyes)
/*-- Company: AtomSoft ..... Author: Jason Lopez --*/
/*-- Please download --- UM10139: Volume 1: LPC214x User Manual --*/
/*-- As i will refer to it for more info here... --*/

#include

#define LED1 10

#define GET0(bit) ((FIO0PIN>>(bit))&1)
#define GET1(bit) ((FIO1PIN>>(bit))&1)

#define HIGH0(bit) (FIO0SET = 1<<(bit))
#define LOW0(bit) (FIO0CLR = 1<<(bit))

#define HIGH1(bit) (FIO1SET = 1<<(bit))
#define LOW1(bit) (FIO1CLR = 1<<(bit))

void Initialize(void);
int main(void);
void Initialize(void) {

PLL0CON=0x0;

PLL0FEED=0xAA;
PLL0FEED=0x55;

VPBDIV=0x00;
SCS = 0x03;
}
int main(void){
int x;

Initialize();
PINSEL0=0x00000000;
FIO0MASK = ~(1<
FIO0DIR=0xFFFFFFFF;

while(1){
HIGH0(LED1);
for(x=0;x<666666;x++);

LOW0(LED1);
for(x=0;x<666666;x++);
}
}

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: LPC2148 Blink Tutorial - "J.C. Wren" - Aug 4 11:37:26 2009

"Did I mention how I NEVER want to rely on my memory of operator
precedence?"

Man, I am *so* about that. I do good some days to remember my name and
where I live. Wife's name is optional ("hey honey, ..." always works).

--jc

On Tue, Aug 4, 2009 at 11:10 AM, rtstofer wrote:

> --- In l...@yahoogroups.com , "rtstofer"
> wrote:
>
> > Now it expands to IOSET0 = 1 << (9+1) and operator precedence is not
> determining the order of evaluation.
> > Strictly speaking, before I get flamed, operator precedence is still in
> control. But the parentheses force the evaluation of the expression before
> using it in the shift operation.
>
> Did I mention how I NEVER want to rely on my memory of operator precedence?
> I can remember My Dear Aunt Sally but that's about it.
>
> For those who miss the mnemonics, you Multiply and Divide before you Add
> and Subtract. But that only covers 2 of 15 rows in the table.
>
> Richard
>
>
>
[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: LPC2148 Blink Tutorial - "J.C. Wren" - Aug 4 12:03:40 2009

Now compile your program with -O2 or -O3 and see what happens...

--jc

On Tue, Aug 4, 2009 at 11:26 AM, atomsoftlive wrote:

> heh yeah hence why i ask alot of why questions. No experience or well not
> enough.
>
> Let me thank all the people that are taking there time here to comment and
> fix this buggy programmer (me of course) :)
>
> Thanks Guys/Gals!!!
>
>
>
[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - rtstofer - Aug 4 12:07:41 2009

--- In l...@yahoogroups.com, Pete Vidler wrote:
>
> rtstofer wrote:
> > The proper way to write the macro is:
> >
> > #define square(x) (x) * (x)
>
> Using the expression in the macro twice is also problematic in cases
> where the expression may have side effects.
>
> square(x++)
> square(func_that_alters_global_state_or_does_io())
>
> ... very contrived, but you see the point.
>

Not so contrived. This is the kind of thing that bites C programmers all the time. Trying to anticipate all of the possible side effects makes using macros for these kinds of things more work than it is worth. And the bugs are so subtle...
Richard
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 13:38:29 2009

--- In l...@yahoogroups.com, "J.C. Wren" wrote:
>
> Now compile your program with -O2 or -O3 and see what happens...
>
> --jc
>
> On Tue, Aug 4, 2009 at 11:26 AM, atomsoftlive wrote:
>

What does it do? Should i try it with the (1+9) thing?

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - rtstofer - Aug 4 13:44:50 2009

--- In l...@yahoogroups.com, "J.C. Wren" wrote:
>
> Now compile your program with -O2 or -O3 and see what happens...
>
> --jc
Yup! That jumped up and bit me in the backsides. I had a spin loop just like that for a delay(uS) kind of thing. It completely disappeared with -O3.

Richard

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 13:51:16 2009

Im lost where do i put the: -O3

Im using crossworks 1.7 (yes i know i need a upgrade lol)

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - rtstofer - Aug 4 14:02:15 2009

--- In l...@yahoogroups.com, "atomsoftlive" wrote:
>
> I changed SCS to 3 so i can do it on both ports...
>
> Non commented version (easy on eyes)
> /*-- Company: AtomSoft ..... Author: Jason Lopez --*/
> /*-- Please download --- UM10139: Volume 1: LPC214x User Manual --*/
> /*-- As i will refer to it for more info here... --*/
>
> #include #define LED1 10
>
> #define GET0(bit) ((FIO0PIN>>(bit))&1)
> #define GET1(bit) ((FIO1PIN>>(bit))&1)
>
> #define HIGH0(bit) (FIO0SET = 1<<(bit))
> #define LOW0(bit) (FIO0CLR = 1<<(bit))
>
> #define HIGH1(bit) (FIO1SET = 1<<(bit))
> #define LOW1(bit) (FIO1CLR = 1<<(bit))
>
> void Initialize(void);
> int main(void);
> void Initialize(void) {
>
> PLL0CON=0x0;
>
> PLL0FEED=0xAA;
> PLL0FEED=0x55;
>
> VPBDIV=0x00;
> SCS = 0x03;
> }
> int main(void){
> int x;
>
> Initialize();
> PINSEL0=0x00000000;
> FIO0MASK = ~(1< >
> FIO0DIR=0xFFFFFFFF;
>
> while(1){
> HIGH0(LED1);
> for(x=0;x<666666;x++);
>
> LOW0(LED1);
> for(x=0;x<666666;x++);
> }
> }
>

I compiled this with -O3 and the loop code was not eliminated. I expected it would be. Hm...

However, when I compiled it with -O2, OOPS! No more loop code and no time delays.

Here's the related portion of the .lss file for -O2:

while(1){
HIGH0(LED1);
164: e3a03b01 mov r3, #1024 ; 0x400
168: e50c3fe7 str r3, [ip, #-4071]
for(x=0;x<666666;x++);

LOW0(LED1);
16c: e50c3fe3 str r3, [ip, #-4067]
170: eafffffc b 168

Here it is with -O0:

while(1){
HIGH0(LED1);
198: e3e03dff mvn r3, #16320 ; 0x3fc0
19c: e243319f sub r3, r3, #-1073741785 ; 0xc0000027
1a0: e3a02b01 mov r2, #1024 ; 0x400
1a4: e5832000 str r2, [r3]
for(x=0;x<666666;x++);
1a8: e3a03000 mov r3, #0 ; 0x0
1ac: e50b3010 str r3, [fp, #-16]
1b0: ea000002 b 1c0
1b4: e51b3010 ldr r3, [fp, #-16]
1b8: e2833001 add r3, r3, #1 ; 0x1
1bc: e50b3010 str r3, [fp, #-16]
1c0: e51b2010 ldr r2, [fp, #-16]
1c4: e3a03aa2 mov r3, #663552 ; 0xa2000
1c8: e2833ec2 add r3, r3, #3104 ; 0xc20
1cc: e2833009 add r3, r3, #9 ; 0x9
1d0: e1520003 cmp r2, r3
1d4: dafffff6 ble 1b4

LOW0(LED1);
1d8: e3e03dff mvn r3, #16320 ; 0x3fc0
1dc: e243318f sub r3, r3, #-1073741789 ; 0xc0000023
1e0: e3a02b01 mov r2, #1024 ; 0x400
1e4: e5832000 str r2, [r3]
for(x=0;x<666666;x++);
1e8: e3a03000 mov r3, #0 ; 0x0
1ec: e50b3010 str r3, [fp, #-16]
1f0: ea000002 b 200
1f4: e51b3010 ldr r3, [fp, #-16]
1f8: e2833001 add r3, r3, #1 ; 0x1
1fc: e50b3010 str r3, [fp, #-16]
200: e51b2010 ldr r2, [fp, #-16]
204: e3a03aa2 mov r3, #663552 ; 0xa2000
208: e2833ec2 add r3, r3, #3104 ; 0xc20
20c: e2833009 add r3, r3, #9 ; 0x9
210: e1520003 cmp r2, r3
214: dafffff6 ble 1f4
218: eaffffde b 198

And that's what happens when you use spin loops and add a little optimization.

Hence the recommendation to use timers. Even then, if you spin on reading a register, unless 'volatile' is working properly, the code will still be optimized away. So you have to be very careful how the register is defined. The usual .h files are probably correct although it pays to look at the list file to see exactly what was emitted.

Richard
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 14:14:41 2009

I get it now. Thanks!

Ill be sure to use loops

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 14:14:44 2009

aka TIMER LOOPS

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 4 19:54:37 2009

Ok this is what i got working so far. It seems to blink every 2 second meaning 1 second its on and 1 its off.

Its supposed to be half of that. Any thoughts?

Thanks again...
/*-- Company: AtomSoft ..... Author: Jason Lopez --*/
/*-- Please download --- UM10139: Volume 1: LPC214x User Manual --*/
/*-- As i will refer to it for more info here... --*/

#include
#include

#define LED1 10 /*-- LED1 on PIN 10 ....--*/

#define GET0(bit) ((FIO0PIN>>(bit))&1) /*-- Get IOPIN0 Bit ...--*/
#define GET1(bit) ((FIO1PIN>>(bit))&1) /*-- Get IOPIN1 Bit ...--*/

#define HIGH0(bit) (FIO0SET = 1<<(bit)) /*-- Set IO0SET Bit ...--*/
#define LOW0(bit) (FIO0CLR = 1<<(bit)) /*-- Clear IO0CLR Bit .--*/

#define HIGH1(bit) (FIO1SET = 1<<(bit)) /*-- Set IO1SET Bit ...--*/
#define LOW1(bit) (FIO1CLR = 1<<(bit)) /*-- Clear IO1CLR Bit .--*/

/*-- Prototypes --*/
void Initialize(void);
int main(void);
void Init_ISR(void);
void IRQ_Routine(void);
void Delay500mS(void);

/*-- Global Variables --*/
char fhmS;
int tmp;
int en;

void Initialize(void) {
/*-- Disable the PLL running at 12 MHz from Crystal ..--*/
PLL0CON=0x0;
PLL0FEED=0xAA;
PLL0FEED=0x55;

VPBDIV=0x00;
SCS = 0x03;
}

void Init_ISR(void) {
fhmS = 0;

T0TCR = 0x02; //Counter Reset
T0IR = 0xFF; //Reset All Interrupts
T0MCR = 0x0003; //Reset on MR0
T0MR0 = 0x5B8D80; //Match Register 0: 6,000,000 aka 500mS

VICVectCntl0 = 0x00000024; //TIMER0 and ENABLE
VICVectAddr0 = (unsigned)IRQ_Routine; //Addresses of the Interrupt Service routines (ISRs)
VICIntEnable = 0x00000010; //TIMER0 interrupt as IRQ
T0TCR = 0x01; //When one, the Timer Counter is enabled for counting
en = libarm_set_irq(1); //Enable Global IRQ interrupts
}

void IRQ_Routine(void) {
T0IR = 1;
T0TCR = 0x00;

fhmS = ~fhmS;

libarm_set_irq(en);
}
int main(void){
int x;

Initialize();
Init_ISR();

PINSEL0=0x00000000;
FIO0MASK = ~(1< FIO0DIR=0xFFFFFFFF;

while(1){
Delay500mS();
HIGH0(LED1);

Delay500mS();
LOW0(LED1);
}
}

void Delay500mS(void) {
fhmS = 0;
T0TCR = 0x01;
while(!fhmS);
}
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - cfbsoftware1 - Aug 4 19:59:34 2009

--- In l...@yahoogroups.com, "atomsoftlive" wrote:
>
> I write a ton of comments so people can learn. No one wants to read a uptight comment without some human emotion involved.
>

Excessive code comments severely impact the readability of code. If you want to write a useful tutorial write a document with snippets of code in it rather than writing code with snippets of a document in it.

In the majority of software development systems (BlackBox Component Builder being a notable exception) the typical single-font plain text code comment format is far too primitive a medium to convey the sort of information required in a useful tutorial.

Conversely, document formats allow a combination of font-styles, diagrams, pictures to clearly get the message across. Code snippets can be written in a monospaced font to conveniently distinguish them from explanatory text.

Regards,
Chris Burrows

CFB Software
Armaide v2.1: LPC2xxx Oberon-07 Development System
http://www.cfbsoftware.com/armaide
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - rtstofer - Aug 4 20:55:46 2009

--- In l...@yahoogroups.com, "atomsoftlive" wrote:
>
> Ok this is what i got working so far. It seems to blink every 2 second meaning 1 second its on and 1 its off.
>
> Its supposed to be half of that. Any thoughts?
>
> Thanks again...

A couple of thoughts. First, fhmS needs to be declared volatile for the compiler to do the right thing in Delay500mS. The variable is changed in the interrupt handler outside of the while loop. At some optimization level, that while loop msy disappear as fhmS is loop invariant as far as the compiler knows.

Second, how does your compiler know that IRQ_Routine() is an interrupt routine and needs the approprate prolog and epilog? Is it a reserved name?

For GCC, the proper prototype might look like:

void T0_ISR (void) __attribute__ ((interrupt));

It isn't really an IRQ, FIQ, SWI or UNDEF interrupt. It is just an interrupt with the vector address provided by the VIC. It does not use any of the predefined entry points.

I also don't know anything about your interrupt library but one thing that needs to happen in the ISR is to clear the VIC by:

VICVectAddr = 0xff;

Here's the code that goes with that prototype:

volatile unsigned int ticks = 0;

void T0_ISR(void)
{
ticks++;
if ((ticks & 0x03FF) == 0)
{
if (ticks & 0x0400)
IOSET = LED;
else
IOCLR = LED;
}

TIMER0_IR = 0x01;
VICVectAddr = 0xFF;
}

This particular routine flashes a heartbeat LED and provides 'ticks' to the uIP TCP/IP stack.

So far as I know, interrupts are not disabled when the ISR is called because the VIC can nest interrupts. I certainly don't re-enable them in any code I have written. They are enabled once in boot.s and that's it.

Individual interrupts can be controlled via the VIC or the peripheral.

Richard
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - carnac100 - Aug 4 21:21:14 2009

--- In l...@yahoogroups.com, "atomsoftlive" wrote:
>
> Ok this is what i got working so far. It seems to blink every 2 second meaning 1 second its on and 1 its off.
>
> Its supposed to be half of that. Any thoughts?
>
> Thanks again...
> /*-- Company: AtomSoft ..... Author: Jason Lopez --*/
> /*-- Please download --- UM10139: Volume 1: LPC214x User Manual --*/
> /*-- As i will refer to it for more info here... --*/
>
> #include
> #include #define LED1 10 /*-- LED1 on PIN 10 ....--*/
>
> #define GET0(bit) ((FIO0PIN>>(bit))&1) /*-- Get IOPIN0 Bit ...--*/
> #define GET1(bit) ((FIO1PIN>>(bit))&1) /*-- Get IOPIN1 Bit ...--*/
>
> #define HIGH0(bit) (FIO0SET = 1<<(bit)) /*-- Set IO0SET Bit ...--*/
> #define LOW0(bit) (FIO0CLR = 1<<(bit)) /*-- Clear IO0CLR Bit .--*/
>
> #define HIGH1(bit) (FIO1SET = 1<<(bit)) /*-- Set IO1SET Bit ...--*/
> #define LOW1(bit) (FIO1CLR = 1<<(bit)) /*-- Clear IO1CLR Bit .--*/
>
> /*-- Prototypes --*/
> void Initialize(void);
> int main(void);
> void Init_ISR(void);
> void IRQ_Routine(void);
> void Delay500mS(void);
>
> /*-- Global Variables --*/
> char fhmS;
> int tmp;
> int en;
>
> void Initialize(void) {
> /*-- Disable the PLL running at 12 MHz from Crystal ..--*/
> PLL0CON=0x0;
> PLL0FEED=0xAA;
> PLL0FEED=0x55;
>
> VPBDIV=0x00;
> SCS = 0x03;
> }
>
> void Init_ISR(void) {
> fhmS = 0;
>
> T0TCR = 0x02; //Counter Reset
> T0IR = 0xFF; //Reset All Interrupts
> T0MCR = 0x0003; //Reset on MR0
> T0MR0 = 0x5B8D80; //Match Register 0: 6,000,000 aka 500mS
>
> VICVectCntl0 = 0x00000024; //TIMER0 and ENABLE
> VICVectAddr0 = (unsigned)IRQ_Routine; //Addresses of the Interrupt Service routines (ISRs)
> VICIntEnable = 0x00000010; //TIMER0 interrupt as IRQ
> T0TCR = 0x01; //When one, the Timer Counter is enabled for counting
> en = libarm_set_irq(1); //Enable Global IRQ interrupts
> }
>
> void IRQ_Routine(void) {
> T0IR = 1;
> T0TCR = 0x00;
>
> fhmS = ~fhmS;
>
> libarm_set_irq(en);
> }
> int main(void){
> int x;
>
> Initialize();
> Init_ISR();
>
> PINSEL0=0x00000000;
> FIO0MASK = ~(1< > FIO0DIR=0xFFFFFFFF;
>
> while(1){
> Delay500mS();
> HIGH0(LED1);
>
> Delay500mS();
> LOW0(LED1);
> }
> }
>
> void Delay500mS(void) {
> fhmS = 0;
> T0TCR = 0x01;
> while(!fhmS);
> }
>
Your code disables the PLL and with a 12MHz crystal/bus, You are setting the PCLK to 1/4 of the bus clock (VPBDIV = 0)gives a timer clk of 3MHz. With a match value of 6,000,000 you should be generating interrupts every 2 seconds. Are you sure you are seeing 1 second interrupts?

Frank
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - cfbsoftware1 - Aug 4 22:26:00 2009

> --- In l...@yahoogroups.com, "atomsoftlive" wrote:
>
> T0MR0 = 0x5B8D80; //Match Register 0: 6,000,000 aka 500mS
>

If the value *is* decimal 6 million then *show it* as decimal 6 million.

e.g.

T0MR0 = 6000000; // 500ms assuming a 12Mhz PCLK

Only use hex notation if it is relevant to the actual use e.g. it's a specific address, a recognisable bit pattern etc. etc.

Chris Burrows

CFB Software
Armaide v2.1: LPC2xxx Oberon-07 Development System
http://www.cfbsoftware.com/armaide
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 5 6:31:26 2009

MY Interrupt works. This is how its done in Crossworks i think. Ive seen it in App Notes.

if i enable them from the start the led var fhMs would change even before i use it.

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 5 6:34:02 2009

Dude you rock!

VPBDIV=0x01;

This is what i needed. The code works fine now... I guess i didnt read the VPBDIV part right ... Thanks

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 5 6:44:47 2009

--- In l...@yahoogroups.com, "cfbsoftware1" wrote:
>
> > --- In l...@yahoogroups.com, "atomsoftlive" wrote:
> >
> > T0MR0 = 0x5B8D80; //Match Register 0: 6,000,000 aka 500mS
> >
>
> If the value *is* decimal 6 million then *show it* as decimal 6 million.
>
> e.g.
>
> T0MR0 = 6000000; // 500ms assuming a 12Mhz PCLK
>
> Only use hex notation if it is relevant to the actual use e.g. it's a specific address, a recognisable bit pattern etc. etc.
>
> Chris Burrows
>
> CFB Software
> Armaide v2.1: LPC2xxx Oberon-07 Development System
> http://www.cfbsoftware.com/armaide
>
Thanks for the tip. Ill edit my code now...

Also for the other guy i dont disable interrupts. Its enabled all the time but i do not start counting until i need to this ensure me to save CPU time and avoids any not needed interrupts. Ill be sure to just turn on counting. and have it check/blink led in ISR.
Here it is:

//*-- Company: AtomSoft ..... Author: Jason Lopez --*/
/*-- Please download --- UM10139: Volume 1: LPC214x User Manual --*/
/*-- As i will refer to it for more info here... --*/

#include
#include

#define LED1 10

#define GET0(bit) ((FIO0PIN>>(bit))&1)
#define GET1(bit) ((FIO1PIN>>(bit))&1)

#define HIGH0(bit) (FIO0SET = 1<<(bit))
#define LOW0(bit) (FIO0CLR = 1<<(bit))

#define HIGH1(bit) (FIO1SET = 1<<(bit))
#define LOW1(bit) (FIO1CLR = 1<<(bit))
void Initialize(void);
int main(void);
void Init_ISR(void);
void ToggleLED(void);
void Delay500mS(void);
volatile char fhmS;
volatile int en;

void Initialize(void) {
PLL0CON=0x0;
PLL0FEED=0xAA;
PLL0FEED=0x55;

VPBDIV=0x01;
SCS = 0x03;
}

void Init_ISR(void) {
fhmS = 0;

T0TCR = 0x02;
T0IR = 0xFF;
T0MCR = 0x0003;
T0MR0 = 6000000;

VICVectCntl0 = 0x00000024;
VICVectAddr0 = (unsigned)ToggleLED;
VICIntEnable = 0x00000010;
T0TCR = 0x01;
en = libarm_set_irq(1);
}

void ToggleLED(void) {
T0IR = 1;
fhmS = ~fhmS;

if(fhmS)
HIGH0(LED1);
else
LOW0(LED1);

libarm_set_irq(en);
}
int main(void){
int x;

Initialize();
Init_ISR();

PINSEL0=0x00000000;
FIO0MASK = ~(1< FIO0DIR=0xFFFFFFFF;

T0TCR = 0x01;

while(1){
}
}
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 7 17:57:29 2009

hey guys not sure if you would be proud of what ive recently create. Its untested but have a look.

Using a 12 MHZ processor you can use this to delay:

Microseconds, Milliseconds and Seconds with a timer.

Not sure it it works just yet but i hope it does :D
void delay(int length, int type) {
switch(type){
case 0:
type = 12; //uS
break;
case 1:
type = 12000; //mS
break;
case 2:
type = 12000000; //S
break;
default:
type = 0;
break;
}
Timer_Flag = 1;
T0MR0 = (length * type);
T0TCR = 0x01;
while(Timer_Flag);
}

void delay_isr(void){
T0IR = 1;
Timer_Flag = 0;
libarm_set_irq(en);
}

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: LPC2148 Blink Tutorial - Paul Curtis - Aug 7 18:33:19 2009

On Fri, 07 Aug 2009 22:55:59 +0100, atomsoftlive
wrote:

> hey guys not sure if you would be proud of what ive recently create.
> Its untested but have a look.
>
> Using a 12 MHZ processor you can use this to delay:
>
> Microseconds, Milliseconds and Seconds with a timer.
>
> Not sure it it works just yet but i hope it does :D
> void delay(int length, int type) {
> switch(type){
> case 0:
> type = 12; //uS
> break;
> case 1:
> type = 12000; //mS
> break;
> case 2:
> type = 12000000; //S
> break;
> default:
> type = 0;
> break;
> }
> Timer_Flag = 1;
> T0MR0 = (length * type);
> T0TCR = 0x01;
> while(Timer_Flag);
> }
>
> void delay_isr(void){
> T0IR = 1;
> Timer_Flag = 0;
> libarm_set_irq(en);
^^^^^^^^^^^^^^^^^^ ????????

-- Paul.
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 7 19:46:06 2009

It works!!! i made this code before with old delays and i altered it with new ones using the timer stuff...

This is a Sony IR Receiver with info displayed on a Nokia 7110 display and a uart terminal at 19200:

#include

#define GETBIT(var,bit) (((var)>>(bit))&1)
#define SETBIT(var,bit) ((var)|=(1<<(bit)))
#define CLRBIT(var,bit) ((var)&=(~(1<<(bit))))

#define LCDP IOPIN1
#define CS 21 //1
#define DC 22 //2
#define SCL 23 //5
#define SDO 24 //6
#define RST 25 //7

#define irP IOPIN1
#define irPin 16 //IR IN

#define LED1 10
#define LED2 11

#define Buzz1 12
#define Buzz2 13
int BuzzL;
int BuzzF;
char BuzzD;

volatile int Timer_Flag;
volatile int en;
#define BTN 15
/*
LCD | DESC | PIN-COLOR WIRE
--------------------------------------------

--------------------------------------------
2 | CS | 1.LIGHT BLUE
--------------------------------------------
4 | D/C | 2.ORANGE
--------------------------------------------
5 | SCL | 5.BLUE
--------------------------------------------
13 | DATA | 6.WHITE - BLACK
--------------------------------------------
14 | RESET | 7.WHITE - LIGHT BLUE
--------------------------------------------
*/
int main(void);
void Initialize(void);
void feed(void);

void CLS(void);
void LCD_Init(void);
void LCD_Reset(void);
void SendByte(unsigned char data);
void LCD_Send(unsigned char cmd, unsigned char type);
void LCDChar(unsigned char letter,unsigned char font,unsigned char style,unsigned char top, unsigned char left);
void LCDString(const char *str,unsigned char font,unsigned char style,unsigned char top, unsigned char left);
void LCDImage(const char *image,char top, char left);
void GetSIRC(char *address, char *command);

void UART1_Init(void);
static void UART1_SendString(char *text,char clear);

void Init_ISR(void);
void delay(int length, int type);
void delay_isr(void);

void DisplayAll(char *text,unsigned char font,unsigned char style,unsigned char top, unsigned char left, char clear);

const char Font5x7 [] = {
0x00,0x00,0x00,0x00,0x00, // 20 space
0x00,0x00,0x5f,0x00,0x00, // 21 !
0x00,0x07,0x00,0x07,0x00, // 22 "
0x14,0x7f,0x14,0x7f,0x14, // 23 #
0x24,0x2a,0x7f,0x2a,0x12, // 24 $
0x23,0x13,0x08,0x64,0x62, // 25 %
0x36,0x49,0x55,0x22,0x50, // 26 &
0x00,0x05,0x03,0x00,0x00, // 27 '
0x00,0x1c,0x22,0x41,0x00, // 28 (
0x00,0x41,0x22,0x1c,0x00, // 29 )
0x14,0x08,0x3e,0x08,0x14, // 2a *
0x08,0x08,0x3e,0x08,0x08, // 2b +
0x00,0x50,0x30,0x00,0x00, // 2c ,
0x08,0x08,0x08,0x08,0x08, // 2d -
0x00,0x60,0x60,0x00,0x00, // 2e .
0x20,0x10,0x08,0x04,0x02, // 2f /
0x3e,0x51,0x49,0x45,0x3e, // 30 0
0x00,0x42,0x7f,0x40,0x00, // 31 1
0x42,0x61,0x51,0x49,0x46, // 32 2
0x21,0x41,0x45,0x4b,0x31, // 33 3
0x18,0x14,0x12,0x7f,0x10, // 34 4
0x27,0x45,0x45,0x45,0x39, // 35 5
0x3c,0x4a,0x49,0x49,0x30, // 36 6
0x01,0x71,0x09,0x05,0x03, // 37 7
0x36,0x49,0x49,0x49,0x36, // 38 8
0x06,0x49,0x49,0x29,0x1e, // 39 9
0x00,0x36,0x36,0x00,0x00, // 3a :
0x00,0x56,0x36,0x00,0x00, // 3b ;
0x08,0x14,0x22,0x41,0x00, // 3c <
0x14,0x14,0x14,0x14,0x14, // 3d =
0x00,0x41,0x22,0x14,0x08, // 3e >
0x02,0x01,0x51,0x09,0x06, // 3f ?
0x32,0x49,0x79,0x41,0x3e, // 40 @
0x7e,0x11,0x11,0x11,0x7e, // 41 A
0x7f,0x49,0x49,0x49,0x36, // 42 B
0x3e,0x41,0x41,0x41,0x22, // 43 C
0x7f,0x41,0x41,0x22,0x1c, // 44 D
0x7f,0x49,0x49,0x49,0x41, // 45 E
0x7f,0x09,0x09,0x09,0x01, // 46 F
0x3e,0x41,0x49,0x49,0x7a, // 47 G
0x7f,0x08,0x08,0x08,0x7f, // 48 H
0x00,0x41,0x7f,0x41,0x00, // 49 I
0x20,0x40,0x41,0x3f,0x01, // 4a J
0x7f,0x08,0x14,0x22,0x41, // 4b K
0x7f,0x40,0x40,0x40,0x40, // 4c L
0x7f,0x02,0x0c,0x02,0x7f, // 4d M
0x7f,0x04,0x08,0x10,0x7f, // 4e N
0x3e,0x41,0x41,0x41,0x3e, // 4f O
0x7f,0x09,0x09,0x09,0x06, // 50 P
0x3e,0x41,0x51,0x21,0x5e, // 51 Q
0x7f,0x09,0x19,0x29,0x46, // 52 R
0x46,0x49,0x49,0x49,0x31, // 53 S
0x01,0x01,0x7f,0x01,0x01, // 54 T
0x3f,0x40,0x40,0x40,0x3f, // 55 U
0x1f,0x20,0x40,0x20,0x1f, // 56 V
0x3f,0x40,0x38,0x40,0x3f, // 57 W
0x63,0x14,0x08,0x14,0x63, // 58 X
0x07,0x08,0x70,0x08,0x07, // 59 Y
0x61,0x51,0x49,0x45,0x43, // 5a Z
0x00,0x7f,0x41,0x41,0x00, // 5b [
0x02,0x04,0x08,0x10,0x20, // 5c 55
0x00,0x41,0x41,0x7f,0x00, // 5d ]
0x04,0x02,0x01,0x02,0x04, // 5e ^
0x40,0x40,0x40,0x40,0x40, // 5f _
0x00,0x01,0x02,0x04,0x00, // 60 `
0x20,0x54,0x54,0x54,0x78, // 61 a
0x7f,0x48,0x44,0x44,0x38, // 62 b
0x38,0x44,0x44,0x44,0x20, // 63 c
0x38,0x44,0x44,0x48,0x7f, // 64 d
0x38,0x54,0x54,0x54,0x18, // 65 e
0x08,0x7e,0x09,0x01,0x02, // 66 f
0x0c,0x52,0x52,0x52,0x3e, // 67 g
0x7f,0x08,0x04,0x04,0x78, // 68 h
0x00,0x44,0x7d,0x40,0x00, // 69 i
0x20,0x40,0x44,0x3d,0x00, // 6a j
0x7f,0x10,0x28,0x44,0x00, // 6b k
0x00,0x41,0x7f,0x40,0x00, // 6c l
0x7c,0x04,0x18,0x04,0x78, // 6d m
0x7c,0x08,0x04,0x04,0x78, // 6e n
0x38,0x44,0x44,0x44,0x38, // 6f o
0x7c,0x14,0x14,0x14,0x08, // 70 p
0x08,0x14,0x14,0x18,0x7c, // 71 q
0x7c,0x08,0x04,0x04,0x08, // 72 r
0x48,0x54,0x54,0x54,0x20, // 73 s
0x04,0x3f,0x44,0x40,0x20, // 74 t
0x3c,0x40,0x40,0x20,0x7c, // 75 u
0x1c,0x20,0x40,0x20,0x1c, // 76 v
0x3c,0x40,0x30,0x40,0x3c, // 77 w
0x44,0x28,0x10,0x28,0x44, // 78 x
0x0c,0x50,0x50,0x50,0x3c, // 79 y
0x44,0x64,0x54,0x4c,0x44, // 7a z
0x00,0x08,0x36,0x41,0x00, // 7b {
0x00,0x00,0x7f,0x00,0x00, // 7c |
0x00,0x41,0x36,0x08,0x00, // 7d }
0x10,0x08,0x08,0x10,0x08, // 7e ~
0x78,0x46,0x41,0x46,0x78}; // 7f ¦

const char RadioShack[] =
{
96,64,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0x80,0xC0,0xC0,0xE0,0xE0,0xE0,0xE0,0x60,0x60,0x60,0x60,0x60,0xE0,0xE0,0xE0,0xE0,
0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0xF8,0x7C,
0x1E,0x0F,0x07,0x07,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x01,0x03,0x03,0x07,0x0F,0x1E,0x3C,0xF8,0xF0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x3F,0x07,0x00,
0x03,0x03,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x07,0x07,0x07,0xFF,0xFF,0xFF,0xFE,0xFE,0xFC,
0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1F,0xFF,0xFC,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xF8,0xC0,
0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0E,0x0E,0x1E,0xFE,0xFF,0xFF,0xFF,0xFB,0xF3,
0xE1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xFF,0x7F,0x0F,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,
0x1F,0x3E,0x7C,0xF8,0xF8,0xFF,0xFF,0xBF,0x3F,0x3F,0x3F,0x38,0x38,0x00,0x00,0x07,0x1F,0x3F,0x3F,
0x3F,0x3F,0x3E,0x38,0x38,0x30,0x80,0x80,0xC0,0xE0,0xF0,0x78,0x3E,0x1F,0x07,0x03,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x07,0x07,0x07,0x0E,0x0E,0x0E,0x0C,0x1C,0x1C,0x1C,0x1C,
0x1C,0x0C,0x0E,0x0E,0x0E,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFC,0xCC,0xCC,0xCC,0xFC,0x78,0x00,0x00,0x80,0xC0,
0xE0,0x60,0x60,0xC0,0xE0,0xE0,0x00,0x00,0x80,0xC0,0xE0,0x60,0x60,0xC0,0xFC,0xFC,0x00,0x00,0xEC,
0xEC,0x00,0x00,0x80,0xC0,0xE0,0x60,0x60,0xE0,0xC0,0x80,0x00,0x00,0x78,0xFC,0xCC,0x8C,0x9C,0x08,
0x00,0x00,0xFC,0xFC,0xC0,0x60,0x60,0xE0,0xC0,0x00,0x00,0x80,0xC0,0xE0,0x60,0x60,0xC0,0xE0,0xE0,
0x00,0x00,0x80,0xC0,0xE0,0x60,0x60,0x60,0xE0,0x40,0x00,0x00,0xFC,0xFC,0x00,0x80,0xC0,0x60,0x20,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x01,0x07,0x1E,0x18,0x00,0x00,0x07,
0x0F,0x1C,0x18,0x18,0x0C,0x1F,0x1F,0x00,0x00,0x07,0x0F,0x1C,0x18,0x18,0x0C,0x1F,0x1F,0x00,0x00,
0x1F,0x1F,0x00,0x00,0x07,0x0F,0x1C,0x18,0x18,0x1C,0x0F,0x07,0x00,0x08,0x0C,0x18,0x18,0x19,0x1F,
0x0F,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x07,0x0F,0x1C,0x18,0x18,0x0C,0x1F,
0x1F,0x00,0x00,0x07,0x0F,0x1C,0x18,0x18,0x18,0x1C,0x08,0x00,0x00,0x1F,0x1F,0x03,0x07,0x0C,0x18,
0x10,0x00,0x00,0x18,0x18,0x00,0x00,0x00
};
const char Font8x8[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , // ASCII - 32
0x00,0x00,0x00,0x5F,0x5F,0x00,0x00,0x00 , // ASCII - 33
0x00,0x00,0x03,0x07,0x00,0x07,0x03,0x00 , // ASCII - 34
0x00,0x10,0x74,0x1C,0x77,0x1C,0x17,0x04 , // ASCII - 35
0x00,0x24,0x2E,0x2A,0x7F,0x2A,0x3A,0x10 , // ASCII - 36
0x00,0x4C,0x6A,0x76,0x1A,0x6A,0x56,0x33 , // ASCII - 37
0x00,0x30,0x7A,0x4F,0x5D,0x37,0x7A,0x48 , // ASCII - 38
0x00,0x00,0x04,0x07,0x03,0x00,0x00,0x00 , // ASCII - 39
0x00,0x00,0x00,0x1C,0x3E,0x63,0x41,0x00 , // ASCII - 40
0x00,0x00,0x41,0x63,0x3E,0x1C,0x00,0x00 , // ASCII - 41
0x00,0x08,0x2A,0x3E,0x1C,0x3E,0x2A,0x08 , // ASCII - 42
0x00,0x08,0x08,0x3E,0x3E,0x08,0x08,0x00 , // ASCII - 43
0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00 , // ASCII - 44
0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00 , // ASCII - 45
0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00 , // ASCII - 46
0x00,0x60,0x30,0x18,0x0C,0x06,0x03,0x01 , // ASCII - 47
0x00,0x1C,0x3E,0x61,0x43,0x3E,0x1C,0x00 , // ASCII - 48
0x00,0x00,0x44,0x7F,0x7F,0x40,0x00,0x00 , // ASCII - 49
0x00,0x46,0x67,0x71,0x59,0x4F,0x66,0x00 , // ASCII - 50
0x00,0x22,0x63,0x49,0x4D,0x7F,0x32,0x00 , // ASCII - 51
0x00,0x18,0x1C,0x52,0x7F,0x7F,0x50,0x00 , // ASCII - 52
0x00,0x2F,0x6F,0x45,0x45,0x7D,0x39,0x00 , // ASCII - 53
0x00,0x3C,0x7E,0x4B,0x49,0x79,0x30,0x00 , // ASCII - 54
0x00,0x07,0x43,0x71,0x7D,0x0F,0x03,0x00 , // ASCII - 55
0x00,0x36,0x7F,0x4D,0x59,0x7F,0x36,0x00 , // ASCII - 56
0x00,0x06,0x4F,0x49,0x69,0x3F,0x1E,0x00 , // ASCII - 57
0x00,0x00,0x00,0x66,0x66,0x00,0x00,0x00 , // ASCII - 58
0x00,0x00,0x00,0x66,0x66,0x00,0x00,0x00 , // ASCII - 59
0x00,0x00,0x08,0x1C,0x36,0x63,0x41,0x00 , // ASCII - 60
0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00 , // ASCII - 61
0x00,0x00,0x41,0x63,0x36,0x1C,0x08,0x00 , // ASCII - 62
0x00,0x02,0x07,0x51,0x59,0x0F,0x06,0x00 , // ASCII - 63
0x00,0x3E,0x41,0x5D,0x55,0x5D,0x51,0x1E , // ASCII - 64
0x00,0x40,0x70,0x1D,0x17,0x1F,0x78,0x60 , // ASCII - 65
0x00,0x41,0x7F,0x7F,0x49,0x4F,0x7E,0x30 , // ASCII - 66
0x00,0x1C,0x3E,0x63,0x41,0x41,0x42,0x27 , // ASCII - 67
0x00,0x41,0x7F,0x7F,0x41,0x63,0x3E,0x1C , // ASCII - 68
0x00,0x41,0x7F,0x7F,0x49,0x5D,0x41,0x63 , // ASCII - 69
0x00,0x41,0x7F,0x7F,0x49,0x1D,0x01,0x03 , // ASCII - 70
0x00,0x1C,0x3E,0x63,0x41,0x51,0x72,0x77 , // ASCII - 71
0x00,0x7F,0x7F,0x08,0x08,0x7F,0x7F,0x00 , // ASCII - 72
0x00,0x00,0x41,0x7F,0x7F,0x41,0x00,0x00 , // ASCII - 73
0x00,0x30,0x70,0x41,0x41,0x7F,0x3F,0x01 , // ASCII - 74
0x00,0x7F,0x7F,0x08,0x1C,0x77,0x63,0x41 , // ASCII - 75
0x00,0x41,0x7F,0x7F,0x41,0x40,0x60,0x70 , // ASCII - 76
0x00,0x7F,0x7E,0x0C,0x18,0x0C,0x7E,0x7F , // ASCII - 77
0x00,0x7F,0x7E,0x0C,0x18,0x30,0x7F,0x7F , // ASCII - 78
0x00,0x1C,0x3E,0x63,0x41,0x63,0x3E,0x1C , // ASCII - 79
0x00,0x41,0x7F,0x7F,0x49,0x09,0x0F,0x06 , // ASCII - 80
0x00,0x1C,0x3E,0x63,0x51,0x63,0x3E,0x1C , // ASCII - 81
0x00,0x7F,0x7F,0x09,0x19,0x7F,0x66,0x40 , // ASCII - 82
0x00,0x66,0x6F,0x4D,0x59,0x7B,0x33,0x00 , // ASCII - 83
0x00,0x03,0x41,0x7F,0x7F,0x41,0x03,0x00 , // ASCII - 84
0x00,0x3F,0x7F,0x40,0x40,0x40,0x7F,0x3F , // ASCII - 85
0x00,0x03,0x0F,0x3D,0x70,0x1D,0x07,0x01 , // ASCII - 86
0x00,0x0F,0x7F,0x30,0x1C,0x30,0x7F,0x0F , // ASCII - 87
0x00,0x63,0x77,0x1C,0x1C,0x77,0x63,0x00 , // ASCII - 88
0x01,0x03,0x47,0x7C,0x78,0x47,0x03,0x01 , // ASCII - 89
0x00,0x67,0x73,0x59,0x4D,0x67,0x73,0x00 , // ASCII - 90
0x00,0x00,0x00,0x7F,0x7F,0x41,0x41,0x00 , // ASCII - 91
0x00,0x01,0x03,0x06,0x0C,0x18,0x30,0x60 , // ASCII - 92
0x00,0x00,0x41,0x41,0x7F,0x7F,0x00,0x00 , // ASCII - 93
0x00,0x00,0x04,0x06,0x03,0x06,0x04,0x00 , // ASCII - 94
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , // ASCII - 95
0x00,0x00,0x01,0x03,0x06,0x04,0x00,0x00 , // ASCII - 96
0x00,0x68,0x6C,0x54,0x54,0x3C,0x78,0x40 , // ASCII - 97
0x00,0x41,0x7F,0x3F,0x6C,0x44,0x7C,0x38 , // ASCII - 98
0x00,0x38,0x7C,0x44,0x44,0x6C,0x2C,0x00 , // ASCII - 99
0x00,0x38,0x7C,0x44,0x49,0x3F,0x7F,0x40 , // ASCII - 100
0x00,0x38,0x7C,0x54,0x54,0x5C,0x58,0x00 , // ASCII - 101
0x00,0x00,0x48,0x7E,0x7F,0x49,0x0B,0x02 , // ASCII - 102
0x00,0x48,0x7C,0x34,0x34,0x2C,0x68,0x44 , // ASCII - 103
0x00,0x41,0x7F,0x7F,0x08,0x04,0x7C,0x78 , // ASCII - 104
0x00,0x00,0x44,0x7D,0x7D,0x40,0x00,0x00 , // ASCII - 105
0x00,0x60,0x60,0x04,0x7D,0x7D,0x00,0x00 , // ASCII - 106
0x00,0x41,0x7F,0x7F,0x10,0x78,0x6C,0x44 , // ASCII - 107
0x00,0x00,0x41,0x7F,0x7F,0x40,0x00,0x00 , // ASCII - 108
0x00,0x7C,0x7C,0x0C,0x78,0x0C,0x7C,0x78 , // ASCII - 109
0x00,0x44,0x7C,0x7C,0x08,0x04,0x7C,0x78 , // ASCII - 110
0x00,0x38,0x7C,0x44,0x44,0x7C,0x38,0x00 , // ASCII - 111
0x00,0x04,0x7C,0x78,0x24,0x24,0x3C,0x18 , // ASCII - 112
0x00,0x18,0x3C,0x24,0x24,0x78,0x7C,0x00 , // ASCII - 113
0x00,0x44,0x7C,0x78,0x4C,0x04,0x1C,0x18 , // ASCII - 114
0x00,0x48,0x5C,0x5C,0x74,0x74,0x24,0x00 , // ASCII - 115
0x00,0x00,0x04,0x3E,0x7F,0x44,0x24,0x00 , // ASCII - 116
0x00,0x3C,0x7C,0x40,0x40,0x3C,0x7C,0x40 , // ASCII - 117
0x00,0x04,0x1C,0x3C,0x60,0x30,0x1C,0x04 , // ASCII - 118
0x00,0x1C,0x7C,0x30,0x1C,0x30,0x7C,0x1C , // ASCII - 119
0x00,0x44,0x6C,0x3C,0x10,0x78,0x6C,0x44 , // ASCII - 120
0x00,0x44,0x4C,0x1C,0x70,0x64,0x1C,0x0C , // ASCII - 121
0x00,0x4C,0x64,0x74,0x5C,0x4C,0x64,0x00 , // ASCII - 122
0x00,0x08,0x08,0x3E,0x77,0x41,0x41,0x00 , // ASCII - 123
0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00 , // ASCII - 124
0x00,0x41,0x41,0x77,0x3E,0x08,0x08,0x00 , // ASCII - 125
0x00,0x02,0x01,0x01,0x03,0x02,0x02,0x01 , // ASCII - 126
0x00,0x60,0x78,0x4E,0x47,0x5E,0x78,0x60}; // ASCII - 127

#define None 0x00
#define Strike 0x10
#define DblStrike 0x24
#define Underline 0x80
#define Overline 0x01

char cmdTmp;
char devTmp;
int main(void){
char MyDat;
int i,j,k;
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
PLL0CON=0x0;
PLL0FEED=0xAA;
PLL0FEED=0x55;

VPBDIV=0x01;

SETBIT(IOPIN0,LED2);
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

PINSEL0=0x00000000;
IODIR0=0xFFFFFFFF;

PINSEL1=0x00000000;
IODIR1=0xFFFFFFFF;

CLRBIT(IODIR0,BTN);
CLRBIT(IODIR1,irPin);

Init_ISR();
LCD_Init();
UART1_Init(); //19200bps 8-N-1

SETBIT(IODIR0,Buzz1);
SETBIT(IODIR0,Buzz2);

while(1){
CLS();
LCDString("AtomSoftTech ",0,None,0,0);
LCDString(" .info",0,None,1,0);
LCDString("Nokia 7110 LCD ",0,None,3,0);
LCDString("Sony IR Test ",0,None,4,0);
LCDString("UART1 ",0,None,5,0);
LCDString("Author: ",1,Underline,6,0);
LCDString("Jason Lopez ",0,None,7,0);

UART1_SendString("AtomSoftTech.info",1);
UART1_SendString(" \r\n \r\n",0);
UART1_SendString("Nokia 7110 LCD\r\n",0);
UART1_SendString("Sony IR\r\n",0);
UART1_SendString("UART1\r\n",0);
UART1_SendString("Author: Jason Lopez\r\n",0);

delay(3,2);

//CLS();
//LCDImage(RadioShack,0,0);
//while(GETBIT(IOPIN0,BTN));
//DelayMs(400);

BuzzD = 0;
BuzzL = 500;
CLS();
LCDString("Waiting for Sony",0,None,0,0);
LCDString("Infrared Data...",0,None,1,0);
LCDString("Device:",0,None,3,0);
LCDString("Command:",0,None,5,0);

UART1_SendString("Waiting for Sony Infrared Data...\r\n",1);
UART1_SendString("Device: ...\r\n",0);
UART1_SendString("Command: ...\r\n",0);

while(GETBIT(IOPIN0,BTN)){
GetSIRC(&devTmp, &cmdTmp);
delay(100,1);
LCDString(" ",0,None,4,0);
LCDString(" ",0,None,6,0);

LCDChar(((devTmp>>4)+0x30),0,None,4,0);
LCDChar(((devTmp&0x0F)+0x30),0,None,4,7);

LCDChar(((cmdTmp>>4)+0x30),0,None,6,0);
LCDChar(((cmdTmp&0x0F)+0x30),0,None,6,7);

switch(cmdTmp){
case 0x00:
BuzzF = 200;
SETBIT(IOPIN0,LED2);
CLRBIT(IOPIN0,LED1);
break;
case 0x01:
BuzzF = 300;
SETBIT(IOPIN0,LED1);
CLRBIT(IOPIN0,LED2);
break;
case 0x02:
BuzzF = 400;
break;
case 0x03:
BuzzF = 500;
break;
case 0x04:
BuzzF = 600;
break;
case 0x05:
BuzzF = 700;
break;
case 0x06:
BuzzF = 800;
break;
case 0x07:
BuzzF = 900;
break;
case 0x08:
BuzzF = 1000;
break;
case 0x09:
BuzzF = 1100;
break;
case 0x15:
//BuzzD
CLRBIT(IOPIN0,Buzz2);
if(BuzzD == 1){
for(k=0;k for(j=0;j<10;j++){
SETBIT(IOPIN0,Buzz1);
for (i=k; i; i--);
CLRBIT(IOPIN0,Buzz1);
for (i=k; i; i--);
}
}
BuzzD = 0;
} else {
for(k=BuzzL;k>0;k-=1){
for(j=0;j<10;j++){
SETBIT(IOPIN0,Buzz1);
for (i=k; i; i--);
CLRBIT(IOPIN0,Buzz1);
for (i=k; i; i--);
}
}
BuzzD = 1;
}

BuzzF = 0;
break;
default:
BuzzF = 0;
break;
}

UART1_SendString("Waiting for Sony Infrared Data...\r\n",1);

UART1_SendString("Device: ",0);
U1THR = ((devTmp>>4)+0x30);
U1THR = ((devTmp&0x0F)+0x30);

UART1_SendString("\r\nCommand: ",0);
U1THR = ((cmdTmp>>4)+0x30);
U1THR = ((cmdTmp&0x0F)+0x30);

CLRBIT(IOPIN0,Buzz2);

for(j=0;j SETBIT(IOPIN0,Buzz1);
for (i=BuzzF; i; i--);
CLRBIT(IOPIN0,Buzz1);
for (i=BuzzF; i; i--);
}

}
delay(400,0);

}

}

void GetSIRC(char *address, char *command){
char ir_add;
char ir_cmd;
char x, lTime;
char pinTmp;

StartLook:
ir_add = ir_cmd = 0;

pinTmp = GETBIT(irP,irPin);
while(pinTmp){
pinTmp = GETBIT(irP,irPin);
} //wait for it to be low
lTime = 0; //reset the counter

while(!pinTmp){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
delay(200,0);
pinTmp = GETBIT(irP,irPin);
}

if(lTime <= 10) //Start too short
goto StartLook; //Restart
if(lTime >= 14) //Start too long
goto StartLook; //Restart

lTime = 0;
for(x=0;x<7;x++){ //repeat 7 times for command
ir_cmd >>= 1; //if it was skipped or is done ORing then shift over the 1

while(GETBIT(irP,irPin)); //wait for it to be low
lTime = 0; //reset the counter

while(GETBIT(irP,irPin) == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
delay(200,0);
}

if(lTime >= 6) //If its high then OR a 1 in else skip
ir_cmd |= 0x40; //if its less than 6 its a 0 so dont OR it

}
for(x=0;x<5;x++){ //repeat 5 times for address/device
ir_add >>= 1; //if it was skipped or is done ORing then shift over the 1

while(GETBIT(irP,irPin)); //wait for it to be low
lTime = 0; //reset the counter

while(GETBIT(irP,irPin) == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
delay(200,0);
}

if(lTime >= 6) //If its high then OR a 1 in else skip
ir_add |= 0x10; //if its less than 6 its a 0 so dont OR it
}

*address = ir_add;
*command = ir_cmd;
}
unsigned char GetPin(unsigned long tPin){
unsigned long tmp;
delay(8,1);
tmp = IOPIN0 & (1< if(tmp == 0)
return 0;
else
return 1;
}

void LCD_Init(void){

SETBIT(IOPIN0,BTN);
SETBIT(LCDP,DC);

delay(8,1);
LCD_Reset();
LCD_Send(0xA6,0); //Display: Normal
LCD_Send(0xA3,0); //LCD Bias Settings: 1/7
LCD_Send(0xA1,0); //ADC Selection: Reverse
LCD_Send(0xC0,0); //Common Output: Normal Direction
//LCD_Send(0xC8,0); //Common Output: Upside Down
LCD_Send(0x22,0); //Set the V5 output Voltage
LCD_Send(0x81,0); //Set Electronic Volume Register
LCD_Send(0x2E,0); //Power Controller Set: Booster circuit: ON/Voltage regulator circuit: ON/Voltage follower circuit: OFF
LCD_Send(0x2F,0); //Power Controller Set: Voltage follower circuit: ON
LCD_Send(0xE3,0); //Non-OPeration Command
LCD_Send(0x40,0); //Set the start line
LCD_Send(0xAF,0); //LCD On
LCD_Send(0xA5,0); //Display All Points: ON
delay(17,1);
LCD_Send(0xA4,0); //Display All Points: NORMAL

}

void CLS(void){
unsigned char i,x;
unsigned char line;
line = 0xB0;

for(x=0;x<9;x++){
LCD_Send(line,0);
LCD_Send(17,0);
LCD_Send(2,0);

for(i=0;i<0x60;i++){
LCD_Send(0x00,1);
}
line++;
}
}

void SendByte(unsigned char data){
char x;

for(x=0;x<8;x++){
CLRBIT(LCDP,SCL);
CLRBIT(LCDP,SDO);

if(data & 0x80)
SETBIT(LCDP,SDO);

SETBIT(LCDP,SCL);
data <<= 1;
}
}

void LCD_Send(unsigned char cmd, unsigned char type){
if(type){
SETBIT(LCDP,DC);
} else {
CLRBIT(LCDP,DC);
}

CLRBIT(LCDP,CS);
SendByte(cmd);
SETBIT(LCDP,CS);
}

void LCD_Reset(void){
SETBIT(LCDP,CS);
delay(8,1);
SETBIT(LCDP,RST);
delay(8,1);
}
void LCDChar(unsigned char letter,unsigned char font,unsigned char style,unsigned char top, unsigned char left){
unsigned char myData,x;
unsigned char leftH,leftL;

top += 0xB0;
left += 18;
leftH = (left >> 4) | 0x10 ;
leftL = left & 0x0F ;

LCD_Send(top,0); //Page 0 (0xBx (x = page))
LCD_Send(leftH,0); //Column Upper Nybble (0x1x) (x = upper Nybble)
LCD_Send(leftL,0); //Column Lower Nybble (0x0x) (x = upper Nybble)

letter -= 0x20;

if(font){
for(x=0;x<8;x++){
myData = Font8x8[((letter*8) + x)] | style;
LCD_Send(myData,1);
}
} else {
for(x=0;x<5;x++){
myData = Font5x7[((letter*5) + x)] | style;
LCD_Send(myData,1);
}
}
LCD_Send((0|style),1); //Spacer
}
void LCDString(const char *str,unsigned char font,unsigned char style,unsigned char top, unsigned char left){
while(*str != 0){
LCDChar(*str++, font, style, top, left);
if(font)
left += 9;
else
left += 6;
}
}
void LCDImage(const char *image,char top, char left){

unsigned char widthLoop, heightLoop;
unsigned char leftH, leftL;
unsigned char width, height;
unsigned char temp;

width = *image++;
height = *image++;

height /= 8;

top += 0xB0;
//LCD_Send(top,0);

left += 18;

leftH = (left >> 4) | 0x10 ;
leftL = left & 0x0F ;

for(heightLoop=0;heightLoop LCD_Send(top,0);
LCD_Send(leftH,0);
LCD_Send(leftL,0);
for(widthLoop=0;widthLoop temp = *image++;
LCD_Send(temp,1);
}
top++;
}
}

void UART1_Init(void)
{
PINSEL0 |= 0x00050000;
U1LCR = 0x83;
U1DLM = 0;
U1DLL = 0x27;
U1FCR = 0x07;
U1LCR = 0x03;
}

static void UART1_SendString(char *text, char clear){
if(clear == 1){
U1THR = 27;
U1THR = '[';
U1THR = '2';
U1THR = 'J';
}
while(*text != 0){
U1THR = *text++;
delay(500,0);
}
}

void DisplayAll(char *text,unsigned char font,unsigned char style,unsigned char top, unsigned char left, char clear){
int txtLen = 0;

if(clear == 1){
U1THR = 27;
U1THR = '[';
U1THR = '2';
U1THR = 'J';
}

while(*text != 0){
U1THR = *text++;
txtLen++;
delay(500,0);
}

UART1_SendString(" \r\n",0);

text -= txtLen;
while(*text != 0){
LCDChar(*text++, font, style, top, left);

if(font)
left += 9;
else
left += 6;

}
}

void Init_ISR(void) {
T0TCR = 0x02;
T0IR = 0xFF;
T0MCR = 0x0003;
T0MR0 = 6000000;

VICVectCntl0 = 0x00000024;
VICVectAddr0 = (unsigned)delay_isr;
VICIntEnable = 0x00000010;
//T0TCR = 0x01;
en = libarm_set_irq(1);
}

void delay(int length, int type){
switch(type){
case 0:
type = 12;
break;
case 1:
type = 12000;
break;
case 2:
type = 12000000;
break;
}

Timer_Flag = 1;

T0TCR = 0x02;
T0IR = 0xFF;
T0MCR = 0x0003;
T0MR0 = length * type;
T0TCR = 0x01;

while(Timer_Flag);
T0TCR = 0x02;
}

void delay_isr(void){
T0IR = 1;
Timer_Flag = 0;
libarm_set_irq(en);
}
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: LPC2148 Blink Tutorial - Wouter van Ooijen - Aug 9 5:34:36 2009

> T0MR0 = 6000000; // 500ms assuming a 12Mhz PCLK

IMHO better: T0MR0 = 6 * 1000 * 1000;

A human (tested with a representative sample of size 1 ) can recognize
only up to 3 (maybe 4) 0's immediately.

IMHO still better: show the calculation, based on a #define PCLK macro
constant.

--

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: www.voti.nl/hvu

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 9 7:01:10 2009

--- In l...@yahoogroups.com, Wouter van Ooijen wrote:
>
> > T0MR0 = 6000000; // 500ms assuming a 12Mhz PCLK
>
> IMHO better: T0MR0 = 6 * 1000 * 1000;
>
> A human (tested with a representative sample of size 1 ) can recognize
> only up to 3 (maybe 4) 0's immediately.
>
> IMHO still better: show the calculation, based on a #define PCLK macro
> constant.
>
> --
>
> Wouter van Ooijen
>
> -- -------------------------------------------
> Van Ooijen Technische Informatica: www.voti.nl
> consultancy, development, PICmicro products
> docent Hogeschool van Utrecht: www.voti.nl/hvu
>

Ok will do! thanks. Ill try it now.

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 9 7:04:25 2009

Here we go better?

/*-- Company: AtomSoft ..... Author: Jason Lopez --*/
/*-- Please download --- UM10139: Volume 1: LPC214x User Manual --*/
/*-- As i will refer to it for more info here... --*/

#include
#include

#define LED1 10
#define LED2 11
#define LED3 25
#define GET0(bit) ((FIO0PIN>>(bit))&1)
#define GET1(bit) ((FIO1PIN>>(bit))&1)

#define HIGH0(bit) (FIO0SET = 1<<(bit))
#define LOW0(bit) (FIO0CLR = 1<<(bit))

#define HIGH1(bit) (FIO1SET = 1<<(bit))
#define LOW1(bit) (FIO1CLR = 1<<(bit))

#define MyClock 12

void Initialize(void);
int main(void);
void Init_ISR(void);
void ToggleLED(void);
void Delay500mS(void);
volatile char fhmS;
volatile int tmp;
volatile int en;
volatile int Timer_Flag;

void Initialize(void) {
PLL0CON=0x0;
PLL0FEED=0xAA;
PLL0FEED=0x55;

VPBDIV=0x01;
SCS = 0x03;

HIGH0(LED2);
HIGH1(LED3);
}

void Init_ISR(void) {
fhmS = 0;

T0TCR = 0x02;
T0IR = 0xFF;
T0MCR = 0x0003;
T0MR0 = 6000000;

VICVectCntl0 = 0x00000024;
VICVectAddr0 = (unsigned)ToggleLED;
VICIntEnable = 0x00000010;
//T0TCR = 0x01;
en = libarm_set_irq(1);
}

void ToggleLED(void) {
T0IR = 1;
fhmS = ~fhmS;

if(fhmS){
HIGH0(LED1);
LOW1(LED3);
} else {
LOW0(LED1);
HIGH1(LED3);
}

libarm_set_irq(en);
}
int main(void){
int x;

Initialize();
Init_ISR();

PINSEL0=0x00000000;
PINSEL1=0x00000000;
FIO0MASK = ~(1< FIO0DIR=0xFFFFFFFF;
FIO1MASK = ~(1< FIO1DIR=0xFFFFFFFF;

T0TCR = 0x01;
delay(2,2);
while(1){
}
}
void delay(int length, int type) {
switch(type){
case 0:
type = MyClock;
break;
case 1:
type = MyClock * 1000;
break;
case 2:
type = MyClock * 1000 * 1000;
break;
default:
type = 0;
break;
}

Timer_Flag = 1;

T0TCR = 0x02;
T0IR = 0xFF;
T0MCR = 0x0003;
T0MR0 = length * type;
T0TCR = 0x01;

while(Timer_Flag);
}

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2148 Blink Tutorial - atomsoftlive - Aug 9 7:31:56 2009

Heh that last code update was messed up. Im not sure how my code got mixed like that but everyone can see my close nice and clear here...
http://atomsofttech.info/index.php?option=com_content&view=article&id=57:tmrblink&catid=36:arm&Itemid=55

or goto http://atomsofttech.info and click on

Latest News
then
Blinking With a Timer

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )