반응형
LED 점등1 프로그램
- 해당 LED의 체크 박스를 선택 후, 수동구동 버튼을 누르면 LED가 점등하고
- 체크박스를 해제한 후, 수동구동 버튼을 누르면 LED가 소등
- 파일명 : LED1
PC 프로그램 데이타
PC와 미니 MPS 트레이너를 연결함.
프로그램 실행 - FILE - NEW - 창이 뜨면
MFC AppWizard [exe] 선택
파일구조를 보면 아래와 같다.
새로운 프로젝트를 만들때 링크를 걸어주어야 오류가 생기지 않는다.
FTD2xx.lib
led0... 소스를 더블 클릭해서 들여다 보자.
// led1Dlg.cpp : implementation file
#include "stdafx.h"
#include "led1.h"
#include "led1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//######################################################## 추가입력 내용 1 시작
#include <MPSDriver.h>
#define PPI_A 0x00 //PPIBoard 조건
#define PPI_B 0x01
#define PPI_C 0x02
#define PPI_CR 0x03
UINT Z(LPVOID lParam); //스레드 구동 사용자 지정 함수
unsigned char flag = 0;
unsigned char RunThread = 0;
int supf, supb, sup;
int led0, led1, led2, led3, led;
int stp, cm, stage, act;
int a, b, c, d, e, i, j, sum;
int bs1, bs2, bs3, bs4;
//######################################################## 추가입력 내용 1 끝
/////////////////////////////////////////////////////////////////////////////
// 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
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)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLed1Dlg dialog
CLed1Dlg::CLed1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CLed1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLed1Dlg)
m_led0 = FALSE;
m_led1 = FALSE;
m_led2 = FALSE;
m_led3 = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CLed1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLed1Dlg)
DDX_Check(pDX, IDC_CHECK1, m_led0);
DDX_Check(pDX, IDC_CHECK2, m_led1);
DDX_Check(pDX, IDC_CHECK3, m_led2);
DDX_Check(pDX, IDC_CHECK4, m_led3);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLed1Dlg, CDialog)
//{{AFX_MSG_MAP(CLed1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
ON_BN_CLICKED(IDC_CHECK4, OnCheck4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLed1Dlg message handlers
BOOL CLed1Dlg::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
//######################################################## 추가입력 내용 2 시작
if (InitDrv() < 0) return -1; //USB포트 정의
if (USBDrvInit() < 0) return -1; //USB포트 정의
//######################################################## 추가입력 내용 2 끝
return TRUE; // return TRUE unless you set the focus to a control
}
void CLed1Dlg::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 CLed1Dlg::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 CLed1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CLed1Dlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
//######################################################## 추가입력 내용 3 시작
if (RunThread == 0) AfxBeginThread(Z, NULL);
//######################################################## 추가입력 내용 3 끝
}
void CLed1Dlg::OnButton1() // 수동 구동
{
if (1)
led = led0 + led1 + led2 + led3;
}
void CLed1Dlg::OnCheck1() // LED0
{
if (m_led0 == false) led0 = 0;
else if (m_led0 == true) led0 = 0;
UpdateData(true);
}
void CLed1Dlg::OnCheck2() // LED1
{
if (m_led1 == false) led1 = 2;
else if (m_led1 == true) led1 = 0;
UpdateData(true);
}
void CLed1Dlg::OnCheck3() // LED2
{
if (m_led2 == false) led2 = 4;
else if (m_led2 == true) led2 = 0;
UpdateData(true);
}
void CLed1Dlg::OnCheck4() // LED3
{
if (m_led3 == false) led3 = 8;
else if (m_led3 == true) led3 = 0;
UpdateData(true);
}
UINT Z(LPVOID lParam)
{
RunThread = 1;
flag = 1;
do
{
if (1)
{
Outputb(PPI_C, led);
Sleep(500);
}
} while (1);
RunThread = 0;
return 0;
}
'자동제어 > PC 제어' 카테고리의 다른 글
PC제어프로그램 10일차 (20.07.31) LED 점등 3_2 프로그램 (0) | 2020.07.31 |
---|---|
PC제어프로그램 9일차 (20.07.30) LED 점등하기(LED3) (0) | 2020.07.30 |
PC제어프로그램 7일차 (20.07.14) (0) | 2020.07.14 |
PC제어프로그램 5일차 (20.05.14) - 기본코딩2 (0) | 2020.06.18 |
PC제어프로그램 5일차 (20.05.14) - 기본코딩1 (0) | 2020.06.18 |