Hi there,
Just went through discussions, but could not get any satisfactory thread.
I want to control 3 IR sensors and a Ultrasonics.
For IR, I tried to configure port 5, but, it gives error "C67:DP5 Undefined identifier "
the code was: ----------------------------------------------------
#include <reg167.h>
sbit DP5_0 = DP5^0; sbit DP5_1 = DP5^1; sbit DP5_2 = DP5^2; sbit DP5_3 = DP5^3;
unsigned int GetReading (unsigned char channel) { ADCON = 0xB000; ADCON |= channel & 0x000F; /* Select channel to ADST = 1; /* Begin conversion while (ADBSY == 1); /* Wait while the return (ADDAT & 0x03FF) }
void Get_Signal (void)
{ unsigned char i; unsigned int result;
DP5 = 0x000F; P5_1 = 0;
while(1) { for (i = 0; i < 16; i++) { result = GetReading (i); } }
void main(void) { Get_Signal (); for(;;) ; }
------------------------------------------------------- I am using uVision 3.
I would really appreciate if I get an expert's opinion.
Thank you.
Amit
You would perform an A/D conversion on the channel you want to read. Basically like you already coded. I would however modify your code slightly.
#include <reg167.h> unsigned int results[16]; #define ADC_SETTINGS (0xB080) unsigned int GetReading(unsigned int ch) { ADCIR = 0; ADCON = ADC_SETTINGS | (ch & 0xF); while (ADCIR == 0); /* polled mode */ return (ADDAT & 0x3FF); } void Get_Signal (void) { unsigned int i; for (i = 0; i < 2; i++) { results[i] = GetReading(i); } } void main(void) { /* disable digital inputs on P5.0 and P5.1 */ P5DIDIS = 0x0003; /* don't use interrupt, just poll for ADC finished */ ADCIC = 0; /* read the channels */ Get_Signal(); for(;;); }
hey ...thanx !!!
Well, i'll try it out !!!
Chao, Ams