PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Trao đổi ngoài luồng (http://www.picvietnam.com/forum/forumdisplay.php?f=22)
-   -   Hỏi code mẫu C++/C# (http://www.picvietnam.com/forum/showthread.php?t=3258)

trieutuduong 04-12-2008 07:43 AM

Hỏi code mẫu C++/C#
 
xin giải thích giùm chương trình sau , và cho biết dùng để làm gì . cám ơn các bác trước .
chương trình :
void CTest2Dlg::OnXit()
{
// TODO: Add your control notification handler code here
int r;
r = _outp(0x0378,0x00);
OnOK();
}
void CTest2Dlg::OnUp()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(a<45) a+=5;
else MessageBox("Maximum speed limit");
m_speedfact.Format("%d", a);
UpdateData(FALSE);
}
void CTest2Dlg::OnDwn()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(a>-45) a-=5;
else MessageBox("Minimum speed limit");
m_speedfact.Format("%d", a);
UpdateData(FALSE);
}
void CTest2Dlg::OnFwd()
{
// TODO: Add your control notification handler code here
int p;
int z = 5000/(2*m_sf);
for(int i=0;i<z;i++)
{
p = _outp(0x0378,0x03);
Sleep(m_sf + a);
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
}
void CTest2Dlg::OnRew()
{
// TODO: Add your control notification handler code here
int p;
int z = 5000/(2*m_sf);
for(int i=0;i<z;i++)
{
p = _outp(0x0378,0x0C);
Sleep(m_sf + a);
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
}

Mr.Bi 05-12-2008 04:15 PM

Trích:

Nguyên văn bởi trieutuduong (Post 21132)
xin giải thích giùm chương trình sau , và cho biết dùng để làm gì . cám ơn các bác trước .
chương trình :
void CTest2Dlg::OnXit()
{
// TODO: Add your control notification handler code here
int r;
r = _outp(0x0378,0x00);
OnOK();
}
void CTest2Dlg::OnUp()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(a<45) a+=5;
else MessageBox("Maximum speed limit");
m_speedfact.Format("%d", a);
UpdateData(FALSE);
}
void CTest2Dlg::OnDwn()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(a>-45) a-=5;
else MessageBox("Minimum speed limit");
m_speedfact.Format("%d", a);
UpdateData(FALSE);
}
void CTest2Dlg::OnFwd()
{
// TODO: Add your control notification handler code here
int p;
int z = 5000/(2*m_sf);
for(int i=0;i<z;i++)
{
p = _outp(0x0378,0x03);
Sleep(m_sf + a);
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
}
void CTest2Dlg::OnRew()
{
// TODO: Add your control notification handler code here
int p;
int z = 5000/(2*m_sf);
for(int i=0;i<z;i++)
{
p = _outp(0x0378,0x0C);
Sleep(m_sf + a);
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
}

hix , bác này thấy đoạn code này ở đâu , vác về vứt phẹt vào đây oy kiu giải thích . Đây chỉ là các hàm thui , ko phải là chương trình .

trieutuduong 06-12-2008 01:13 AM

mong các bac giai thích gium các hàm , em mới tiếp xúc , không hiểu gì cả

dvkkt 06-12-2008 10:32 AM

Tôi không dùng VC++ nên chỉ giải thích vắn tắt cái hàm.
Code:

void CTest2Dlg::OnXit()
{
// TODO: Add your control notification handler code here
int r;
r = _outp(0x0378,0x00); // xuất data 0x00 ra cổng LPT
OnOK();
}

Code:

void CTest2Dlg::OnUp()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(a<45) a+=5;
else MessageBox("Maximum speed limit");
m_speedfact.Format("%d", a);
UpdateData(FALSE);
}

nút OnUp này giống như chỉnh tốc độ cho motor, nếu đạt giới hạn thì sẽ hiện thông báo "Maximum speed limit"

Code:

void CTest2Dlg::OnDwn()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(a>-45) a-=5;
else MessageBox("Minimum speed limit");
m_speedfact.Format("%d", a);
UpdateData(FALSE);
}

Ngược với hàm ở trên.

Code:

void CTest2Dlg::OnFwd()
{
// TODO: Add your control notification handler code here
int p;
int z = 5000/(2*m_sf);
for(int i=0;i<z;i++)
{
p = _outp(0x0378,0x03);
Sleep(m_sf + a);              // giống như hàm delay tính bằng milisecond
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
}

nút điều khiển motor quay thuận.

Code:

void CTest2Dlg::OnRew()
{
// TODO: Add your control notification handler code here
int p;
int z = 5000/(2*m_sf);
for(int i=0;i<z;i++)
{
p = _outp(0x0378,0x0C);
Sleep(m_sf + a);             
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
}

quay ngược.

trieutuduong 06-12-2008 11:41 AM

càm ơn bác nhiều , tôi mới tìm hiểu về nó mong các bác giúp đỡ


Múi giờ GMT. Hiện tại là 11:16 AM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam