Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "LPC2000.h"
- void sys_init();
- __attribute__ ((interrupt)) void timer0 (void);
- int main()
- {
- sys_init();
- T0_TCR = 0x03; //Reset counter and prescaler
- T0_PR = 0x30; //Load Prescaler register for 1usec tick, formula --> toHex(1msec/(1/pclk))
- T0_IR = 0x01; //Reset timer0 interrupt
- T0_MCR = 0x03; //interrupt and reset on MR0
- T0_MR0 = 0x01; //match to 1 TC iterations
- VICVectCntl0 = 0x00000024; //use it for Timer 0 Interrupt
- VICVectAddr0 = (unsigned)timer0; //set interrupt vector 0
- VICIntEnable = 0x00000010; //enable TIMER0 interrupt
- T0_TCR = 0x01; //enable Timer0
- GPIO0_IODIR = 0x0F;
- GPIO0_IOCLR = 0x0F;
- while(1);
- }
- __attribute__ ((interrupt)) void timer0 (void)
- {
- T0_IR = 0x01; //clear interrupt
- VICVectAddr = 0; //end of interrupt - dummy write
- }
- //-------------------------------------------------
- void sys_init()
- {
- /* System Init */
- /* Init PLL */
- SCB_PLLCFG = 0x22; //Msel*fosc, Msel = 3, Psel = 2, fosc = 16MHz
- SCB_PLLFEED = 0xAA; SCB_PLLFEED = 0x55;
- SCB_PLLCON = 0x01; // Enable PLL
- SCB_PLLFEED = 0xAA; SCB_PLLFEED = 0x55;
- while ( !(SCB_PLLSTAT & 0x0400) ); // Wait for PLL to lock
- SCB_PLLCON = 0x03; // Connect PLL as clock source
- SCB_PLLFEED = 0xAA; SCB_PLLFEED = 0x55;
- /* Init MAM & Flash memory fetch */
- MAM_MAMCR=0x2; // MAM = flash
- MAM_MAMTIM=0x4;
- SCB_VPBDIV =0x01; //pclk = cclk
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement