Esempio n. 1
0
 public void send(byte data)
 {
     for (int i = 0; i < 8; i++)
     {
         _clock.Write(false);
         _data.Write((data & 1) > 0 ? true : false);
         data >>= 1;
         _clock.Write(true);
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <summary>
        /// Sends 8 bit command to the DS1620
        /// </summary>
        /// <param name="command">The command</param>
        private void SendCommand(int command)
        {
            // Sends 8 bit command on DQ output, least sig bit first
            int n, bit;

            for (n = 0; n < 8; n++)
            {
                bit = ((command >> n) & (0x01));
                _dq.Write((bit == 1));
                _clk.Write(false);
                _clk.Write(true);
            }
        }
Esempio n. 4
0
        public TM16XX(GPIO data, GPIO clock, GPIO strobe, int displays, bool activateDisplay, int intensity)
        {
            // Set the pins
            _data     = data;
            _clock    = clock;
            _strobe   = strobe;
            _displays = displays;

            _strobe.Write(true);
            _clock.Write(true);

            sendCommand(0x40);
            sendCommand((byte)(0x80 | (activateDisplay ? 0x08 : 0x00) | Math.Min(7, intensity)));

            _strobe.Write(false);
            send(0xC0);
            for (int i = 0; i < 16; i++)
            {
                send(0x00);
            }
            _strobe.Write(true);
        }
Esempio n. 5
0
        public void setupDisplay(bool active, int intensity)
        {
            sendCommand((byte)(0x80 | (active ? 8 : 0) | Math.Min(7, intensity)));

            // necessary for the TM1640
            _strobe.Write(false);
            _clock.Write(false);
            _clock.Write(true);
            _strobe.Write(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Send the commands to retrieve the temperature
        /// </summary>
        /// <returns>The temperature with a half degree granularity</returns>
        private double GetTemperature()
        {
            _rst.Write(false);
            _clk.Write(true);
            _rst.Write(true);
            SendCommand(0x0c); // write config command
            SendCommand(0x02); // cpu mode
            _rst.Write(false);
            Thread.Sleep(200); // wait until the configuration register is written
            _clk.Write(true);
            _rst.Write(true);
            SendCommand(0xEE); // start conversion
            _rst.Write(false);
            Thread.Sleep(200);
            _clk.Write(true);
            _rst.Write(true);
            SendCommand(0xAA);
            int raw_data = ReadData();

            _rst.Write(false);
            return((double)raw_data / 2.0);
        }
Esempio n. 7
0
        public TM16XX(GPIO data, GPIO clock, GPIO strobe, int displays, bool activateDisplay, int intensity)
        {
            // Set the pins
            _data = data;
            _clock = clock;
            _strobe = strobe;
            _displays = displays;

            _strobe.Write(true);
            _clock.Write(true);

            sendCommand(0x40);
            sendCommand((byte)(0x80 | (activateDisplay ? 0x08 : 0x00) | Math.Min(7, intensity)));

            _strobe.Write(false);
            send(0xC0);
            for (int i = 0; i < 16; i++)
            {
                send(0x00);
            }
            _strobe.Write(true);
        }