DAY_C1_PROGDOC_COURSWORK (779998), страница 2
Текст из файла (страница 2)
4. Коммутация трех логических устройств второго уровня с тремя выходными цепями первого уровня:
Таблица. 3, N = 0.
Решение.
1. Таблица. 1, N = 5: OR1, AND1, OR2
2. Таблица. 2, N = 1: X2, X3; Y1, Y2; Y3, X1.
Входы OR1: X2, X3.
Входы AND1: Y1, Y2.
Входы OR2: Y3, X1.
3. Таблица. 1, N = 3: AND2, OR3, OR4.
4. Таблица. 3, N = 0: 1, 2; 3, 1; 2, 3.
Выходы AND2: OR1, AND1.
Выходы OR3: OR2, OR1.
Выходы OR4: AND1, OR2.
Написание уравнений логической схемы программного имитатора начинается с выходов Z.
Z1=AND2=OR1*AND1=(X2+X3)*(Y1*Y2);
Z2=OR3=OR2+OR1=(Y3+X1)+(X2+X3);
Z3=OR4=AND1+OR2=(Y1*Y2)+(Y3+X1)
6. Исходный текст программы на языке Си.
[1] /*######################################################*/
[2] /*Copyright (C) 2005 by A.E.Stefanovich tel. 268-3916, 236-2729
[3] Moscow State Academy of the Instrumentation and Informatics MGAPI
[4] Chair Mechatronics of the systems industrial TI-4
[5] */
[6] /*######################################################*/
[7] /* File: imMG.c
[8] Imitator of the schemes electronics */
[9] /*############################################## LEGEND */
[10] /* <=### CHANGE ###
[11] Moscow State Academy of the Instrumentation and Informatics MGAPI
[12] Chair Mechatronics of the systems industrial TI-4
[13] ---------------
[14] Student: L.V. Doronina
[15] Code: 94505
[16] Group: TI-4-94-02
[17] ---------------
[18] Discipline: Programming and bases of algorithms (3401)
[19] Specialty: 2102
[20] Teacher: A.E. Stefanovich
[21] ---------------
[22] Year: 2003-2004
[23] ---------------
[24] DEVICE LVD
[25] Entrances: X1,X2,X3;
[26] Or1=Y2Y1X3+Y1Y3X2+Y3Y2X1+X1X2X3
[27] Or2=X3X2+X3X1+X2X1
[28] Exits:Z1, Z2
[29] */
[30] /*########################################### PROGRAMME */
[31] /*============================= Includes */
[32] #include <c:\TURBOC.3_0\include\stdio.h>
[33] #include <c:\TURBOC.3_0\include\conio.h>
[34] #include <c:\TURBOC.3_0\include\stdlib.h>
[35] #include <c:\TURBOC.3_0\include\graphics.h>
[36] /*============================= Declarations */
[37] int graph_regime();
[38] int text_regime();
[39] int title_sheet();
[40] int draft(int mode); /* <=### CHANGE ### */
[41] int entry_x(); /* <=### CHANGE ### */
[42] int bit(int x,int y,int bit); /* 0 or 1 */
[43] /*============================= Global constants */
[44] #define LF cprintf("\n")
[45] #define CR cprintf("\r")
[46] #define HT cprintf("\t")
[47] #define VT cprintf("\v")
[48] #define BS cprintf("\b")
[49] #define BELL cprintf("\a")
[50] /* */
[51] #define STOP getch()
[52] #define STOP_DRAFT bioskey(0)
[53] #define ALERT_SIGNAL cprintf("\a\a\a")
[54] #define ROW 25
[55] #define COL 80
[56] #define ROW_D 36 /* <=### CHANGE ### */
[57] #define COL_D 50 /* <=### CHANGE ### */
[58] /* */
[59] #define DISPLAY 1
[60] #define WORK 0
[61] /*============================= Global variable */
[62] /*----------------------------- Device */ /* <=### CHANGE ### */
[63] unsigned int X1,X2,X3; /* Entrances */
[64] unsigned int Y1,Y2,Y3; /* Invert. Entrances */
[65] unsigned int And1,And2,And3,And4,And5,And6,And7; /* 1 range */
[66] unsigned int Or1,Or2; /* 2 range */
[67] /*------------------------------ Global graphic variables */
[68] int Font[8]; /* NN user characters */
[69] int Maxx,Maxy; /* Max. dimensions of the screen in the pixels */
[70] /*----------------------------- Text */ /* <=### CHANGE ### */
[71] char *title_1=
[72] " Moscow State Academy of the Instrumentation and Informatics (MGAPI) ";
[73] char *title_2=
[74] " I M I T A T O R - LVD ";
[75] char *title_3=
[76] " Student: L.V. Doronina ";
[77] char *title_4=
[78] " Group: TI-4-94-02 (d); Code: 94505 ";
[79] char *title_5=
[80] " Discipline: Programming and bases of algorithms (3401) ";
[81] char *title_6=
[82] " Specialty: 2102 ";
[83] char *title_7=
[84] " Chair Mechatronics of the systems industrial (TI-4) ";
[85] char *title_8=
[86] " Teacher: A.E. Stefanovich ";
[87] char *title_9=
[88] " Year: 2003-2004 ";
[89] /*------------- Text (device) */
[90] char *title_10=
[91] " Z1=Y2Y1X3+Y1Y3X2+Y3Y2X1+X1X2X3 ";
[92] char *title_11=
[93] " Z2=X3X2+X3X1+X2X1 ";
[94] /*############################################## MAIN */
[95] main()
[96] {
[97] /*----------------------------- Variables */
[98] char work_exit[2];
[99] /*-----------------------------*/
[100] title_sheet();
[101] /* */
[102] draft(DISPLAY);
[103] /* */
[104] while(1)
[105] {/*----------------------------- Top while(1) */
[106] for(;;)
[107] {/*------------ Top for(;;) */
[108] clrscr();
[109] gotoxy(20,12);
[110] cprintf
[111] (" Input 1 (for Work) or 0 (for Exit) --> ");
[112] cscanf("%s",&work_exit);
[113] if(work_exit[0]=='0')
[114] exit(EXIT_SUCCESS); /* -> EXIT SUCCESS */
[115] if(work_exit[0]=='1')
[116] break; /* -> to START */
[117] ALERT_SIGNAL;/* ERROR of the Input and ^ */
[118] }/*------------ Down for(;;) */
[119] /*----------------------------- START */
[120] entry_x();
[121] /* */
[122] draft(WORK);
[123] }/*----------------------------- Down while(1) */
[124] }
[125] /*###################################### SUB_PROGRAMMS */
[126] /*IIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
[127] int graph_regime()
[128] {
[129] /*----------------------------- Variables */
[130] int gdriver=DETECT,gmode,errorcode;
[131] /*----------------------------- Graph. initialisation */
[132] initgraph(&gdriver,&gmode,"C:\\TURBOC.3_0\\BGI");
[133] errorcode=graphresult();
[134] if(errorcode != grOk)
[135] {
[136] gotoxy(1,24);
[137] textattr(LIGHTRED+(BLACK<<4));
[138] cprintf("GRAPHICS ERROR: %s\n",grapherrormsg(errorcode));
[139] STOP;
[140] exit(EXIT_SUCCESS);
[141] }
[142] Maxx=getmaxx();
[143] Maxy=getmaxy();
[144] /*----------------------------- Installuserfont */
[145] Font[0]=installuserfont("bold");
[146] Font[1]=installuserfont("euro"); /* Cyr */
[147] Font[2]=installuserfont("lcom"); /* Cyr */
[148] Font[3]=installuserfont("litt");
[149] Font[4]=installuserfont("sans");
[150] Font[5]=installuserfont("scri"); /* Cyr manuscript */
[151] Font[6]=installuserfont("simp"); /* Cyr */
[152] Font[7]=installuserfont("tscr"); /* Cyr manuscript */
[153] /* */
[154] return 0;
[155] }
[156] /*IIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
[157] text_regime()
[158] {
[159] closegraph();
[160] restorecrtmode();
[161] textbackground(BLACK);
[162] textcolor(WHITE);
[163] /* */
[164] return 0;
[165] }
[166] /*IIIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
[167] int title_sheet()
[168] {
[169] /*----------------------------- Variables */
[170] int x,y;
[171] int kx; /* Scale of the title sheet */
[172] int ky;
[173] /*----------------------------- Graph. initialisation */
[174] graph_regime();
[175] /*----------------------------- Scale of the title sheet */
[176] kx=Maxx/COL;
[177] ky=Maxy/ROW;
[178] /*----------------------------- Title 1 */
[179] setcolor(YELLOW);
[180] setbkcolor(BLACK);
[181] settextstyle(SMALL_FONT,HORIZ_DIR,5);
[182] settextjustify(CENTER_TEXT,CENTER_TEXT);
[183] x=Maxx/2;
[184] y=1*ky;
[185] outtextxy(x,y,title_1); /* MGAPI */
[186] /*----------------------------- Frame */
[187] setcolor(WHITE);
[188] setlinestyle(SOLID_LINE,0,THICK_WIDTH);
[189] x=1*kx;
[190] y=2*ky;
[191] rectangle(x,y,Maxx,Maxy);
[192] setfillstyle(SOLID_FILL,BLUE);
[193] x=Maxx/2;
[194] y=Maxy/2;
[195] floodfill(x,y,WHITE);
[196] /*----------------------------- Text */
[197] settextjustify(CENTER_TEXT,CENTER_TEXT);
[198] setcolor(YELLOW);
[199] settextstyle(SMALL_FONT,HORIZ_DIR,7);
[200] x=Maxx/2;
[201] y=19*ky;
[202] outtextxy(x,y,title_4); /* Group, Code ... */
[203]
[204] settextstyle(SMALL_FONT,HORIZ_DIR,5);
[205] x=Maxx/2;
[206] y=4*ky;
[207] outtextxy(x,y,title_7); /* TI-4... */
[208]
[209] settextstyle(SMALL_FONT,HORIZ_DIR,5);
[210] setcolor(LIGHTGRAY);
[211] x=Maxx/2;
[212] y=21*ky;
[213] outtextxy(x,y,title_6); /* Speciality... */
[214]
[215] x=Maxx/2;
[216] y=22*ky;
[217] outtextxy(x,y,title_5); /* Discipline... */
[218]
[219] x=Maxx/2;
[220] y=23*ky;
[221] outtextxy(x,y,title_8); /* Teacher... */
[222]
[223] x=Maxx/2;
[224] y=24*ky;
[225] outtextxy(x,y,title_9); /* Year... */
[226]
[227] settextstyle(TRIPLEX_FONT,HORIZ_DIR,0);
[228] setusercharsize(1,1,3,2);
[229] settextjustify(CENTER_TEXT,CENTER_TEXT);
[230] x=Maxx/2;
[231] y=11*ky;
[232] setcolor(BLACK);
[233] outtextxy(x,y,title_2); /* IMITATOR... */
[234] setcolor(WHITE);
[235] outtextxy(x+4,y+4,title_2);
[236]
[237] setcolor(WHITE);
[238] settextstyle(SMALL_FONT,HORIZ_DIR,7);
[239] settextjustify(CENTER_TEXT,CENTER_TEXT);
[240] x=Maxx/2;
[241] y=14*ky;
[242] outtextxy
[243] (x,y,"(Imitator of the schemes electronics)");
[244]
[245] setcolor(YELLOW);
[246] settextstyle(SMALL_FONT,HORIZ_DIR,7);
[247] settextjustify(CENTER_TEXT,CENTER_TEXT);
[248] x=Maxx/2;
[249] y=18*ky;
[250] outtextxy(x,y,title_3); /* Student... */
[251] /*----------------------------- Happy work */
[252] settextstyle(SMALL_FONT,HORIZ_DIR,7);
[253] settextjustify(CENTER_TEXT,CENTER_TEXT);
[254] x=Maxx/2;
[255] y=16*(Maxy/ROW);
[256] while(bioskey(1)==0)
[257] {
[258] setcolor(random(16));
[259] outtextxy(x,y," HAPPY WORK ");
[260] }
[261] STOP_DRAFT;
[262] /*----------------------------- Return to text mode */
[263] text_regime();
[264] /* */
[265] return 0;
[266] }
[267] /*IIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
[268] int draft(int mode) /* <=### CHANGE ### */
[269] {
[270] /*----------------------------- Variables */
[271] int x,y;
[272] int kx; /* Scale of the title sheet */
[273] int ky;
[274] /*----------------------------- Graph. initialisation */
[275] graph_regime();
[276] /*----------------------------- Scale of the title sheet */
[277] kx=Maxx/COL_D;
[278] ky=Maxy/ROW_D;
[279] /*----------------------------- Frame */
[280] setbkcolor(BLACK);
[281] setcolor(LIGHTGRAY);
[282] setlinestyle(SOLID_LINE,0,NORM_WIDTH);
[283] rectangle(0,0,50*kx,36*ky);
[284] /*----------------------------- Title 1 */
[285] settextstyle(SMALL_FONT,HORIZ_DIR,7);
[286] settextjustify(CENTER_TEXT,CENTER_TEXT);
[287] setcolor(YELLOW);
[288] outtextxy(25*kx,1*kx,title_2);
[289] /*----------------------------- Devices */
[290] settextstyle(Font[2],HORIZ_DIR,1);
[291] setlinestyle(SOLID_LINE,0,NORM_WIDTH);
[292] setcolor(WHITE);
[293] /*------------- Devices Invertor */
[294] /* invertor 1 */
[295] rectangle(38*kx,7*ky,40*kx,11*ky);
[296] circle(39*kx,11*ky,3);
[297] setcolor(YELLOW);
[298] outtextxy(39*kx,8*ky,"1");
[299] setcolor(LIGHTGRAY);