I'm trying to read the data from an ADC. I'm getting the error message error C193 '+=' bad operand type. If I use '=+' I don't get the error but my data is shifting. My result is a 0 or 1. It should be in the range from 0 to 255. CONVST is the convert command I'm sending to the ADC, SCLK is the clock pulse I'm sending to the ADC, DOUT is the data coming from the ADC, and ad_in is my variable. Any help would be appreciated. Here it the part of the program that's giving me the trouble. void read_ad(void) { data byte i; SCLK = 1; CONVST = 0; ad_in = 0; CONVST = 1; i=8; do { SCLK = 0; ad_in<<=1; SCLK = 1; ad_in += DOUT; } while(--i); }
Hi Glenn, Even assuming the ad_in += DOUT worked did you mean to set bit7 or bit0 in ad_in?, if you want to clock the data into bit0 of ad_in, try replacing the line 'ad_in += DOUT' with :- if (DOUT) /* is the port bit a 1? */ { ad_in++; /* if so, 'shift' bit into result */ // ad_in |= 0x80; /* use this if you meant bit7 */ } Hope this helps, Mark.