Increase your Embedded skills with our new online classes (from Just Rs750/-) for details click here

Home > Code Library > LPC2378 interface with LED C Code

LPC2378 interface with LED C Code

November 28th, 2009 Leave a comment Go to comments

LPC2378 interface with LED C Code:

arm lpc2378 led interface circuit

#include <iolpc2378.h>

#include “irq.h”

#include “config.h”

void delay()

{

unsigned int i,j;

for(i=0;i<0x3fff;i++)

for(j=0;j<0xff;j++);

}

int main (void)

{

unsigned int Fdiv;

TargetResetInit();

PINSEL0 = 0×00000050; /* RxD0 and TxD0 */

U0LCR = 0×83; /* 8 bits, no Parity, 1 Stop bit */

Fdiv = ( Fpclk / 16 ) / 19200 ; /*baud rate */

U0DLM = Fdiv / 256;

U0DLL = Fdiv % 256;

U0LCR = 0×03; /* DLAB = 0 */

U0FCR = 0×07; /* Enable and reset TX and RX FIFO. */

FIO3DIR = 0X008000FF;

while(1)

{

FIO3PIN = 0X000000ff;

delay();

FIO3PIN = 0X00000000;

delay();

}

}

Config.h

#if USE_USB /* 1 is USB, 0 is non-USB related */

/* Fcck = 57.6Mhz, Fosc = 288Mhz, and USB 48Mhz */

#define PLL_MValue 11

#define PLL_NValue 0

#define CCLKDivValue 4

#define USBCLKDivValue 5

/* System configuration: Fosc, Fcclk, Fcco, Fpclk must be defined */

/* PLL input Crystal frequence range 4KHz~20MHz. */

#define Fosc 12000000

/* System frequence,should be less than 80MHz. */

#define Fcclk 57600000

#define Fcco 288000000

#else

/* Fcck = 50Mhz, Fosc = 300Mhz, and USB 48Mhz */

#define PLL_MValue 24

#define PLL_NValue 1

#define CCLKDivValue 5

#define USBCLKDivValue 6

/* System configuration: Fosc, Fcclk, Fcco, Fpclk must be defined */

/* PLL input Crystal frequence range 4KHz~20MHz. */

#define Fosc 12000000

/* System frequence,should be less than 80MHz. */

#define Fcclk 50000000

#define Fcco 300000000

#endif

/* APB clock frequence , must be 1/2/4 multiples of ( Fcclk/4 ). */

/* If USB is enabled, the minimum APB must be greater than 16Mhz */

#if USE_USB

#define Fpclk (Fcclk / 2)

#else

#define Fpclk (Fcclk / 4)

#endif

void init_VIC(void)

{

long i = 0;

long *vect_addr, *vect_cntl;

/* initialize VIC*/

VICIntEnClear = 0xffffffff;

VICAddress = 0;

VICIntSelect = 0;

/* set all the vector and vector control register to 0 */

for ( i = 0; i < VIC_SIZE; i++ )

{

vect_addr = (long *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + i*4);

vect_cntl = (long *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + i*4);

*vect_addr = 0×0;

*vect_cntl = 0xF;

}

return;

}

void GPIOResetInit( void )

{

/* Reset all GPIO pins to default: primary function */

PINSEL0 = 0×00000000;

PINSEL1 = 0×00000000;

PINSEL2 = 0×00000000;

PINSEL3 = 0×00000000;

PINSEL4 = 0×00000000;

PINSEL5 = 0×00000000;

PINSEL6 = 0×00000000;

PINSEL7 = 0×00000000;

PINSEL8 = 0×00000000;

PINSEL9 = 0×00000000;

PINSEL10 = 0×00000000;

IO0DIR = 0×00000000;

IO1DIR = 0×00000000;

FIO0DIR = 0×00000000;

FIO1DIR = 0×00000000;

FIO2DIR = 0×00000000;

FIO3DIR = 0×00000000;

FIO4DIR = 0×00000000;

FIO0MASK = 0×00000000;

FIO1MASK = 0×00000000;

FIO2MASK = 0×00000000;

FIO3MASK = 0×00000000;

FIO4MASK = 0×00000000;

return;

}

void ConfigurePLL ( void )

{

long MValue, NValue;

if ( PLLSTAT & (1 << 25) )

{

PLLCON = 1; /* Enable PLL, disconnected */

PLLFEED = 0xaa;

PLLFEED = 0×55;

}

PLLCON = 0; /* Disable PLL, disconnected */

PLLFEED = 0xaa;

PLLFEED = 0×55;

SCS |= 0×20; /* Enable main OSC */

while( !(SCS & 0×40) ); /* Wait until main OSC is usable */

CLKSRCSEL = 0×1; /* select main OSC, 12MHz, as the PLL clock source */

PLLCFG = PLL_MValue | (PLL_NValue << 16);

PLLFEED = 0xaa;

PLLFEED = 0×55;

PLLCON = 1; /* Enable PLL, disconnected */

PLLFEED = 0xaa;

PLLFEED = 0×55;

CCLKCFG = CCLKDivValue; /* Set clock divider */

#if USE_USB

USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */

#endif

while ( ((PLLSTAT & (1 << 26)) == 0) ); /* Check lock bit status */

MValue = PLLSTAT & 0x00007FFF;

NValue = (PLLSTAT & 0x00FF0000) >> 16;

while ((MValue != PLL_MValue) && ( NValue != PLL_NValue) );

PLLCON = 3; /* enable and connect */

PLLFEED = 0xaa;

PLLFEED = 0×55;

while ( ((PLLSTAT & (1 << 25)) == 0) ); /* Check connect bit status */

return;

}

void TargetResetInit(void)

{

/* This if-else statement detects if interrupt vectors located by the linker

command file are at memory location 0 or not. */

#pragma segment = “INTVEC”

if (( void * )0x00000000UL == __segment_begin( “INTVEC” ))

{

MEMMAP = 1; // normal flash mode

}

else

{

MEMMAP = 2 ; // user ram mode – Map lowest 64 bytes of the address space to

// bottom of internal RAM, moving exception vectors into place

}

#if USE_USB

PCONP |= 0×80000000; /* Turn On USB PCLK */

#endif

/* Configure PLL, switch from IRC to Main OSC */

ConfigurePLL();

/* Set system timers for each component */

#if (Fpclk / (Fcclk / 4)) == 1

PCLKSEL0 = 0×00000000; /* PCLK is 1/4 CCLK */

PCLKSEL1 = 0×00000000;

#endif

#if (Fpclk / (Fcclk / 4)) == 2

PCLKSEL0 = 0xAAAAAAAA; /* PCLK is 1/2 CCLK */

PCLKSEL1 = 0xAAAAAAAA;

#endif

#if (Fpclk / (Fcclk / 4)) == 4

PCLKSEL0 = 0×55555555; /* PCLK is the same as CCLK */

PCLKSEL1 = 0×55555555;

#endif

/* Set memory accelerater module*/

MAMCR = 0;

#if Fcclk < 20000000

MAMTIM = 1;

#else

#if Fcclk < 40000000

MAMTIM = 2;

#else

MAMTIM = 3;

#endif

#endif

MAMCR = 2;

GPIOResetInit();

init_VIC();

return;

}

IRQ.h:

/******************************************************************************

* irq.h: Interrupt related Header file for NXP LPC230x Family

* Microprocessors

*

* ******************************************************************************/

#ifndef __IRQ_H

#define __IRQ_H

#define I_Bit 0×80

#define F_Bit 0×40

#define SYS32Mode 0x1F

#define IRQ32Mode 0×12

#define FIQ32Mode 0×11

#define HIGHEST_PRIORITY 0×01

#define LOWEST_PRIORITY 0x0F

#define WDT_INT 0

#define SWI_INT 1

#define ARM_CORE0_INT 2

#define ARM_CORE1_INT 3

#define TIMER0_INT 4

#define TIMER1_INT 5

#define UART0_INT 6

#define UART1_INT 7

#define PWM0_1_INT 8

#define I2C0_INT 9

#define SPI0_INT 10 /* SPI and SSP0 share VIC slot */

#define SSP0_INT 10

#define SSP1_INT 11

#define PLL_INT 12

#define RTC_INT 13

#define EINT0_INT 14

#define EINT1_INT 15

#define EINT2_INT 16

#define EINT3_INT 17

#define ADC0_INT 18

#define I2C1_INT 19

#define BOD_INT 20

#define EMAC_INT 21

#define USB_INT 22

#define CAN_INT 23

#define MCI_INT 24

#define GPDMA_INT 25

#define TIMER2_INT 26

#define TIMER3_INT 27

#define UART2_INT 28

#define UART3_INT 29

#define I2C2_INT 30

#define I2S_INT 31

#define VIC_SIZE 32

#define VIC_BASE_ADDR ((unsigned int)&VICIRQStatus)

#define VECT_ADDR_INDEX 0×100

#define VECT_CNTL_INDEX 0×200

void init_VIC( void );

long install_irq( long IntNumber, void *HandlerAddr, long Priority );

#endif /* end __IRQ_H */

/******************************************************************************

** End Of File

******************************************************************************/

include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
<iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}#include <iolpc2378.h>
#include “irq.h”
#include “config.h”
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0×00000050;              /* RxD0 and TxD0 */
U0LCR = 0×83;                     /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ;   /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0×03;                   /* DLAB = 0 */
U0FCR = 0×07;   /* Enable and reset TX and RX FIFO. */
FIO3DIR = 0X008000FF;
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
}
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.