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 MAX7219_LPT_01 { public partial class Form1 : Form { class ControlPort { [DllImport("inpout32.dll", EntryPoint = "Out32")] public static extern void Output(int adress, int value); } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { ControlPort.Output(0x378, 4); /*write_max72(0x0B, 0x07); //scan limit 11,7 write_max72(0x09, 0x00); //decode mode 9,0 write_max72(0x0C, 0x01); //shutdown 12,1 write_max72(0x0F, 0x00); //display test 15,0 write_max72(0x0A, 0x02); //intensity 10,2*/ } void write_max72(byte address, byte dato) { int num, a, i; double b = 0; int lpt; ControlPort.Output(0x378, 0); //cs 0 num = (address << 8) + dato; for (i = 15; i > 0; i--) { a = (num & 0x0001); b = b + (Math.Pow(2, i) * a); num = num >> 1; } for (i = 0; i < 16; i++){ lpt = ((int)b & 0x01); ControlPort.Output(0x378, lpt); //data lpt = lpt + 2; ControlPort.Output(0x378, lpt); //sck High lpt = lpt - 2; ControlPort.Output(0x378, lpt); //sck low b = (int)((int)b >> 1); } ControlPort.Output(0x378, 4); //cs 1 Thread.Sleep(1); } private void btnLimpiar_Click(object sender, EventArgs e) { for (int j = 1; j < 9; j++ ) write_max72((byte)j, 0); } private void btnEnviar_Click(object sender, EventArgs e) { int dir, data; dir = Convert.ToInt32(txtDir.Text); data = Convert.ToInt32(txtData.Text); write_max72((byte)dir, (byte)data); } } }
Descarga del archivo
Descargar archivo