计算器程序

更新时间:2023-12-07 08:31:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

1、GPIOLEDDlg.cpp程序代码

m_hDev=CreateFile(_T(\L,OPEN_EXISTING,0,0);

if(m_hDev==INVALID_HANDLE_VALUE) {

AfxMessageBox(_T(\打开设备失败\ }

m_hDev1=CreateFile(_T(\LL,OPEN_EXISTING,0,0);

if(m_hDev==INVALID_HANDLE_VALUE) {

AfxMessageBox(_T(\打开设备失败\ }

return TRUE; // return TRUE unless you set the focus to a control }

void CGPIOLEDDlg::OnButton1() {

// TODO: Add your control notification handler code here //设置LED灯亮 KillTimer(1); KillTimer(2); KillTimer(3); KillTimer(4);

m_bValue=FALSE;

WriteFile(m_hDev,&m_bValue,4,&m_dwBytes,NULL); }

void CGPIOLEDDlg::OnButton2() {

// TODO: Add your control notification handler code here //设置LED灯熄灭 KillTimer(1); KillTimer(2); KillTimer(3); KillTimer(4);

m_bValue=TRUE;

WriteFile(m_hDev,&m_bValue,4,&m_dwBytes,NULL);

}

void CGPIOLEDDlg::OnButton3() {

// TODO: Add your control notification handler code here m_cla=0;

m_bValue=FALSE; KillTimer(2); KillTimer(3); KillTimer(4);

SetTimer(1,1000,NULL); }

void CGPIOLEDDlg::OnTimer(UINT nIDEvent) {

// TODO: Add your message handler code here and/or call default

if(nIDEvent==1) {

//设置LED闪烁 m_cla=m_cla+1; if(m_bValue==FALSE) {

if(m_cla==m_s1) {

m_bValue=TRUE; m_cla=0; } }

if(m_bValue==TRUE) {

if(m_cla==m_s2) {

m_bValue=FALSE; m_cla=0; } }

WriteFile(m_hDev,&m_bValue,4,&m_dwBytes,NULL); }

if(nIDEvent==2) {

//LED的循环

BYTE data2[4]={0,0,0,0}; DWORD bytes;

m_cla=m_cla+1; if(m_bValue==1) {

if(m_cla==m_s1) {

WriteFile(m_hDev1,data2,4,&bytes,NULL); m_cla=0;

m_bValue=0; } } else {

if(m_cla==m_s1) {

WriteFile(m_hDev1,data,4,&bytes,NULL); m_cla=0; m_bValue=1; } } }

if(nIDEvent==3) {

//LED的单闪

BYTE data2[4]={data[0],0x00,0x00,0x00}; BYTE data3[4]={0x00,data[1],0x00,0x00}; BYTE data4[4]={0x00,0x00,data[2],0x00}; BYTE data5[4]={0x00,0x00,0x00,data[3]}; DWORD bytes; m_cla=m_cla+1; if(m_cla==m_s1) {

if(i>3) { i=0; }

if(i==0) {

WriteFile(m_hDev1,data2,4,&bytes,NULL); }

if(i==1)

{

WriteFile(m_hDev1,data3,4,&bytes,NULL); }

if(i==2) {

WriteFile(m_hDev1,data4,4,&bytes,NULL); }

if(i==3) {

WriteFile(m_hDev1,data5,4,&bytes,NULL); }

i=i+1; m_cla=0; } }

if(nIDEvent==4) {

//LED的右移 BYTE a;

DWORD bytes; m_cla=m_cla+1; if(m_cla==m_s1) {

a=data[3];

data[3]=data[2]; data[2]=data[1]; data[1]=data[0]; data[0]=a;

WriteFile(m_hDev1,data,4,&bytes,NULL); m_cla=0; } }

CDialog::OnTimer(nIDEvent); }

void CGPIOLEDDlg::OnButton4() {

// TODO: Add your control notification handler code here BOOL b1,b2; UINT q;

UINT val1=GetDlgItemInt(IDC_EDIT1,&b1,FALSE);

UINT val2=GetDlgItemInt(IDC_EDIT2,&b2,FALSE); m_s1=0; m_s2=0; data[0]=0; data[1]=0; data[2]=0; data[3]=0;

//获取Edit框的内容 memset(data,0,2); if(b1) {

int i1,n1; char str1[16];

n1=sprintf(str1,\ n1=n1>2?2:n1; for(i1=0;i1

q=str1[i1]-'0';

data[i1+2]=ledfont[q]; m_s1=m_s1*10+q; } }

memset(data,0,2); if(b2) {

int i2,n2; char str2[16];

n2=sprintf(str2,\ n2=n2>2?2:n2; for(i2=0;i2

q=str2[i2]-'0';

data[i2]=ledfont[q]; m_s2=m_s2*10+q; } } }

void CGPIOLEDDlg::OnButton5() {

// TODO: Add your control notification handler code here //数码管显示数据

本文来源:https://www.bwwdw.com/article/ps7t.html

Top