📄 frmmain.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace USB_PIC18_GUI
{
public partial class frmMain : Form
{
PicUSBAPI USB = new PicUSBAPI();
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
CheckSwitch();
}
private void btnReadADC_Click(object sender, EventArgs e)
{
uint val=USB.ReadAdc(Convert.ToByte(nudSamples.Value), Convert.ToByte(nudChannel.Value), 10);
double Volt= Convert.ToDouble(val);
Volt = (double)Volt * .00488;
txtVolts.Text = Volt.ToString();
}
private void btnSwitch_Click(object sender, EventArgs e)
{
CheckSwitch();
}
private void btnLED1_Click(object sender, EventArgs e)
{
SetLeds(1);
}
private void btnLED2_Click(object sender, EventArgs e)
{
SetLeds(2);
}
private void SetLeds(byte LED)
{
byte[] ToSend = new byte[5];
ToSend[3] = (byte)('L');
ToSend[4] = LED;
USB.SendByteArray(ToSend, 5);
}
private void CheckSwitch()
{
byte[] ioBuff = new byte[4];
ioBuff[3] = (byte)('S');
USB.SendByteArray(ioBuff, 4);
ioBuff = USB.GetByteArray(4);
int s = (int)ioBuff[3];
switch (s)
{
case 0:
lblS1.Text = "S1=OFF";
lblS2.Text = "S2=OFF";
break;
case 1:
lblS1.Text = "S1=ON";
lblS2.Text = "S2=OFF";
break;
case 2:
lblS1.Text = "S1=OFF";
lblS2.Text = "S2=ON";
break;
case 3:
lblS1.Text = "S1=ON";
lblS2.Text = "S2=ON";
break;
default: break;
}
}
private void btnLogo_Click(object sender, EventArgs e)
{
byte[] Buff = new byte[36];
Buff[3] = (byte)'E';
USB.SendByteArray(Buff, 4);
Buff = USB.GetByteArray(32);
lblLogo.Text = "";
for (int i = 0; i < 32; i++)
lblLogo.Text += (char)Buff[i];
string st= "There is no any garentee for this package. Use on as is basis.It is provided for learning only. No one can use it for Commercial.This example show how to use PIC18F4550 as usb device.Interface code is written in Visual C#.NET 2K5.I am thankful to J.Nut (www.jnutthailand.com) for his great usb articale on usb.I learned usb interfacing from his article.If you upgrade or modify this code please do tell me at rafique4m@gmail.comI know this is not very good code but i wrote it for learning.Thanks!Muhammad Rafique. Islamabad Pakistan. rafique4m@gmail.comand Sorry for my Bad englishJan 2K9";
MessageBox.Show(st);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -