Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "LPC214x.h"
- #include "timer.h"
- #include "ADC7.h"
- #include "uart0.h"
- #include <stdio.h>
- int i;
- unsigned int val;
- unsigned int tick;
- const static unsigned short table_sine[64] = // Sine Function Table(12Bit)
- {
- 0x07FF, 0x08C8, 0x098E, 0x0A51,
- 0x0B0F, 0x0BC4, 0x0C71, 0x0D12,
- 0x0DA7, 0x0E2E, 0x0EA5, 0x0F0D,
- 0x0F63, 0x0FA6, 0x0FD7, 0x0FF5,
- 0x0FFF, 0x0FF5, 0x0FD7, 0x0FA6,
- 0x0F63, 0x0F0D, 0x0EA5, 0x0E2E,
- 0x0DA7, 0x0D12, 0x0C71, 0x0BC4,
- 0x0B0F, 0x0A51, 0x098E, 0x08C8,
- 0x07FF, 0x0736, 0x0670, 0x05AD,
- 0x04EF, 0x043A, 0x038D, 0x02EC,
- 0x0257, 0x01D0, 0x0159, 0x00F1,
- 0x009B, 0x0058, 0x0027, 0x0009,
- 0x0000, 0x0009, 0x0027, 0x0058,
- 0x009B, 0x00F1, 0x0159, 0x01D0,
- 0x0257, 0x02EC, 0x038D, 0x043A,
- 0x04EF, 0x05AD, 0x0670, 0x0736
- };
- /*******************************************************/
- //unsigned int min, sec, tick;
- //extern unsigned int tick;
- /*******************************************************/
- void TimerInit(void)
- {
- VPBDIV = 1; // Configure the VPB divi
- T0PR = 60; //Load prescaler
- T0TCR = 2; //Reset counter and prescaler
- T0MR0 = (15-1);
- T0MCR = 3; //On match reset the counter and generate an interrupt
- T0TCR = 1;
- VICVectAddr4 = (unsigned)T0isr; //Set the timer ISR vector address
- VICVectCntl4 = (0x20 | 4); //Set channel
- VICIntEnable |= (1 << 4); //Enable the interrupt
- PINSEL1 &= 0xFFF3FFFF; // Select DAC Pin Connect P0.25
- PINSEL1 |= 0x00080000;
- }
- /*****************************************************/
- void T0isr (void) __irq
- {
- DACR = ((table_sine[i]/4) << 6);
- i++;
- i &= 0x3F;
- tick++;
- T0IR = 1;
- VICVectAddr = 0;
- }
- /*****************************************************/
- void TimerOn(void){}
- void TimerOff(void){}
- void main(void){
- uart_init();
- TimerInit();
- AD7Init();
- printf("Hello\n");
- while(1)
- {
- //printf("val_main = %d tick = %d\n",val,tick);
- printf("val_main tick = %d\n",tick);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment