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 Conversor_ADC_LPT_02 { 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, adc2, adc3; private void Form1_Load(object sender, EventArgs e) { ControlPort.Output(0x378, 0x02); //CS HIGH } private void timer1_Tick(object sender, EventArgs e) { adc1 = 0; adc2 = 0; adc3 = 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)); } for (i = 0; i < 10; i++) //Ciclo para leer el segundo ADC { ControlPort.Output(0x378, 0x01); Thread.Sleep(1); ControlPort.Output(0x378, 0x00); Thread.Sleep(1); puerto = ControlPort.Input(0x379); if (puerto == 126) adc2 = adc2 + (int)(Math.Pow(2, i)); } for (i = 0; i < 10; i++) //Ciclo para leer el tercer ADC { ControlPort.Output(0x378, 0x01); Thread.Sleep(1); ControlPort.Output(0x378, 0x00); Thread.Sleep(1); puerto = ControlPort.Input(0x379); if (puerto == 126) adc3 = adc3 + (int)(Math.Pow(2, i)); } ControlPort.Output(0x378, 0x02); //CS HIGH lblADC1.Text = "ADC1: " + adc1; lblADC2.Text = "ADC2: " + adc2; lblADC3.Text = "ADC3: " + adc3; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { ControlPort.Output(0x378, 0x02); //CS HIGH } } }
Descarga del archivo
Descargar archivo