Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LPC2148 Delays

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hey guys since i had some help from other at LPC2000 i decided to help here. I made this code my self! but was helped in timer code like how to use it right by some people there.

Ok for my lpc i chose to run at 12 MHZ meaning 12,000,000 ticks per second.

so know this you can easily arrive at:

1 uS = 12 ticks
1 mS = 12,000 ticks
1 S = 12,000,000

Now here is my code which set ups the timer and then starts it delaying the amount of time you need...

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

#include <LPC214x.h>
#include <ctl_api.h>

void Initialize(void);
int main(void);
void Init_ISR(void);
void delay_isr(void);

volatile int en;
volatile int Timer_Flag;

void Initialize(void)  {  //12 Mhz
    PLL0CON=0x0;    
    PLL0FEED=0xAA;
    PLL0FEED=0x55;
 
    VPBDIV=0x01;
}

void Init_ISR(void) {
    T0TCR = 0x02;                          
    T0IR  = 0xFF;                           
    T0MCR = 0x0003;                         
    T0MR0 = 6000000; //temp it doesnt matter....
            
    VICVectCntl0 = 0x00000024;              
    VICVectAddr0 = (unsigned)delay_isr;   
    VICIntEnable = 0x00000010;             
                       
    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;
      default:
        type = 0;
        break;
    }

    Timer_Flag = 1;

    T0TCR = 0x02;                          
    T0IR  = 0xFF;                           
    T0MCR = 0x0003;                         
    T0MR0 = length * type;                             
    T0TCR = 0x01;                           
                           
    while(Timer_Flag);
}

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

i will comment them more later
 
Nice new clean code... Blink a LED using a timer. Includes a generic timer delay which can be reused!

It works great!!

**broken link removed**
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top