📄 testmulticolorplotctrldlg.cpp
字号:
// testMultiColorPlotCtrlDlg.cpp : implementation file
//
#include "stdafx.h"
#include "testMultiColorPlotCtrl.h"
#include "testMultiColorPlotCtrlDlg.h"
#include <stdio.h>
#include <conio.h>
#include "ApiEx.h"
#pragma comment(lib,"ApiEx.lib")
#define port1 0x281 //8253 1口
#define portk 0x283 //8253 控制口
#define port0 0x280 //8253 0口
#define port2 0x282 //8253 2口
#define ioport 0x2b0 //8279 数据口
#define ioportk 0x2b1 //8279 控制口
int k;
int disled[6]={0x00,0x00,0x00,0x00,0x00,0x00};//led从右到左显示,最左显示功能键
int realkey[4]={0x00,0x00,0x00,0x00};//得到真实的按键值
int led[] ={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,
0x39,0x5E,0x79,0x71,0x80,0x40};//0,1,2,3,4,5,6,7,8,9,A,b,C,d,E,F,g,m,P,r,w,x,y,.,-
int table[]={0x1b,0x13,0x0b,0x03,0x1a,0x12,0x0a,0x02,0x19,0x11,0x09,0x01,0x18,0x10,0x08,0x00};
int keyin=0;
void key(); //键盘显示
void disp(); //显示
void int_proc(); //中断处理程序
void motorstart();//启动电机
void measurespeed();//测量转速
void pidadapt();//PID调速
int funkey=0;//0表示是功能键,1表示数字键
int datakey=0;//表示之前未按功能键,1表示按下了功能键
int keydatanum=0;//表示按下数字键的个数
int keycdown=0;//表示按下了E键
int keyedown=0;//表示按下了C键
int keyadaptspeed=0xff;
int getspeed=0;//测得的转速
int j=0;
int jj=0;
int d=0;//存放给定的速度换算成高电平持续时间
int saved=0;
int keysave=0;//保存初始转速的键值
BYTE data;//存放按键值
BYTE data1=0x00;//存计数的低8位
BYTE data2=0x00;//存计数的高8位
int count=0;//得到定时器2的当前计数值
int count1=0;//测到的转速值
int mspeed[2]={0x00,0x00};
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
afx_msg void OnTimer(UINT nIDEvent);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestMultiColorPlotCtrlDlg dialog
CTestMultiColorPlotCtrlDlg::CTestMultiColorPlotCtrlDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestMultiColorPlotCtrlDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestMultiColorPlotCtrlDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestMultiColorPlotCtrlDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestMultiColorPlotCtrlDlg)
DDX_Control(pDX, IDC_MULTICOLORPLOT, m_ctrlMultiColorPlot);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestMultiColorPlotCtrlDlg, CDialog)
//{{AFX_MSG_MAP(CTestMultiColorPlotCtrlDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_GEIDINGZHI, OnGeidingzhi)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_BN_CLICKED(IDC_XIANSHI, OnXianshi)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_TINGZHI, OnTingzhi)
ON_BN_CLICKED(IDC_ZHUANDONG, OnZhuandong)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestMultiColorPlotCtrlDlg message handlers
BOOL CTestMultiColorPlotCtrlDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_ctrlMultiColorPlot.SetTitle("当前实时速度曲线是:");
m_ctrlMultiColorPlot.SetUnit(" :转/秒");
m_ctrlMultiColorPlot.LockRang(20.00f,90.00f);
m_ctrlMultiColorPlot.SetPlotGranulatrity(4);
m_ctrlMultiColorPlot.SetGridResolutionX(15);
m_ctrlMultiColorPlot.ShowTitle(4);
m_ctrlMultiColorPlot.SetPlotType(BAR);
SetTimer(1,200,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestMultiColorPlotCtrlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestMultiColorPlotCtrlDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestMultiColorPlotCtrlDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestMultiColorPlotCtrlDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// TODO: 在此添加消息处理程序代码和/或调用默认值
m_ctrlMultiColorPlot.SetData( ( float ) GetRandom(2000,5000)/100 ) ;
// m_ctrlMultiColorPlot.SetData( ( float ) 148 ) ;
CDialog::OnTimer(nIDEvent);
}
void CTestMultiColorPlotCtrlDlg::OnGeidingzhi()
{
disled[5]=led[0x0a];//显示键A
for(jj=0;jj<4;jj++)//清真实的数字键值
{ realkey[jj]=0; }
disled[0]=led[0];//显示给定值为00
disled[1]=led[0];
disled[2]=led[0];//显示测速值为00
disled[3]=led[0];
funkey=0;//表示按下了功能键
keycdown=0;//表示没有按下功能键E
keyedown=0;//表示没有按下功能键C
datakey=1;//表示当前按下A功能键
mspeed[0]=0;//测定的速度显示为00
mspeed[1]=0;
d=0;//给定的脉宽值为0
// TODO: Add your control notification handler code here
}
void CTestMultiColorPlotCtrlDlg::OnChangeEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CTestMultiColorPlotCtrlDlg::OnXianshi()
{
disled[2]=led[mspeed[0]];//显示测速值的低位
disled[3]=led[mspeed[1]];//显示测速值的高位
// TODO: Add your control notification handler code here
}
void CTestMultiColorPlotCtrlDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CTestMultiColorPlotCtrlDlg::OnButton4()
{
// TODO: Add your control notification handler code here
}
void CTestMultiColorPlotCtrlDlg::OnTingzhi()
{
disled[0]=led[0];//显示给定值为00
disled[1]=led[0];
disled[2]=led[0];//显示测速值为00
disled[3]=led[0];
disled[4]=0x00;
for(jj=0;jj<4;jj++)
{
realkey[jj]=0;
}
mspeed[0]=0;//测定的速度显示为00
mspeed[1]=0;
funkey=0;//表示按下了功能键
keycdown=0;//表示没有按下功能键E
keyedown=0;//表示没有按下功能键C
datakey=0;//表示当前没按下A功能键
d=0;//给定的脉宽值为0
keydatanum=0; //计录的按下数字键值为0个
// TODO: Add your control notification handler code here
}
void CTestMultiColorPlotCtrlDlg::OnZhuandong()
{
d=realkey[0]+realkey[1]*10;
disled[5]=led[0x0e];
disled[0]=led[realkey[0]];//显示给定值
disled[1]=led[realkey[1]];
disled[2]=led[0];//显示测速值为0
disled[3]=led[0];
disled[4]=0x00;
mspeed[0]=0;//测定的速度显示为00
mspeed[1]=0;
funkey=0;//表示按下了功能键
keycdown=1;//表示没有按下功能键C
keyedown=0;//表示按下功能键E
keydatanum=0; //计录的按下数字键值为0个
// TODO: Add your control notification handler code here
}
void CAboutDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -