maygapixel

Untitled

Dec 16th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.06 KB | None | 0 0
  1. #include "LPC214x.h"
  2. #include "timer.h"
  3. #include "ADC7.h"
  4. #include "uart0.h"
  5. #include <stdio.h>
  6.  
  7. int i;
  8. unsigned int val;
  9. unsigned int tick;
  10. const static unsigned short table_sine[64] =                // Sine Function Table(12Bit)
  11.           {
  12.             0x07FF, 0x08C8, 0x098E, 0x0A51,    
  13.             0x0B0F, 0x0BC4, 0x0C71, 0x0D12,
  14.             0x0DA7, 0x0E2E, 0x0EA5, 0x0F0D,
  15.             0x0F63, 0x0FA6, 0x0FD7, 0x0FF5,
  16.             0x0FFF, 0x0FF5, 0x0FD7, 0x0FA6,
  17.             0x0F63, 0x0F0D, 0x0EA5, 0x0E2E,
  18.             0x0DA7, 0x0D12, 0x0C71, 0x0BC4,
  19.             0x0B0F, 0x0A51, 0x098E, 0x08C8,
  20.             0x07FF, 0x0736, 0x0670, 0x05AD,
  21.             0x04EF, 0x043A, 0x038D, 0x02EC,
  22.             0x0257, 0x01D0, 0x0159, 0x00F1,
  23.             0x009B, 0x0058, 0x0027, 0x0009,
  24.             0x0000, 0x0009, 0x0027, 0x0058,
  25.             0x009B, 0x00F1, 0x0159, 0x01D0,
  26.             0x0257, 0x02EC, 0x038D, 0x043A,
  27.             0x04EF, 0x05AD, 0x0670, 0x0736  
  28.           };   
  29.  
  30. /*******************************************************/
  31. //unsigned int min, sec, tick;
  32. //extern unsigned int tick;
  33. /*******************************************************/
  34.  void TimerInit(void)
  35. {
  36.     VPBDIV      = 1;            // Configure the  VPB divi
  37.     T0PR        = 60;           //Load prescaler
  38.     T0TCR       = 2;            //Reset counter and prescaler
  39.     T0MR0       = (15-1);  
  40.     T0MCR       = 3;            //On match reset the counter and generate an interrupt         
  41.     T0TCR       = 1;
  42.    
  43.     VICVectAddr4 = (unsigned)T0isr;     //Set the timer ISR vector address
  44.     VICVectCntl4 = (0x20 | 4);          //Set channel
  45.     VICIntEnable |= (1 << 4);           //Enable the interrupt
  46.    
  47.     PINSEL1 &= 0xFFF3FFFF;                                  // Select DAC Pin Connect P0.25
  48.     PINSEL1 |= 0x00080000;         
  49. }
  50. /*****************************************************/
  51. void T0isr (void)   __irq
  52. {  
  53.     DACR = ((table_sine[i]/4) << 6);
  54.     i++;
  55.     i &= 0x3F;
  56.     tick++;
  57.     T0IR = 1;          
  58.     VICVectAddr = 0;           
  59. }
  60.  
  61. /*****************************************************/  
  62. void TimerOn(void){}
  63. void TimerOff(void){}
  64.  
  65.  
  66. void main(void){
  67.     uart_init();
  68.     TimerInit();
  69.     AD7Init();
  70.     printf("Hello\n");
  71.     while(1)
  72.     {
  73.     //printf("val_main = %d tick = %d\n",val,tick);
  74.     printf("val_main  tick = %d\n",tick);
  75.  
  76.     }
  77.    
  78. }
Advertisement
Add Comment
Please, Sign In to add comment