Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "LPC214x.H" // LPC2148 MPU Register
- #include <stdio.h>
- #include "Timer.h"
- #include "uart0.h" // For Used Function printf
- /* pototype section */
- void init_serial0 (void); // Initil UART-0
- int putchar (int ch); // Put Char to UART-0
- int getchar (void); // Get Char From Uart-0
- void delay(unsigned long int); // Delay Time Function
- unsigned int val; // ADC Result (HEX)
- int i = 0;
- int volt=0;
- 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
- };
- int main(void)
- {
- uart_init(); // Initial UART0 = 9600,N,8,1
- printf("\nCP-JR ARM7 USB-LPC2148...TEST ADC7(P0.5)\n"); // Call prinff Function
- printf("Input Voltage 0-3.3V to P0.5 For Test\n"); // Call prinff Function
- // Initial ADC7 (GPIO-0.5) By Set PINSEL0[11:10=11]
- // xxxx xxxx xxxx xxxx xxxx 11xx xxxx xxxx
- PINSEL0 &= 0xFFFFF3FF; // Select ADC7 Pin Connect P0.5
- PINSEL0 |= 0x00000C00;
- // Initial ADC0 (ADCR=0x01210680)
- AD0INTEN = (0x100)|(7<<1); // Disable ADC Interrupt
- AD0CR &= 0x00000000; // Clear All Bit Control
- AD0CR |= 0x00000080; // Select ADC = AIN7
- AD0CR |= 0x00000600; // ADC Clock = VBP(PCLK) / 7
- AD0CR |= 0x00010000; // Busrt = 1 = Conversion Continue
- AD0CR &= 0xFFF1FFFF; // CLKS = 000 = 10Bit : 11 Cycle Clock Conversion
- AD0CR |= 0x00200000; // PDN = 1 = Active ADC Module
- AD0CR &= 0xFF3FFFFF; // TEST[1:0] = 00 = Normal Mode
- AD0CR &= 0xF7FFFFFF; // EDGE = 0 = Conversion on Falling Edge
- AD0CR |= 0x01000000; // START = 001 = Start Conversion Now
- // Start Test Read ADC0 and Display on UART0 //
- while(1) // Loop Continue
- {
- do // Loop Read ADC1
- {
- val = AD0DR7; // Read A/D Data Register
- }
- while ((val & 0x80000000) == 0); // Wait ADC Conversion Complete
- val = (val >> 6) & 0x03E8; // Shift ADC Result to Integer
- //volt = val * 3.3 / 1023.0;
- val = (val+50)/50; // Volt = ADC Result x [3.3V / 1024]
- printf("ADC7 Result = %d Volt.\n",val); // Display 3-Digit Result(0-3.3V)
- val = val/64;
- TimerInit();
- delay(10000);
- }
- }
- /***********************/
- /* Delay Time Function */
- void delay(unsigned long int count1)
- {
- while(count1 > 0) {count1--;} // Loop Decrease Counter
- }
- void TimerInit(void)
- {
- VPBDIV = 1; //Configure the VPB divi
- T0PR = 60; //Load prescaler
- T0TCR = 2; //Reset counter and prescaler
- T0MR0 = ((val)-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;
- T0IR = 1;
- VICVectAddr = 0;
- //printf("val = %d\n",val);
- }
- void TimerOn(void){}
- void TimerOff(void){}
Add Comment
Please, Sign In to add comment