Guest User

Untitled

a guest
Dec 16th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.32 KB | None | 0 0
  1.  
  2. #include "LPC214x.H"                                        // LPC2148 MPU Register
  3. #include <stdio.h>                                          // For Used Function printf
  4. #include "adc7.h"
  5. //#include "uart0.h"
  6.  
  7. /* pototype  section */
  8. //void init_serial0 (void);                                     // Initil UART-0
  9. //int putchar (int ch);                                         // Put Char to UART-0
  10. //int getchar (void);                                       // Get Char From Uart-0
  11. //void delay(unsigned long int);                                // Delay Time Function
  12. //void AD0isr (void)    __irq;
  13.  
  14. //unsigned int val;                                         // ADC Result (HEX)
  15. //unsigned int status0;
  16.  
  17. void AD7Init(void)
  18. {  
  19.       //init_serial0();                                         // Initial UART0 = 9600,N,8,1
  20.       //TimerInit();
  21.       //printf("CP-JR ARM7 USB-LPC2148...TEST ADC7(P0.5)\n");   // Call prinff Function
  22.       //printf("Input Voltage 0-3.3V to P0.5 For Test\n");      // Call prinff Function
  23.    
  24.       // Initial ADC7 (GPIO-0.5) By Set PINSEL0[11:10=11]
  25.       // xxxx xxxx xxxx xxxx xxxx 11xx xxxx xxxx
  26.       PINSEL0 &= 0xFFFFF3FF;                                    // Select ADC7 Pin Connect P0.5
  27.       PINSEL0 |= 0x00000C00;                                   
  28.      
  29.       // Initial ADC0 (ADCR=0x01210680)    
  30.       //AD0INTEN = 0x180;//(1 << 7);                                                // Disable ADC Interrupt
  31.       AD0INTEN=(0x100)|(7<<1);
  32.       AD0CR &= 0x00000000;                                      // Clear All Bit Control
  33.       AD0CR |= 0x00000080;                                      // Select ADC = AIN7
  34.       AD0CR |= 0x00000600;                                      // ADC Clock = VBP(PCLK) / 7
  35.       AD0CR |= 0x00010000;                                      // Busrt = 1 = Conversion Continue
  36.       AD0CR &= 0xFFF1FFFF;                                      // CLKS = 000 = 10Bit : 11 Cycle Clock Conversion
  37.       AD0CR |= 0x00200000;                                      // PDN = 1 = Active ADC Module
  38.       AD0CR &= 0xFF3FFFFF;                                      // TEST[1:0] = 00 = Normal Mode
  39.       AD0CR &= 0xF7FFFFFF;                                      // EDGE = 0 = Conversion on Falling Edge  
  40.       AD0CR |= 0x01000000;                                      // START = 001 = Start Conversion Now
  41.  
  42.         VICVectAddr4 = (unsigned)AD0isr;    //  //Set the timer ISR vector address
  43.         VICVectCntl4 = (0x20 | 18);     //  //Set channel
  44.         VICIntEnable |= (1 << 18);      //  //Enable the interrupt  
  45.         /// / // Start Test Read ADC0 and Display on UART0 //
  46.          // while(1)                                                    // Loop Continue
  47.          // {    
  48.          // } ;
  49. }
  50.  
  51.  void AD0isr (void) __irq
  52. {  
  53.     val = (AD0DR7>>6) & 0x3E8; // (AD0DR6>>6) & 0x3ff;
  54.     val = (val + 50)/5;
  55.     //printf("ADC7 Result = %d \n",val);   
  56.     //TimerInit(); 
  57.     //T0MR0     = (val-1); 
  58.     VICVectAddr = 0;           
  59. }
Advertisement
Add Comment
Please, Sign In to add comment