ArmandoCircuitos
Inicio
Electronica
Programacion
Resultado
Codigo
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Threading; namespace Medidor_temperatura_LPT_01 { public partial class Form1 : Form { class ControlPort { [DllImport("inpout32.dll", EntryPoint = "Out32")] public static extern void Output(int adress, int value); [DllImport("inpout32.dll", EntryPoint = "Inp32")] public static extern char Input(int adress); } public Form1() { InitializeComponent(); } int puerto, i, adc1, medida; double celcius, kelvin, fahrenheit; private void Form1_Load(object sender, EventArgs e) { ControlPort.Output(0x378, 0x02); //CS HIGH } private void timer1_Tick(object sender, EventArgs e) { adc1 = 0; ControlPort.Output(0x378, 0x00); //CS LOW for (i = 0; i < 10; i++) //Ciclo para leer el primer ADC { ControlPort.Output(0x378, 0x01); Thread.Sleep(1); ControlPort.Output(0x378, 0x00); Thread.Sleep(1); puerto = ControlPort.Input(0x379); if (puerto == 126) adc1 = adc1 + (int)(Math.Pow(2, i)); } ControlPort.Output(0x378, 0x02); //CS HIGH celcius = (4.98 * adc1 * 100) / 1024; kelvin = celcius + 273.15; fahrenheit = (celcius * 1.8) + 32; lblCelcius.Text = celcius.ToString("N2") + "°C"; lblKelvin.Text = kelvin.ToString("N2") + "°K"; lblFahrenheit.Text = fahrenheit.ToString("N2") + "°F"; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { ControlPort.Output(0x378, 0x02); //CS HIGH } } }
Descarga del archivo
Descargar archivo