Advertisement
Guest User

LPC2106 Timer 0 with interrupt

a guest
Apr 15th, 2010
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. #include "LPC2000.h"
  2.  
  3. void sys_init();
  4. __attribute__ ((interrupt)) void timer0 (void);
  5.  
  6. int main()
  7. {  
  8.  
  9.     sys_init();
  10.  
  11.     T0_TCR = 0x03;            //Reset counter and prescaler
  12.     T0_PR = 0x30;                 //Load Prescaler register for 1usec tick, formula --> toHex(1msec/(1/pclk))        
  13.     T0_IR = 0x01;             //Reset timer0 interrupt
  14.     T0_MCR = 0x03;                        //interrupt and reset on MR0
  15.     T0_MR0 = 0x01;                        //match to 1 TC iterations
  16.     VICVectCntl0 = 0x00000024;            //use it for Timer 0 Interrupt
  17.     VICVectAddr0 = (unsigned)timer0;      //set interrupt vector 0
  18.     VICIntEnable = 0x00000010;            //enable TIMER0 interrupt
  19.     T0_TCR = 0x01;                        //enable Timer0
  20.  
  21.     GPIO0_IODIR = 0x0F;
  22.     GPIO0_IOCLR = 0x0F;
  23.     while(1);
  24. }
  25.  
  26. __attribute__ ((interrupt)) void timer0 (void)
  27. {
  28.     T0_IR = 0x01;               //clear interrupt
  29.     VICVectAddr = 0;            //end of interrupt - dummy write
  30. }
  31.  
  32.  
  33. //-------------------------------------------------
  34. void sys_init()
  35. {
  36.     /* System Init */
  37.     /* Init PLL */
  38.     SCB_PLLCFG = 0x22;                 //Msel*fosc,  Msel = 3, Psel = 2, fosc = 16MHz
  39.    
  40.     SCB_PLLFEED = 0xAA; SCB_PLLFEED = 0x55;
  41.    
  42.     SCB_PLLCON = 0x01;                         // Enable PLL
  43.     SCB_PLLFEED = 0xAA; SCB_PLLFEED = 0x55;
  44.    
  45.     while ( !(SCB_PLLSTAT & 0x0400) );         // Wait for PLL to lock
  46.    
  47.     SCB_PLLCON = 0x03;                                // Connect PLL as clock source
  48.     SCB_PLLFEED = 0xAA; SCB_PLLFEED = 0x55;
  49.    
  50.     /* Init MAM & Flash memory fetch */
  51.     MAM_MAMCR=0x2;                                    // MAM = flash
  52.     MAM_MAMTIM=0x4;
  53.    
  54.     SCB_VPBDIV =0x01; //pclk = cclk                                            
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement