imDPd (780149), страница 2
Текст из файла (страница 2)
Создать программный имитатор двоичной цифровой системы управления, имеющий следующую схему (см. Приложение 2):
1. Три логические устройства первого уровня:
Таблица. 1, N = 5.
2. Коммутация трех логических устройств первого уровня с входными X1, X2, X3 и инвертированными Y1, Y2, Y3 цепями:
Таблица. 2, N = 1.
3. Три логические устройства второго уровня:
Таблица. 1, N = 3.
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. Исходный текст программы на языке Си.
/*#####################################################*/
/* Copyright (C) 2003-2004 by A.E.Stefanovich tel. 939-4182, 236-2729
Moscow Town Palace Creation of the Children and Youth
Departement Astronomy
*/
/*#####################################################*/
/* File: imiaDP.c
Imitator of the schemes electronics
*/
/*############################################# LEGEND */
/* <=### CHANGE ###
Moscow Town Palace of the Creation of the Children and Youth
Department Astronomy
---------------
Pupil: L.V. Doronina
School: 45
Class: 9
Tel.: 125-1719
Discipline: Programming and bases of algorithms
Group: 1
Teacher: A.E. Stefanovich
---------------
Year: 2003-2004
---------------
DEVICE LVD
Entrances: X1,X2,X3;
Or1=Y2Y1X3+Y1Y3X2+Y3Y2X1+X1X2X3
Or2=X3X2+X3X1+X2X1
Exits:Z1, Z2
*/
/*############################################## PROGRAMME */
/*============================= Includes */
#include <c:\TURBOC.3_0\include\stdio.h>
#include <c:\TURBOC.3_0\include\conio.h>
#include <c:\TURBOC.3_0\include\stdlib.h>
#include <c:\TURBOC.3_0\include\graphics.h>
/*============================= Declarations */
int graph_regime();
int text_regime();
int title_sheet();
int draft(int mode); /* <=### CHANGE ### */
int entry_x(); /* <=### CHANGE ### */
int bit(int x,int y,int bit); /* 0 or 1 */
/*============================= Global constants */
#define LF cprintf("\n")
#define CR cprintf("\r")
#define HT cprintf("\t")
#define VT cprintf("\v")
#define BS cprintf("\b")
#define BELL cprintf("\a")
/* */
#define STOP getch()
#define STOP_DRAFT bioskey(0)
#define ALERT_SIGNAL cprintf("\a\a\a")
#define ROW 25
#define COL 80
#define ROW_D 36 /* <=### CHANGE ### */
#define COL_D 50 /* <=### CHANGE ### */
/* */
#define DISPLAY 1
#define WORK 0
/*============================= Global variable */
/*----------------------------- Device */ /* <=### CHANGE ### */
unsigned int X1,X2,X3; /* Entrances */
unsigned int Y1,Y2,Y3; /* Invert. Entrances */
unsigned int And1,And2,And3,And4,And5,And6,And7; /* 1 range */
unsigned int Or1,Or2; /* 2 range */
/*------------------------------ Global graphic variables */
int Font[8]; /* NN user characters */
int Maxx,Maxy; /* Max. dimensions of the screen in the pixels */
/*----------------------------- Text */ /* <=### CHANGE ### */
char *title_1=
" Moscow Town Palace Creation of the Children and Youth ";
char *title_2=
" I M I T A T O R - LVD ";
char *title_3=
" Pupil: L.V. Doronina ";
char *title_4=
" School: 45; Class: 9; Tel.: 125-1719 ";
char *title_5=
" Discipline: Programming and bases of algorithms ";
char *title_6=
" Group: 1 ";
char *title_7=
" Department Astronomy ";
char *title_8=
" Teacher: A.E. Stefanovich ";
char *title_9=
" Year: 2003-2004 ";
/*------------- Text (device) */
char *title_10=
" Z1=Y2Y1X3+Y1Y3X2+Y3Y2X1+X1X2X3 ";
char *title_11=
" Z2=X3X2+X3X1+X2X1 ";
/*############################################## MAIN */
main()
{
/*----------------------------- Variables */
char work_exit[2];
/*-----------------------------*/
title_sheet();
/* */
draft(DISPLAY);
/* */
while(1)
{/*----------------------------- Top while(1) */
for(;;)
{/*------------ Top for(;;) */
clrscr();
gotoxy(20,12);
cprintf
(" Input 1 (for Work) or 0 (for Exit) --> ");
cscanf("%s",&work_exit);
if(work_exit[0]=='0')
exit(EXIT_SUCCESS); /* -> EXIT SUCCESS */
if(work_exit[0]=='1')
break; /* -> to START */
ALERT_SIGNAL;/* ERROR of the Input and ^ */
}/*------------ Down for(;;) */
/*----------------------------- START */
entry_x();
/* */
draft(WORK);
}/*----------------------------- Down while(1) */
}
/*###################################### SUB_PROGRAMMS */
/*IIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
int graph_regime()
{
/*----------------------------- Variables */
int gdriver=DETECT,gmode,errorcode;
/*----------------------------- Graph. initialisation */
initgraph(&gdriver,&gmode,"");
errorcode=graphresult();
if(errorcode != grOk)
{
gotoxy(1,24);
textattr(LIGHTRED+(BLACK<<4));
cprintf("GRAPHICS ERROR: %s\n",grapherrormsg(errorcode));
STOP;
exit(EXIT_SUCCESS);
}
Maxx=getmaxx();
Maxy=getmaxy();
/*----------------------------- Installuserfont */
Font[0]=installuserfont("bold");
Font[1]=installuserfont("euro"); /* Cyr */
Font[2]=installuserfont("lcom"); /* Cyr */
Font[3]=installuserfont("litt");
Font[4]=installuserfont("sans");
Font[5]=installuserfont("scri"); /* Cyr manuscript */
Font[6]=installuserfont("simp"); /* Cyr */
Font[7]=installuserfont("tscr"); /* Cyr manuscript */
/* */
return 0;
}
/*IIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
text_regime()
{
closegraph();
restorecrtmode();
textbackground(BLACK);
textcolor(WHITE);
/* */
return 0;
}
/*IIIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
int title_sheet()
{
/*----------------------------- Variables */
int x,y;
int kx; /* Scale of the title sheet */
int ky;
/*----------------------------- Graph. initialisation */
graph_regime();
/*----------------------------- Scale of the title sheet */
kx=Maxx/COL;
ky=Maxy/ROW;
/*----------------------------- Title 1 */
setcolor(YELLOW);
setbkcolor(BLACK);
settextstyle(SMALL_FONT,HORIZ_DIR,5);
settextjustify(CENTER_TEXT,CENTER_TEXT);
x=Maxx/2;
y=1*ky;
outtextxy(x,y,title_1); /* DP... */
/*----------------------------- Frame */
setcolor(WHITE);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);
x=1*kx;
y=2*ky;
rectangle(x,y,Maxx,Maxy);
setfillstyle(SOLID_FILL,BLUE);
x=Maxx/2;
y=Maxy/2;
floodfill(x,y,WHITE);
/*----------------------------- Text */
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(YELLOW);
settextstyle(SMALL_FONT,HORIZ_DIR,7);
x=Maxx/2;
y=19*ky;
outtextxy(x,y,title_4); /* School, Class, Tel. ... */
settextstyle(SMALL_FONT,HORIZ_DIR,5);
x=Maxx/2;
y=4*ky;
outtextxy(x,y,title_7); /* Department Astronomy */
settextstyle(SMALL_FONT,HORIZ_DIR,5);
setcolor(LIGHTGRAY);
x=Maxx/2;
y=21*ky;
outtextxy(x,y,title_6); /* Group... */
x=Maxx/2;
y=22*ky;
outtextxy(x,y,title_5); /* Discipline... */
x=Maxx/2;
y=23*ky;
outtextxy(x,y,title_8); /* Teacher... */
x=Maxx/2;
y=24*ky;
outtextxy(x,y,title_9); /* Year... */
settextstyle(TRIPLEX_FONT,HORIZ_DIR,0);
setusercharsize(1,1,3,2);
settextjustify(CENTER_TEXT,CENTER_TEXT);
x=Maxx/2;
y=11*ky;
setcolor(BLACK);
outtextxy(x,y,title_2); /* IMITATOR... */
setcolor(WHITE);
outtextxy(x+4,y+4,title_2);
setcolor(WHITE);
settextstyle(SMALL_FONT,HORIZ_DIR,7);
settextjustify(CENTER_TEXT,CENTER_TEXT);
x=Maxx/2;
y=14*ky;
outtextxy
(x,y,"(Imitator of the schemes electronics)");
setcolor(YELLOW);
settextstyle(SMALL_FONT,HORIZ_DIR,7);
settextjustify(CENTER_TEXT,CENTER_TEXT);
x=Maxx/2;
y=18*ky;
outtextxy(x,y,title_3); /* Pupil... */
/*----------------------------- Happy work */
settextstyle(SMALL_FONT,HORIZ_DIR,7);
settextjustify(CENTER_TEXT,CENTER_TEXT);
x=Maxx/2;
y=16*(Maxy/ROW);
while(bioskey(1)==0)
{
setcolor(random(16));
outtextxy(x,y," HAPPY WORK ");
}
STOP_DRAFT;
/*----------------------------- Return to text mode */
text_regime();
/* */
return 0;
}
/*IIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
int draft(int mode) /* <=### CHANGE ### */
{
/*----------------------------- Variables */
int x,y;
int kx; /* Scale of the title sheet */
int ky;
/*----------------------------- Graph. initialisation */
graph_regime();
/*----------------------------- Scale of the title sheet */
kx=Maxx/COL_D;
ky=Maxy/ROW_D;
/*----------------------------- Frame */
setbkcolor(BLACK);
setcolor(LIGHTGRAY);
setlinestyle(SOLID_LINE,0,NORM_WIDTH);
rectangle(0,0,50*kx,36*ky);
/*----------------------------- Title 1 */
settextstyle(SMALL_FONT,HORIZ_DIR,7);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(YELLOW);
outtextxy(25*kx,1*kx,title_2);
/*----------------------------- Devices */
settextstyle(Font[2],HORIZ_DIR,1);
setlinestyle(SOLID_LINE,0,NORM_WIDTH);
setcolor(WHITE);
/*------------- Devices Invertor */
/* invertor 1 */
rectangle(38*kx,7*ky,40*kx,11*ky);
circle(39*kx,11*ky,3);
setcolor(YELLOW);
outtextxy(39*kx,8*ky,"1");
setcolor(LIGHTGRAY);
outtextxy(39*kx,10*ky,"1");
/* invertor 2 */
rectangle(42*kx,7*ky,44*kx,11*ky);
circle(43*kx,11*ky,3);
setcolor(YELLOW);
outtextxy(43*kx,8*ky,"1");
setcolor(LIGHTGRAY);
outtextxy(43*kx,10*ky,"2");
/* invertor 3 */
rectangle(46*kx,7*ky,48*kx,11*ky);
circle(47*kx,11*ky,3);
setcolor(YELLOW);
outtextxy(47*kx,8*ky,"1");
setcolor(LIGHTGRAY);
outtextxy(47*kx,10*ky,"3");
/*------------- Devices And */
/* And 1*/
rectangle(4*kx,17*ky,8*kx,21*ky);
setcolor(YELLOW);
outtextxy(6*kx,18*ky,"&");
setcolor(LIGHTGRAY);
outtextxy(6*kx,20*ky,"1");
/* And 2 */
rectangle(9*kx,17*ky,13*kx,21*ky);
setcolor(YELLOW);
outtextxy(11*kx,18*ky,"&");
setcolor(LIGHTGRAY);
outtextxy(11*kx,20*ky,"2");
/* And 3 */
rectangle(14*kx,17*ky,18*kx,21*ky);
setcolor(YELLOW);
outtextxy(16*kx,18*ky,"&");
setcolor(LIGHTGRAY);
outtextxy(16*kx,20*ky,"3");
/* And 4 */
rectangle(19*kx,17*ky,23*kx,21*ky);
setcolor(YELLOW);
outtextxy(21*kx,18*ky,"&");
setcolor(LIGHTGRAY);
outtextxy(21*kx,20*ky,"4");















