کسی میتونه برام توضیح بده دقیقا وظیفه این کد چیه؟؟؟و چرا اینجوری مینویسنش؟؟؟
کد برای adc هستش.اینم کل برنامه:
[glow=red,2,300]BEST REGARDS[/glow]
کد:
[left] } while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion return (i >> 6) & 0x03FF; // bit 6:15 is 10 bit AD value[/left][/left] }
کد:
#include "LPC23xx.h[left]"
static unsigned short ADC_Read(void)
{
unsigned int i;
AD0CR |= 0x01000000; // Start A/D Conversion
do
{
i = AD0DR0; // Read A/D Data Register
} while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion
return (i >> 6) & 0x03FF; // bit 6:15 is 10 bit AD value
}
main (void) {
unsigned short current_value,last_value,temp,value,n;
SCS=SCS | 1;
FIO0DIR = 0x00000FF0; /* P0.4..11 defined as Outputs */
/* Power enable, Setup pin, enable and setup AD converter interrupt
*/
PINSEL1 = 0x4000; /* AD0.0 pin function select */
PCONP |= (1 << 12); /* Enable power to AD block */
AD0CR = 0x00200301; /* Power up, PCLK/4, sel AD0.0 */
while(1){
current_value=ADC_Read();
if (current_value!=last_value)
{
value=current_value>>2;
FIO0CLR=0x0ff;
FIO0SET=value<<4;
last_value=current_value;
}
}
return 0;[/left]
