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
Because there is no P5 (DP5) direction register. There are no output drivers so you cannot configure it as outputs. You can disable the digital inputs (Schmitt triggers) using P5DIDIS register.
Hi Chris,
Thanx for ur reply !! but, still some questions r buggin around..
How my uC is supposed to know that I've connected some sensors n it has to process those???
I've connected 2 IRs on port P5_0 and P5_1....
Ams
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
"How my uC is supposed to know that I've connected some sensors"
In general, it doesn't "know" - you just write the code on the assumption that the sensors will be there, as specified in your design requirements...
If there is a possibility that the sensors may not be there, then you will need to design-in facilities to detect them - that will certainly require additional software, and probably also additional hardware.
If there is the further possibility that different types of sensors may be connected, then you will need to design-in further facilities to identify them and select the appropriate handling...