1. Trang chủ
  2. » Luận Văn - Báo Cáo

Giáo trình hình thành phân mạch ứng dụng điều chế thiết bị bán dẫn chứa các mạch logic điện tử p6

7 11 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 7
Dung lượng 170,7 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

[r]

Trang 1

B.Module Demo.cpp

#include <conio.h>

#include <stdio.h>

#include <stdlib.h>

#include <graphics.h>

#include <string.h>

#include <dos.h>

#include <math.h>

#include <complex.h>

#include <time.h>

#include <dir.h>

#include <ctype.h>

#include "screen.h"

#include "mouse.h"

#include "button.hpp"

#include "textbox.hpp"

#include "list.hpp"

#include "disklist.hpp"

#include "send.hpp"

#define NumBox 2

#define NumBut 2

LPEVENT lpEvent; //bien chua cac bien co chuot

char szMessage[128];

BUTTON But[NumBut],NutKiem;

TEXTBOX Box[NumBox],Port;

char DiskName[27],DName;

char ftype[15]="*.prn";

char inter_Path[100]="";

char RequF[100];

unsigned int St_address,End_address=0;

char Sta_hex[5],End_hex[5];

// -

int TestPressedButton(int x,LPEVENT lpEvent);

int TestPressTexbox(int x,LPEVENT lpEvent,char layra[],unsigned

*attribp);

void MainProgram();

int TestPressList(LIST L,LPEVENT lpEvent,char s[],unsigned

*attrib,char *typ);//nhap bang liet ke

int SendFile();

// -

void main(void)

{

InitGraphics();

InitValues("Download Program.");

InitScreen();

if (!InitMouse(&MainWindow.rViewPort))

{

OutMessage("Mouse driver not found Init mouse and return"); getch();

closegraph();

exit(1);

}

ShowMouse();

MainProgram();

closegraph();

}

Trang 2

// -

void MainProgram()

{

char Name[20],buffer[MAXPATH];

unsigned attrib,Attribp;

SEND Send;

LIST L;

But[0].InitButton(200,380,250,400,LIGHTGRAY,"Send");

But[1].InitButton(400,380,450,400,LIGHTGRAY,"Exit");

Box[0].InitTextBox(50,70,477,90,GREEN,LIGHTGREEN,"Open File"); Port.InitTextBox(50,270,250,290,GREEN,LIGHTGREEN,"Out port");

Port.GetS_in("LPT1");

L.InitList(480,70,500,90,LIGHTGRAY);

But[0].OutButton();//xuat nut lenh

But[1].OutButton();//xuat nut lenh

Box[0].OutTextBox();//xuat hop nhap text

Port.OutTextBox();

L.Show();

setcolor(BLACK);

line(50,150,250,150);

line(50,150,50,215);

setcolor(WHITE);

line(50,215,250,215);

line(250,150,250,215);

outtextxy(50,130,"Free memory request");

outtextxy(55,158,"Start ad :");

outtextxy(55,178,"End ad :");

outtextxy(55,198,"Total :");

OutMessage("Click mouse to chose action");

int kkkk;

char RequestFile[15]="";

do//kiem tra nhap chuot chon cong viec

{

ShowMouse();

lpEvent = GetEvent();//lay bien co chuot

if(TestPressedButton(2,lpEvent)==0)//kiem tra xem da click vao nut nao

//0:nhan OK

{

char InName[100],OutName[100];

Box[0].GetS(InName);

if(InName[strlen(InName)-1]=='\\')

InName[strlen(InName)-1]='\0';

_dos_getfileattr(InName,&attrib);

if(attrib==16)

{

OutMessage("");

OutError("Please enter a file name");

OutMessage("Click mouse to chose action");

}

else//la file

{

if(End_address!=0)

{

if(OutError("Are you sure ?"))

{

OutMessage("Sending Press Esc to stop if time is over.");

Send.CatFile(Sta_hex,End_hex,inter_Path);

Trang 3

Send.Out();

if(Send.Out()!=-1) {

HideMouse();

OutMessage("");

OutError("Task is complete.");

OutMessage("Click mouse to choose action");

} else { HideMouse();

OutMessage("Click mouse to choose action");

} }

}

}

}//if(TestPressedButton

if(TestPressList(L,lpEvent,Name,&attrib,ftype)==1)

//chon OK

{

switch (attrib)

{

case 16:chdir(Name);

getcwd(buffer, MAXPATH);//lay duong dan hien thoi vao buffer

strcpy(inter_Path,buffer);

Box[0].GetS_in(inter_Path);

Box[0].OutTextBox();

break;

default:

getcwd(buffer, MAXPATH);//lay duong dan hien thoi vao buffer

strcpy(inter_Path,buffer);

if(inter_Path[strlen(inter_Path)-1]!='\\') strcat(inter_Path,"\\");

strcat(inter_Path,Name);

Box[0].GetS_in(inter_Path);

Box[0].DuongDan(inter_Path);

Box[0].OutTextBox();

break;

}//end switch

}//if(TestPressList(

//chon Cancel

TestPressTexbox(NumBox,lpEvent,inter_Path,&Attribp);//Path lay

ra duong dan cho file nhap vao

//ShowMouse();

if(kbhit())

{

kkkk=getch();

if(kkkk==0)kkkk=getch();

}

Box[0].GetS(RequF);

{

int n=strlen(RequF);

if(n>5)//?.???

if(RequF[n-1]!='\\')

{

while(n>0&&RequF[n-1]!='\\')

{

n ;

}

char *strtemp=RequF;

Trang 4

for(int m=0;m<n;m++)

strtemp++;

if(strcmp(RequestFile,strtemp))//neu file chon co thay doi {

setfillstyle(SOLID_FILL,CYAN);

bar(155,155,245,210);

strcpy(RequestFile,strtemp);

strtemp+=strlen(strtemp)-4;

if(!strcmp(strtemp,".prn"))//neu dung file prn

{

FILE *f;

if ((f = fopen(RequF,"rb")) == NULL) {

fprintf(stderr, "Cannot open input file.\n");

return ; }

else//neu mo duoc file {

clock_t start, end;

int period=0;

char c,address[7],buf[8];

int thoat;

int dem;

char KyTu_Hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E ','F','a','b','c','d','e','f'};

int Gtri_Dec[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15};

double Value1=0,Value2=0;

char Total[10];

int FindPos,FindValue;

start = clock();

do {

fread(&c,1,1,f);

end = clock();

}while(c!='\''&&(period=(end - start) / CLK_TCK)<10); if(period>=2) goto Error;

fseek(f,-5,SEEK_CUR);

fread(address,10,1,f);

address[4]='\0';

strcpy(Sta_hex,address);

HideMouse();

strcat(address," Hex");

outtextxy(170,158,address);

for (FindPos=3;FindPos>=0;FindPos )

for(FindValue=0;FindValue<22;FindValue++) if(address[FindPos]==KyTu_Hex[FindValue])

Value1+=pow(16,(3-FindPos))*Gtri_Dec[FindValue];

St_address=(unsigned int)Value1;

ShowMouse();

thoat=1;

start = clock();

do {

Trang 5

do { fread(&c,1,1,f);

end = clock();

}while(c!='m'&&c!='M'&&(period=(end - start) / CLK_TCK)<10);

if(period>=10) goto Error;

fseek(f,-1,SEEK_CUR);

fread(buf,7,1,f);

buf[7]='\0';

end = clock();

if(!strcmp(buf,"Macros:")||!strcmp(buf,"MACROS:")||!strcmp(buf," macros:"))

thoat=0;

}while(thoat&&(period=(end - start) / CLK_TCK)<15); if(period>=15) goto Error;

fseek(f,-1,SEEK_CUR);

start = clock();

do {

dem=0;

do { fread(&c,1,1,f);

if(c=='\n') fseek(f,-3,SEEK_CUR);

else fseek(f,-2,SEEK_CUR);

end = clock();

}while(c!='\''&&(period=(end - start) / CLK_TCK)<10);

if(period>=10) goto Error;

do { dem++;

fread(&c,1,1,f);

if(c=='\n') dem=20;

fseek(f,-2,SEEK_CUR);

end = clock();

}while(dem<10&&(period=(end - start) / CLK_TCK)<15); if(period>=15) goto Error;

end = clock();

}while(dem!=20&&(period=(end - start) / CLK_TCK)<15); if(period>=15) goto Error;

fseek(f,2,SEEK_CUR);

start = clock();

do {

fread(&c,1,1,f);

end = clock();

}while(c!='\''&&(period=(end - start) / CLK_TCK)<10); if(period>=10) goto Error;

fseek(f,-5,SEEK_CUR);

fread(buf,4,1,f);

buf[4]='\0';

HideMouse();

strcpy(End_hex,buf);

strcat(buf," Hex");

outtextxy(170,178,buf);

for (FindPos=3;FindPos>=0;FindPos )

Trang 6

III.MODULE BUTTON.CPP

#include <graphics.h>

#include <string.h>

#include "button.hpp"

// -

void BUTTON::InitButton(int x1,int y1,int x2,int y2,int color,char s[])

{

l=x1;

t=y1;

r=x2;

b=y2;

Color=color;

strcpy(S,s);

}

// -

void BUTTON::OutButton()

{

setfillstyle(SOLID_FILL,Color);

bar(l,t,r,b);

setcolor(WHITE);

line(l,t,r,t);

line(l,t,l,b);

setcolor(BLACK);

line(r,t,r,b);

line(l,b,r,b);

setcolor(BLUE);

int x=l+(r-l-textwidth(S))/2,y=t+(b-t-textheight(S))/2;

outtextxy(x,y,S);

}

// -

void BUTTON::PressButton()

{

setcolor(BLACK);

line(l,t,r,t);

line(l,t,l,b);

setcolor(WHITE);

line(r,t,r,b);

line(l,b,r,b);

}

// -

IV CLASS DISKLIST.HPP

#include "textbox.hpp"

#include "mouse.h"

#if !defined DISKLIST

#define DISLIST

extern char Disk(char *s);

extern int ChosenDisk(char *s,/*TEXTBOX *Box,*/char PreDisk,char CurDisk);

extern LPEVENT CheckChooseDisk(char *DiskName,char

*DName,LPEVENT lpEvent,int x,int y);

extern char *FileType(TEXTBOX *b);

#endif

V.MODULE DISKLIST.CPP

#include <dir.h>

#include <alloc.h>

#include <stdio.h>

#include <conio.h>

#include <string.h>

#include <graphics.h>

Trang 7

#include <bios.h>

#include <PROCESS.H>

// <PROCESS.H, STDLIB.H>

#include "disklist.hpp"

char Disk(char *s)//kiem tra co bao nhieu o dia trong may, luu ten cac

o dia vao chuoi s, tra ve ten o dia hien hanh

{

int save,disk, disks;

int equip_check;

char c[4];

s[0]='\0';

save = getdisk();

equip_check = biosequip();

equip_check >>= 6;

equip_check = (equip_check & 3) + 1;//dem so o dia mem

for (disk = 0;disk < 26;++disk)

{

setdisk(disk);

if (disk == getdisk())

{

sprintf(c,"%c",disk +'A');

strcat(s,c);

}

}

setdisk(save);

if(equip_check==1&&s[1]=='B')//neu chi co ot o dia mem

for(int i=1;i<strlen(s);i++)//thi khong co ten o dia B

s[i]=s[i+1];//loai ky tu B ra khoi chuoi luu ten o dia

}

// -

int ChosenDisk(char *s,/*TEXTBOX *Box,*/char PreDisk,char CurDisk) //tra ve ten o dia

{

int i;

if(PreDisk!=CurDisk)

{

for(i=0;i<strlen(s);i++)

if((CurDisk)==s[i])//hien thi cho dia moi

{

setdisk(s[i]-'A');

char buffer[MAXPATH],*iem;

if((iem=getcwd(buffer, MAXPATH))==NULL)

{

OutMessage("Driver is not ready.");

i=0;

ShowMouse();

return s[i];

}

}

return s[i];

}

// -

LPEVENT CheckChooseDisk(char *DiskName,char *DName,LPEVENT lpEvent,int x,int y)

{

int NumDisk=strlen(DiskName);

int x1=x-30,y1=y+NumDisk*14+12;

void far *buf;//con tro chi vung luu tru man hinh

unsigned int size = imagesize(x1,y,x,y1);

Ngày đăng: 01/04/2021, 18:08

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm