#include "LPC23xx.h"
#define LED1 0x02000000 // P3.25(0000 00x0 0000 0000 0000 0000 0000 0000)
#define LED2 0x04000000 // P3.26(0000 0x00 0000 0000 0000 0000 0000 0000)
#define LED1_ON() FIO3CLR = LED1 // LED1 Pin = 0 (ON LED) http://www.etteam.com
#define LED1_OFF() FIO3SET = LED1 // LED1 Pin = 1 (OFF LED)
#define LED2_ON() FIO3CLR = LED2 // LED2 Pin = 0 (ON LED)
#define LED2_OFF() FIO3SET = LED2 // LED2 Pin = 1 (OFF LED)
void delay_ms(long int ms);
void delay_us();
int main(void)
{
unsigned short table_sine[64]={
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 i,j,k,l;
int count;
unsigned int value,value1,value2;
PCONP &=0xFFF81FFF; //Set up power/clock control bit manual
PCONP |=0x00081000;
PCLKSEL0 = 0x03000000; // Set bit 25:24='11' for the periphiral clock of ADC. This is fastest conversion.
AD0CR = 0x012B0001; // bit 31:28=0, EDGE-bit 27=0, Start-bit 26:24=001, 23:22=00, 21=1, 20=0, 16=0, CLKDIV(4)=0x04, SEL=0x01
PINSEL1 = 0x00004000;
PINSEL7 &= 0xFFC3FFFF; // P3[26:25] = GPIO Function(xxxx xxxx xx00 00xx xxxx xxxx xxxx xxxx)
PINMODE7 &= 0xFFC3FFFF; // Enable Puul-Up on P3[26:25]
FIO3DIR |= LED1; // Set GPIO-3[26:25] = Output(xxxx x11x xxxx xxxx xxxx xxxx xxxx xxxx)
FIO3DIR |= LED2;
// Config DAC
PCLKSEL0 |=0x00400000; //Enable peripheral clock DAC
PINSEL1 |=0x00200000; //Set P0.23 Turn to ADC
PINMODE1 |=0x00200000;
// Set port 4 as input for put botton switch P4.28 and P4.29.
PINSEL9 = 0x00000000;
LED1_ON(); /*http://etteam.com*/
LED2_ON();
k=0;
l=0;
while(1)
{
do
{
value=AD0DR0;
}
while((value & 0x80000000) == 0);
value=(value>>6) & 0x03FF;
for (j=0;j<=value;j++)
{
delay_us();
}
DACR = (table_sine[i]<<4);
i++;
i &= 0x3F;
if(((FIO4PIN & 0x10000000) == 0)&&(k==0))
{
LED1_OFF();
delay_ms(200);
LED1_ON();
value1=value;
k=1;
}
else if (((FIO4PIN & 0x10000000)==0)&&(k==1)&&(l==0))
{
LED2_OFF();
delay_ms(200);
LED2_ON();
value2=value;
l==1;
}
else if ((FIO4PIN & 0x20000000) == 0)
{
LED1_OFF();
LED2_OFF();
delay_ms(200);
LED1_ON();
LED2_ON();
while(1)
{
for (count=0;count<=5;count++)
{
for (i=0;i<=63;i++)
{
DACR = (table_sine[i]<<4);
for (j=0;j<=value1;j++)
{
delay_us();
}
}
}
for (count=0;count<=5;count++)
{
for (i=0;i<=63;i++)
{
DACR = (table_sine[i]<<4);
for (j=0;j<=value2;j++)
{
delay_us();
}
}
}
}
}
}
}
void delay_ms(long int ms)
{
long int i,j;
for(i=0;i<ms;i++)
for(j=0;j<3999;j++);
}
void delay_us()
{
return;
}
dear sir,
i've written a program according to my understanding please check
Code C - [expand] 1 2 3 4 5 6 7 8 9 while((AD0DR0 & 0x80000000)==0); //wait till DONE flag is set ADC_Data = ( regVal >> 6 ) & 0x3FF; //extract data for(i=10;i<=0;) { binary_data[i] = (ADC_Data1 = (ADC_Data%10)); ADC_Data = ADC_Data1; i--; } binary_data[11]='\0';
Code C - [expand] 1 2 3 4 5 6 for(i=0;i<=9;i++) { binary_data[i] = ((ADC_Data>>(9-i)) & 1)+48 // move the bit you want to bit0, use and with 1 to read only that and add 48 to convert 0 to '0' and 1 to '1' } binary_data[10]=0;
bikashh; said:in the above code->correct
for(i=10;i>=0
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 volatile unsigned int i,ADC_Data; volatile unsigned char binary_data[11]; /* P0.23: AD0.0 (A/D converter 0 input 0), pull-up resistor enabled */ PINSEL1=0x00004000; /****************************************************************************** ADC0 ******************************************************************************* ADC operational ADC clk: 3,75 MHz (calculated with peripheral clock: 15MHz) ADC rate: 340,9091 Ksamples/sec manual mode, 11 clocks / 10 bit accuracy Start conversion now. Channel 0 enabled, no interrupt Channel 1 dissabled, no interrupt Channel 2 dissabled, no interrupt Channel 3 dissabled, no interrupt Channel 4 dissabled, no interrupt Channel 5 dissabled, no interrupt Channel 6 dissabled, no interrupt Channel 7 dissabled, no interrupt */ PCONP |= 0x1000; /* Enable peripheral clock for ADC (default is disabled) */ AD0CR=0x01200301; /* binary: 00000001_00100000_00000011_00000001 */ AD0INTEN=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ while((AD0DR0 & 0x80000000)==0); //wait till DONE flag is set ADC_Data = ( AD0DR0 >> 6 ) & 0x3FF; //extract data for(i=0;i<=9;i++) { binary_data[i] = ((ADC_Data>>(9-i)) & 1)+48; // move the bit you want to bit0, use and with 1 to read only that and add 48 to convert 0 to '0' and 1 to '1' } binary_data[10]=0; while(1) { } }
main()
{
Init_UART0(9600);
ADCInit(); // <<<< this line was missing
InitTimer();
while(1)
{
ADC0Read(0);
delay_ms(2000);
}
]
main()
{
Init_UART0(9600);
InitTimer();
while(1)
{
ADC0Read(0);
delay_ms(2000);
}
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 #include <LPC23xx.H> void ADCInit(void) { /* Enable CLOCK into ADC controller */ PCONP |= (1 << 12); /* all the related pins are set to ADC inputs, AD0.0~7 */ PINSEL1 &= ~0x003FC000; /* P0.23~26, A0.0~3, function 01 */ PINSEL1 |= 0x00004000; //select AD0.0 AD0CR = ( 0x01 << 0 ) | /* SEL=1,select channel 0~7 on ADC0 */ ( ( 12000000 / 1000000 - 1 ) << 8 ) | /* CLKDIV = Fpclk / 1000000 - 1 */ ( 0 << 16 ) | /* BURST = 0, no BURST, software controlled */ ( 0 << 17 ) | /* CLKS = 0, 11 clocks/10 bits */ ( 1 << 21 ) | /* PDN = 1, normal operation */ ( 0 << 22 ) | /* TEST1:0 = 00 */ ( 0 << 24 ) | /* START = 0 A/D conversion stops */ ( 0 << 27 ); /* EDGE = 0 (CAP/MAT singal falling,trigger A/D conversion) */ } void ADC0Read( char channelNum ) { volatile unsigned int regVal, ADC_Data;//, ADC_Data1; int i; volatile unsigned char binary_data[12]; AD0CR &= 0xFFFFFFFE; AD0CR |= (1 << 24) | (1 << channelNum); /* switch channel,start A/D convert */ for(i=0;i<13;i++) {binary_data[i]='\0';} while((AD0DR0 & 0x80000000)==0); AD0CR &= 0xF8FFFFFF; /* stop ADC now */ ADC_Data = ( regVal >> 6 ) & 0x3FF; for(i=0;i<=9;i++) { binary_data[i] = ((ADC_Data>>(9-i)) & 1)+48; // move the bit you want to bit0, use and with 1 to read only that and add 48 to convert 0 to '0' and 1 to '1' } binary_data[10]=0; //uart0Puts("ADC BINARY DATA"); //uart0Puts((char*)binary_data); /* return A/D conversion value */ //uart0Puts("\n\r"); } main() { //Init_UART0(9600); ADCInit(); //InitTimer(); while(1) { ADC0Read(0); //delay_ms(2000); } }
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?