private int readadc() { if ((adcnum > 7) || adcnum < 0) { return(-1); } cspin.Write(true); clockpin.Write(false); // #start clock low cspin.Write(false); // #bring CS low int commandout = adcnum; commandout |= 0x18; //# start bit + single-ended bit commandout <<= 3; //# we only need to send 5 bits here for (int i = 0; i < 5; i++) { if ((commandout & 0x80) == 128) { mosipin.Write(true); } else { mosipin.Write(false); } commandout <<= 1; clockpin.Write(true); clockpin.Write(false); } int adcout = 0; //# read in one empty bit, one null bit and 10 ADC bits for (int i = 0; i < 12; i++) { clockpin.Write(true); clockpin.Write(false); adcout <<= 1; if (misopin.Read()) { adcout |= 0x1; } } cspin.Write(true); adcout /= 2;//# first bit is 'null' so drop it return(adcout); }
/// <summary> /// Read 8 bit data from the DS1620 /// </summary> /// <returns>The temperature in half degree increments</returns> private int ReadData() { int n; var raw_data = 0; // go into input mode for (n = 0; n < 9; n++) { _clk.Write(false); var bit = _dq.Read() == PinState.High ? 1 : 0; _clk.Write(true); raw_data = raw_data | (bit << n); } Console.WriteLine("bin=" + Convert.ToString(raw_data, 2)); return(raw_data); }
/// <summary> /// Read 8 bit data from the DS1620 /// </summary> /// <returns>The temperature in half degree increments</returns> private int ReadData() { int bit, n; int raw_data = 0; // go into input mode for (n = 0; n < 9; n++) { _clk.Write(false); if (_dq.Read() == true) { bit = 1; } else { bit = 0; } _clk.Write(true); raw_data = raw_data | (bit << n); } Console.WriteLine("bin=" + Convert.ToString(raw_data, 2)); return(raw_data); }
public byte receive() { byte temp = 0; // Pull-up on _data.Write(true); for (int i = 0; i < 8; i++) { temp >>= 1; _clock.Write(false); if (_data.Read()) { temp |= 0x80; } _clock.Write(true); } _data.Write(false); return(temp); }
static void printPin(GPIO pin) { Console.Write(pin.Read() ? "1" : "0"); }