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); }
#pragma small #include <reg51.h> #include <stdio.h typedef unsigned char byte; typedef unsigned short word; sbit CONVST = P1^5; sbit SCLK = P1^6; sbit DOUT = P1^7; word ad_in; word Adata; void read_ad(void); 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); } void main(void) { read_ad(); Adata = ad_in; }
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.
Use ad_in |= DOUT; This will work. Jon
Thanks for the help. ad_in |= DOUT; works Glenn