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 Display_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(); } int numero; byte i; private void Form1_Load(object sender, EventArgs e) { ControlPort.Output(0x378, 4); write_max72(0x0F, 0x00); //display test write_max72(0x0B, 0x03); //scan limit write_max72(0x09, 0x0F); //decode mode write_max72(0x0A, 0x02); //intensity write_max72(0x0C, 0x01); //shutdown for (i = 1; i <= 4; i++) write_max72(i,0x0F); } private void button1_Click(object sender, EventArgs e) { int nible; numero = (int)numericUpDown1.Value; string cadena = numero.ToString(); cadena = cadena.PadLeft(4, '?'); for (i = 1; i <= 4; i++) { nible = ((int)cadena[i - 1]) & 0x0F; write_max72((byte)(5-i), (byte)nible); } } void write_max72(byte address, byte dato) { int num, a, i; double b = 0; int lpt; if (dato == 13) dato = 10; num = (address << 8) + dato; for (i = 15; i > 0; i--) { a = (num & 0x0001); b = b + (Math.Pow(2, i) * a); num = num >> 1; } ControlPort.Output(0x378, 0); //cs 0 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); } } }
Descarga del archivo
Descargar archivo