LPC2378 Reading the Trimpot example

Download pre-release library modules and new examples to use with Astrobe for LPC2000. Forum members can also upload their own source code examples.
Post Reply
4GlCoder
Posts: 27
Joined: Fri Jul 22, 2011 2:47 pm

LPC2378 Reading the Trimpot example

Post by 4GlCoder » Mon Aug 29, 2011 6:06 pm

Just a minor example of reading the values of the on-board trimpot and displaying the values on screen.

MODULE TrimReader;
(* =========================================================================
Example ARM Oberon-07 Program

Description:
Read the value of the trimpot connected to ADC 0.5.
Display it on the LCdisplay

Target:
OLIMEX LPC-2378-STK

Tested on:
OLIMEX LPC-2378-STK Rev. C

References:
NXP LPC23xx User Manual UM10211
-> chapter 27 ADC
Oberon for LPC2000 Microcontrollers

========================================================================= *)

IMPORT SYSTEM, LPC := LPC2378, ADC, Main, Out, Display, Timer;

PROCEDURE Init;
VAR
bits, dirs, selection: SET;
BEGIN
SYSTEM.GET(LPC.PCONP, bits);
SYSTEM.PUT(LPC.PCONP, bits + {12}); (* ADC section needs power *)

SYSTEM.GET(LPC.SCS, bits);
SYSTEM.PUT(LPC.SCS, bits + {0}); (* configure for GPIO/FIO *)
(* Configure pin connected to trimpot as an ADC input *)
(* P1.31 = Input, AD0.5, PINSEL3 31:30 = 11 *)
SYSTEM.GET(LPC.PINSEL3, selection);
SYSTEM.PUT(LPC.PINSEL3, selection + {30, 31});
(* Configure pin for use without pull-up/down resistors 31:30 = 10 *)
SYSTEM.GET(LPC.PINMODE3, selection);
SYSTEM.PUT(LPC.PINMODE3, selection + {31} - {30});
(* Select buttons for input using Fast IO registers*)
SYSTEM.GET(LPC.FIO1DIR, dirs);
SYSTEM.PUT(LPC.FIO1DIR, dirs - {31}); (* clearing the bit, sets it to input *)
ADC.PowerUp()
END Init;

(* Turning Trim pot to the left (counterclockwise) gives higher values,
clockwise gives lower values
Range of values should be 0..1023 *)

PROCEDURE Run;
VAR
data, olddata : INTEGER;
BEGIN
olddata := -1;
WHILE TRUE DO
ADC.Read(5, data); (* Channel 5 = AD0.5 *)
IF olddata # data THEN
Out.Int(data, 0); Out.Ln;(* show sampled value *)
olddata := data;
Timer.MSecDelay(500)
END
END
END Run;

BEGIN
Display.Init; (* Initialize LCD *)
Out.Init(Display.Char); (* Show output in LCD *)
Init; (* initialize ports *)
Run
END TrimReader.

Post Reply