arunbharathi.arasu
Full Member level 2
- Joined
- Feb 28, 2013
- Messages
- 134
- Helped
- 7
- Reputation
- 14
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- Chennai, Tamil Nadu, India
- Activity points
- 2,151
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include <lpc21xx.h> unsigned val = 0; int main(void) { VPBDIV = 0x02; //Set the Pclk to 30 Mhz IODIR1 = 0x00FF0000; // P1.16..23 defined as Outputs ADCR = 0x00270601; // Setup A/D: 10-bit AIN0 @ 3MHz ADCR |= 0x01000000; // Start A/D Conversion while(1) { do { val = ADDR; // Read A/D Data Register } while ((val & 0x80000000) == 0); //Wait for the conversion to complete val = ((val >> 6) & 0x03FF)<<16; //Extract the A/D result IOCLR1 = ~val; //write the result onto the LED pins IOSET1 = val; } }
main()
{
init();
SOC;
wait;
put the result in output;
init();
SOC;
wait;
put the result in output;
while(1);
}
void vADC_Init(void)
{
uint32_t SystemFrequency=12000000;
uint32_t ADC_CLK=1000000;
uint32_t PCLKDIV, PCLK;
LPC_SC->PCONP |= (1 << 12);
LPC_PINCON->PINSEL1 |= (1<<14);
PCLKDIV = (LPC_SC->PCLKSEL0 >> 24) & 0x03;
switch ( PCLKDIV )
{
case 0x00:
default: PCLK = SystemFrequency/4; break;
case 0x01: PCLK = SystemFrequency; break;
case 0x02: PCLK = SystemFrequency/2; break;
case 0x03: PCLK = SystemFrequency/8; break;
}
LPC_ADC->ADCR = ( 1 << 0 ) |
( ( PCLK / ADC_CLK - 1 ) << 8 ) |
( 0 << 16 ) |
( 0 << 17 ) |
( 1 << 21 ) |
( 0 << 24 ) |
( 0 << 27 );
}
int main(void)
{
LPC_GPIO2->FIODIR=0x00000FFF;
LPC_GPIO2->FIOCLR=0x00000FFF;
vADC_Init();
LPC_ADC->ADCR |= 1 << 24;
while(!(LPC_ADC->ADGDR & (1 << 31)));
int curVal=( LPC_ADC->ADDR0 >> 4 ) & 0xFFF;
LPC_GPIO2->FIOSET=curVal;
}
ADC_INT()
{
uint32_t systemfrequency = 12000000;
uint32_t ADC_CLK = 1000000;
uint32_t PCLKDIV,PCLK;
LPC_SC->PCONP |= (1<<12);
LPC_PINCON->PINSEL1 |= (1<<14);
PCLKDIV = (LPC_SC->PCLKSEL0 >>24) & 0X03;
switch(PCLKDIV)
{
case 0x00:default: PCLK =systemfrequency/4;break;
case 0x01: PCLK = systemfrequency;break;
case 0x02: PCLK = systemfrequency/2;break;
case 0x03: PCLK = systemfrequency/8;break;
}
LPC_ADC->ADCR |= (1<<0)
|((PCLK / ADC_CLK -1) << 8)
|(0<<16)
|(0<<17)
|(1<<21)
|(0<<24)
|(0<<27);
}
ADC_Read()
{
uint32_t cur_val;
LPC_ADC->ADCR |= (1<<24);
while(!(LPC_ADC->ADGDR & (1<<31)));
LPC_ADC->ADCR |=(0<<24);
cur_val = (LPC_ADC->ADDR0 >>4) & 0XFFF;
LPC_GPIO2->FIOSET = cur_val;
}
LED_BLINK()
{
LPC_GPIO2->FIOSET = 0X000000FF;
delay(1000);
LPC_GPIO2->FIOCLR = 0X000000FF;
delay(1000);
}
void delay(uint32_t val)
{
uint32_t i,j;
for(i=0;i<val;i++);
for(j=0;j<10000000;j++);
}
void main()
{
LPC_GPIO2->FIODIR = 0X00000FFF;
LPC_GPIO2->FIOCLR = 0X00000FFF;
ADC_INT();
while(1)
{
ADC_Read();
delay(100000);
LED_BLINK();
delay(100000);
}
}
Code C - [expand] 1 2 LPC_GPIO2->FIOCLR = 0xFFF; //Add this line in your pro... LPC_GPIO2->FIOSET = cur_val;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?