here is the example of the CFAX LCD:
/**********************************************************
Defines
**********************************************************/
#define LCD_ON 0xAF
/* *********************************************************
Function declarations
********************************************************* */
// these are for the LPC2138 internal initialization
void Initialize(void);
void feed(void);
void delay(void);
unsigned int get_LCD_port(unsigned char); // Parses data byte (D7:0) to appropriate IO pins
void LCD_out(unsigned char);
void RD(char stat); // sets / clears the various LCD control lines
void RW(char stat);
void RS(char stat);
void RSTB(char stat);
void LCD_init(void);
void LCD_command(unsigned char); // sends command to LCD
void LCD_write_data(unsigned char, unsigned char, unsigned char); // writes data to memory
void LCD_clear_screen(void);
void LCD_put_char(unsigned char character, unsigned char x, unsigned char y);
void LCD_print_string(char *nate, unsigned char x, unsigned char y);
//touch screen
void TS1(unsigned char);
void TS2(unsigned char);
void TS3(unsigned char);
void TS4(unsigned char);
//unsigned int adc_TS2(void);
//unsigned int adc_TS3(void);
void IRQ_Routine (void) attribute ((interrupt(“IRQ”)));
void FIQ_Routine (void) attribute ((interrupt(“FIQ”)));
void SWI_Routine (void) attribute ((interrupt(“SWI”)));
void UNDEF_Routine (void) attribute ((interrupt(“UNDEF”)));
/**********************************************************
Header files
**********************************************************/
#include “LPC213x.h” // this file contains the I/O definitions for the LPC2138 ARM
/**********************************************************
Global Variables
**********************************************************/
// these are the 5x8 ASCII characters starting with ’ '.
// these should probably be stored in flash or eeprom, but ram works for this simple program.
unsigned char characters =
{ \
0x0,0x0,0x0,0x0,0x0,\
0x0,0x0,0x4F,0x0,0x0,\
0x0,0x7,0x0,0x7,0x0,\
0x14,0x7F,0x14,0x7F,0x14,\
0x24,0x2A,0x7F,0x2A,0x12,\
0x23,0x13,0x8,0x64,0x62,\
0x00,0x02,0x05,0x02,0x00,\
0x0,0x5,0x3,0x0,0x0,\
0x1C,0x22,0x41,0x0,0x0,\
0x0,0x0,0x41,0x22,0x1C,\
0x14,0x8,0x3E,0x8,0x14,\
0x8,0x8,0x3E,0x8,0x8,\
0x0,0x50,0x30,0x0,0x0,\
0x8,0x8,0x8,0x8,0x8,\
0x0,0x60,0x60,0x0,0x0,\
0x20,0x10,0x8,0x4,0x2,\
0x3E,0x51,0x49,0x45,0x3E,\
0x0,0x42,0x7F,0x40,0x0,\
0x42,0x61,0x51,0x49,0x46,\
0x21,0x41,0x45,0x4B,0x31,\
0x18,0x14,0x12,0x7F,0x10,\
0x27,0x45,0x45,0x45,0x39,\
0x3C,0x4A,0x49,0x49,0x30,\
0x1,0x71,0x9,0x5,0x3,\
0x36,0x49,0x49,0x49,0x36,\
0x06,0x49,0x49,0x49,0x36,\
0x0,0x36,0x36,0x0,0x0,\
0x0,0x56,0x36,0x0,0x0,\
0x8,0x14,0x22,0x41,0x0,\
0x14,0x14,0x14,0x14,0x14,\
0x0,0x41,0x22,0x14,0x8,\
0x2,0x1,0x51,0x9,0x6,\
0x32,0x49,0x79,0x41,0x3E,\
0x7E,0x11,0x11,0x11,0x7E,\
0x7F,0x49,0x49,0x49,0x36,\
0x3E,0x41,0x41,0x41,0x22,\
0x7F,0x41,0x41,0x22,0x1C,\
0x7F,0x49,0x49,0x49,0x41,\
0x7F,0x9,0x9,0x9,0x1,\
0x3E,0x41,0x49,0x49,0x7A,\
0x7F,0x8,0x8,0x8,0x7F,\
0x0,0x41,0x7F,0x41,0x0,\
0x20,0x40,0x41,0x3F,0x1,\
0x7F,0x8,0x14,0x22,0x41,\
0x7F,0x40,0x40,0x40,0x40,\
0x7F,0x2,0xC,0x2,0x7F,\
0x7F,0x4,0x8,0x10,0x7F,\
0x3E,0x41,0x41,0x41,0x3E,\
0x7F,0x9,0x9,0x9,0x6,\
0x3E,0x41,0x51,0x21,0x5E,\
0x7F,0x9,0x19,0x29,0x46,\
0x46,0x49,0x49,0x49,0x31,\
0x1,0x1,0x7F,0x1,0x1,\
0x3F,0x40,0x40,0x40,0x3F,\
0x1F,0x20,0x40,0x20,0x1F,\
0x3F,0x40,0x38,0x40,0x3F,\
0x63,0x14,0x8,0x14,0x63,\
0x7,0x8,0x70,0x8,0x7,\
0x61,0x51,0x49,0x45,0x43,\
0x7F,0x41,0x41,0x0,0x0,\
0x2,0x4,0x8,0x10,0x20,\
0x0,0x0,0x41,0x41,0x7F,\
0x4,0x2,0x1,0x2,0x4,\
0x40,0x40,0x40,0x40,0x40,\
0x0,0x1,0x2,0x4,0x0,\
0x20,0x54,0x54,0x54,0x78,\
0x7F,0x48,0x44,0x44,0x38,\
0x38,0x44,0x44,0x44,0x20,\
0x38,0x44,0x44,0x48,0x7F,\
0x38,0x54,0x54,0x54,0x18,\
0x8,0x7E,0x9,0x1,0x2,\
0xC,0x52,0x52,0x52,0x3E,\
0x7F,0x8,0x4,0x4,0x78,\
0x0,0x44,0x7D,0x40,0x0,\
0x0,0x20,0x40,0x44,0x3D,\
0x7F,0x10,0x28,0x44,0x0,\
0x0,0x41,0x7F,0x40,0x0,\
0x7C,0x4,0x18,0x4,0x78,\
0x7C,0x8,0x4,0x4,0x78,\
0x38,0x44,0x44,0x44,0x38,\
0x7C,0x14,0x14,0x14,0x8,\
0x8,0x14,0x14,0x18,0x7C,\
0x7C,0x8,0x4,0x4,0x8,\
0x48,0x54,0x54,0x54,0x20,\
0x4,0x3F,0x44,0x40,0x20,\
0x3C,0x40,0x40,0x20,0x7C,\
0x1C,0x20,0x40,0x20,0x1C,\
0x3C,0x40,0x30,0x40,0x3C,\
0x44,0x28,0x10,0x28,0x44,\
0xC,0x50,0x50,0x50,0x3C,\
0x44,0x64,0x54,0x4C,0x44,\
0x8,0x36,0x41,0x0,0x0,\
0x0,0x0,0x7F,0x0,0x0,\
0x0,0x0,0x41,0x36,0x8,\
0x0,0x8,0x4,0x8,0x4,\
0x0,0x0,0x0,0x0,0x0
};
/**********************************************************
MAIN
**********************************************************/
int main (void) {
unsigned int adc_x = 0;
unsigned int adc_y = 0;
unsigned char c = 0;
unsigned char i, data, j;
// Initialize the MCU
Initialize();
// uncomment this to get touch screen values. The acd functions return raw values and will
// have to be scaled to be usable.
/*
// To read touch screen x, drive TS1 high and TS3 low and read TS4 or TS2
// get touch screen x
TS1(0); // 0 is bit clear, 1 is set, 2 is input
TS2(2);
TS3(1);
TS4(2);
adc_x = adc_TS2();
// vice versa for the y reading.
// get touch screen y
TS1(2);
TS2(1);
TS3(2);
TS4(0);
adc_y = adc_TS3();
delay();
*/
LCD_init();
// Print a string of characters, line number (0 - 7), position on line ( 0 - 127)
LCD_print_string(“Hello Sveta!!”, 0, 0);
LCD_print_string(“Hello World!!”, 1, 10);
LCD_print_string(“Hello Sveta!!”, 2, 20);
LCD_print_string(“Hello World!!”, 3, 30);
LCD_print_string(“Hello Dima!!”, 4, 40);
for (;
{
}
}
//Prints a string
void LCD_print_string(char *line, unsigned char x, unsigned char y)
{
static char k;
static int i;
//static int decimal_output[9];
for(i = 0; ; i++)
{
k = line*;*
if (k == ‘\0’)
break;
LCD_put_char(k, x, ((i * 6) + y));
}
}
void LCD_put_char(unsigned char c, unsigned char x, unsigned char y)
{
- //unsigned char i = 0;*
- c -= 32;*
- unsigned char i;*
- for (i = 0; i < 5; i++)*
- {*
LCD_write_data(characters[(c * 5) + i], x, i + y); - }*
}
// send command to the LCD
void LCD_command(unsigned char command)
{ - RS(0);*
- RD(1);*
- LCD_out(command);*
//PORTD = comm_byte;
//TRISD = 0b.0000.0000; //Turn PORTD to Output
RW(0);
RW(1);
RD(0);
}
// initialize LCD
void LCD_init()
{
RSTB(0);
delay();
RSTB(1);
delay();
LCD_command(LCD_ON); //On LCD
//Best boot 5-1-05
LCD_command(0xA3); //LCD Bias (A2 A3) - First Choice
LCD_command(0x2F); //Turn on internal power control
LCD_command(0x26); //Pseudo-Contrast 7 = dark 6 = OK - First Choice
LCD_command(0x81); //Set contrast
LCD_command(54);
LCD_command(0xC8); //Flip screen on the horizontal to match with the vertical software invertion
*LCD_clear_screen(); *
}
void LCD_clear_screen(void){
unsigned char i, j;
for( i = 0 ; i < 9 ; i++ )
for( j = 0 ; j < 133 ; j++ )
//Data, Page num, Col
LCD_write_data(0x00, i, j);
}
//Writes byte to selected page
void LCD_write_data(unsigned char data, unsigned char page, unsigned char column)
{
-
// make sure column and page are within bounds*
-
page %= 9;*
-
column %= 128;*
-
// set column MSB*
LCD_command(0x10 | ((/*127 - */column) >> 4)); -
// set column LSB*
LCD_command(0x0F & (/*127 - */column)); -
// set page*
-
LCD_command(0xB0 |(0x0F & page));*
//Data write
LCD_out(data);
RD(1);
RS(1);
RW(0);
RW(1);
RD(0); //Must have this! Or else the screen will shimmer black
}
// these functions set / clear pins for LCD control lines. they accecpt a 0 or 1
void RD(char stat)
{
-
IODIR0 |= 0x00040000; // RD is P0.18*
-
if (stat) *
-
IOSET0 |= 0x00040000;*
-
else*
-
IOCLR0 |= 0x00040000;*
}
void RW(char stat)
{ -
IODIR0 |= 0x00020000; // RW is P0.17*
-
if (stat) *
-
IOSET0 |= 0x00020000;*
-
else*
-
IOCLR0 |= 0x00020000;*
}
void RS(char stat)
{ -
IODIR0 |= 0x40000000; // RS is P0.30*
-
if (stat) *
-
IOSET0 |= 0x40000000;*
-
else*
-
IOCLR0 |= 0x40000000;*
}
void RSTB(char stat)
{ -
IODIR0 |= 0x00000080; // RSTB is P0.7*
-
if (stat) *
-
IOSET0 |= 0x00000080;*
-
else*
-
IOCLR0 |= 0x00000080;*
}
void TS4(unsigned char stat)
{ -
// TS4 is P0.3*
-
if (stat == 1) *
-
{*
-
IODIR0 |= 0x00000008; *
-
IOSET0 |= 0x00000008;*
-
}*
-
else if (stat == 0)*
-
{ *
-
IODIR0 |= 0x00000008; *
-
IOCLR0 |= 0x00000008;*
-
}*
-
else*
-
IODIR0 &= ~0x00000008;*
}
void TS3(unsigned char stat)
{ -
// TS3 is P0.4*
-
if (stat == 1) *
-
{*
-
IODIR0 |= 0x00000010; *
-
IOSET0 |= 0x00000010;*
-
}*
-
else if (stat == 0)*
-
{ *
-
IODIR0 |= 0x00000010; *
-
IOCLR0 |= 0x00000010;*
-
}*
-
else*
-
IODIR0 &= ~0x00000010;*
}
void TS2(unsigned char stat)
{ -
// TS2 is P0.5*
-
if (stat == 1) *
-
{*
-
IODIR0 |= 0x00000020; *
-
IOSET0 |= 0x00000020;*
-
}*
-
else if (stat == 0)*
-
{ *
-
IODIR0 |= 0x00000020; *
-
IOCLR0 |= 0x00000020;*
-
}*
-
else*
-
IODIR0 &= ~0x00000020;*
}
void TS1(unsigned char stat)
{ -
// TS1 is P0.6*
-
if (stat == 1) *
-
{*
-
IODIR0 |= 0x00000040; *
-
IOSET0 |= 0x00000040;*
-
}*
-
else if (stat == 0)*
-
{ *
-
IODIR0 |= 0x00000040; *
-
IOCLR0 |= 0x00000040;*
-
}*
-
else*
-
IODIR0 &= ~0x00000040;*
}
int adc_TS2(void)
{ -
static int val;*
-
AD0CR = 0;*
-
AD0DR = 0;*
-
ADGSR = 0;*
-
PINSEL0 = 0x00000C00;*
-
AD0CR = 0x00200680;*
-
AD0CR |= 0x01000000;*
-
//ADGSR = 0x01000000;*
-
do*
-
{*
-
val = AD0DR; // Read A/D Data Register*
-
}*
-
while ((val & 0x80000000) == 0); //Wait for the conversion to complete*
-
val = ((val >> 6) & 0x03FF); //Extract the A/D result*
-
//while(!(AD0DR & 0x80000000));*
-
return val;*
}
int adc_TS3(void)
{ -
static int val2;*
-
AD0CR = 0;*
-
AD0DR = 0;*
-
ADGSR = 0;*
-
PINSEL0 = 0x00000300;*
-
AD0CR = 0x00200640;*
-
AD0CR |= 0x01000000;*
-
//ADGSR = 0x01000000;*
-
do*
-
{*
-
val2 = AD0DR; // Read A/D Data Register*
-
}*
-
while ((val2 & 0x80000000) == 0); //Wait for the conversion to complete*
-
val2 = ((val2 >> 6) & 0x03FF); //Extract the A/D result*
-
//while(!(AD0DR & 0x80000000));*
-
return val2;*
}
// send to the LCD
void LCD_out(unsigned char cmd)
{ -
IODIR0 |= 0x2CF80000; // set lcd data pins to output *
-
IOCLR0 |= 0x2CF80000; // clear all pins*
-
IOSET0 |= get_LCD_port(cmd); // set port*
}
_ /* the lcd connects to the LPC like so:_
_ *_
_ * D0 → P0.19_
_ * D1 → P0.20_
_ * D2 → P0.21_
_ * D3 → P0.22_
_ * D4 → P0.23_
_ * D5 → P0.26_
_ * D6 → P0.27_
_ * D7 → P0.29_
_ *_
_ * this function takes data byte and returns an int that can be_
_ * assigned to these pins_
_ *_
_ *_
_ */_
unsigned int get_LCD_port(unsigned char data)
{ -
return ((data & 0x01) << 19) | ((data & 0x02) << 19) | ((data & 0x04) << 19) |*
-
((data & 0x08) << 19) | ((data & 0x10) << 19) |*
-
((data & 0x20) << 21) | ((data & 0x40) << 21) | ((data & 0x80) << 22);*
}
void delay(void){ -
volatile unsigned int count = 0;*
-
for (count = 0; count < 4000000; count++){*
-
asm volatile (“nop”);*
-
}*
}
/**********************************************************
Initialize
**********************************************************/
#define PLOCK 0x400
void Initialize(void) { -
// Setting the Phased Lock Loop (PLL)*
-
// ----------------------------------*
-
//*
-
// Olimex LPC-P2106 has a 14.7456 mhz crystal*
-
//*
-
// We’d like the LPC2106 to run at 53.2368 mhz (has to be an even multiple of crystal)*
-
//*
-
// According to the Philips LPC2106 manual: M = cclk / Fosc where: M = PLL multiplier (bits 0-4 of PLLCFG)*
-
// cclk = 53236800 hz*
-
// Fosc = 14745600 hz*
-
//*
-
// Solving: M = 53236800 / 14745600 = 3.6103515625*
-
// M = 4 (round up)*
-
//*
-
// Note: M - 1 must be entered into bits 0-4 of PLLCFG (assign 3 to these bits)*
-
//*
-
//*
-
// The Current Controlled Oscilator (CCO) must operate in the range 156 mhz to 320 mhz*
-
//*
_ // According to the Philips LPC2106 manual: Fcco = cclk * 2 * P where: Fcco = CCO frequency_ -
// cclk = 53236800 hz*
-
// P = PLL divisor (bits 5-6 of PLLCFG)*
-
//*
_ // Solving: Fcco = 53236800 * 2 * P_ -
// P = 2 (trial value)*
_ // Fcco = 53236800 * 2 * 2_ -
// Fcc0 = 212947200 hz (good choice for P since it’s within the 156 mhz to 320 mhz range*
-
//*
-
// From Table 19 (page 48) of Philips LPC2106 manual P = 2, PLLCFG bits 5-6 = 1 (assign 1 to these bits)*
-
//*
-
// Finally: PLLCFG = 0 01 00011 = 0x23*
-
//*
-
// Final note: to load PLLCFG register, we must use the 0xAA followed 0x55 write sequence to the PLLFEED register*
-
// this is done in the short function feed() below*
-
//*
-
// Setting Multiplier and Divider values*
-
PLLCFG=0x23;*
-
feed();*
_ // Enabling the PLL */ _
-
PLLCON=0x1;*
-
feed();*
-
// Wait for the PLL to lock to set frequency*
-
while(!(PLLSTAT & PLOCK)) ;*
-
// Connect the PLL as the clock source*
-
PLLCON=0x3;*
-
feed();*
-
// Enabling MAM and setting number of clocks used for Flash memory fetch (4 cclks in this case)*
-
MAMCR=0x2;*
-
MAMTIM=0x4;*
-
// Setting peripheral Clock (pclk) to System Clock (cclk)*
-
VPBDIV=0x1;*
}
void feed(void)
{
PLLFEED=0xAA;
PLLFEED=0x55;
}
/* Stubs for various interrupts (may be replaced later) */
/* ---------------------------------------------------- */
void IRQ_Routine (void) { -
while (1) ; *
}
void FIQ_Routine (void) { -
while (1) ; *
}
void SWI_Routine (void) { -
while (1) ; *
}
void UNDEF_Routine (void) { -
while (1) ; *
}
…
Now how do i incert HEX data into the code in order to preview an image on the screen?