- •Предисловие.
- •1. Основные сведения, необходимые для создания программ на языке c.
- •1.1 Общая характеристика языка c.
- •1.2. Процесс создания исполняемого файла.
- •1.3. Распределение памяти программы.
- •1.4. Основные правила работы с программами.
- •2. Программная имитация электронных схем.
- •3. Описание программы образца.
- •3.1. Подпрограммы общего назначения.
- •3.2. Подпрограммы мехатронного объекта.
- •3.3. Подпрограммы графических примитивов.
- •3.4. Подпрограммы системных сообщений.
- •3.5. Подпрограммы звуковой сигнализации.
- •3.6. Глобальные константы и переменные.
- •4. Тексты исходных файлов программы образца.
- •4.1. Подпрограммы общего назначения.
- •4.2. Подпрограммы мeхатронного объекта.
- •4.3. Подпрограммы графических примитивов.
- •4.4. Подпрограммы системных сообщений.
- •4.5. Подпрограммы звуковой сигнализации.
- •4.6. Глобальные константы и переменные.
- •5. Методические указания к лабораторным работам.
- •6. Задания на выполнение лабораторных работ.
- •6.1. Лабораторная работа 1. Разработка графического отображения титульного листа программы.
- •6.2. Лабораторная работа 2. Разработка логической схемы мехатронного объекта.
- •6.3. Лабораторная работа 3. Разработка графического отображения логической схемы мехатронного объекта.
- •6.4. Лабораторная работа 4. Разработка графического отображения работы логической схемы мехатронного объекта.
- •6.5. Лабораторная работа 5. Разработка средств сигнализации (системные сообщения, звуковая сигнализация, дата, время).
- •7. Варианты лабораторных работ.
- •8. Описание dvd диска
- •Литература.
- •Содержание.
3.4. Подпрограммы системных сообщений.
FILE: SYS_MES.H.
[16] Сообщение о старте программы [21] int SysMes_Start(); |
[17] Сообщение об окончании программы [53] int SysMes_End(); |
[18] Сообщение о дате и времени [84] int SysMes_DateTime(); |
3.5. Подпрограммы звуковой сигнализации.
FILE: SYS_MUS.H
[51] Нота [66] void n(float f,float l);
[52] Соната 17 [73] void sonata17(float W);
[53] Соната 17 [97] void sonata17r(float W);
[54] Элизе [107] void elise(float W);
[55] Сирена (восходящая-нисходящая) [115] void siren_0(float W);
[56] Сирена (восходящая) [126] void siren_1(float W);
[57] Сирена (нисходящая) [136] void siren_2(float W);
[58] Гамма (восходящая-нисходящая) [145] void scale_0(float W);
[59] Гамма (восходящая) [174] void scale_1(float W);
[60] Гамма (нисходящая) [192] void scale_2(float W);
[61] Арпеджио (восходящее-нисходящее) [210] void arpeg_0(float W);
[62] Арпеджио (восходящее) [235] void arpeg_1(float W);
[63] Арпеджио (нисходящее [251] void arpeg_2(float W);
3.6. Глобальные константы и переменные.
FILE CNSTVR.H
4. Тексты исходных файлов программы образца.
4.1. Подпрограммы общего назначения.
FILE IMI_LIS.C.
[1] /*#############################################*/
[2] /*
[3] Copyright (C) 2009 by A.E.Stefanovich tel. 236-2729, 268-3916
[4] Moscow State University of Instrument-making and Computer Sciences.
[5] (MGUPI).
[6] Chair TI-1.
[7] */
[8] /*#############################################*/
[9] /*
[10] File: IMI_LIS.C.
[11] Imitator of the schemes electronics.
[12] */
[13] /*################################## PROGRAME */
[14] /*============================== Declarations */
[15] int Graph_regime();
[16] int Text_regime();
[17] int Entry_x(); /* Input code: X0, X1, X2 */
[18] int Bit(int x,int y,int bit); /* Display bit: 0 or 1 */
[19] /*============== Includes of TURBOC.3_0 */
[20] #include <c:\TURBOC.3_0\include\stdio.h>
[21] #include <c:\TURBOC.3_0\include\conio.h>
[22] #include <c:\TURBOC.3_0\include\stdlib.h>
[23] #include <c:\TURBOC.3_0\include\graphics.h>
[24] #include <c:\TURBOC.3_0\include\dos.h>
[25] #include <c:\TURBOC.3_0\include\time.h>
[26] #include <c:\TURBOC.3_0\include\math.h>
[27] /*=======================Includes of the programe IMI_LIS.C */
[28] #include <c:\TURBOC.3_0\work\cnstvr.h> /* Constants & variables */
[29] #include <c:\TURBOC.3_0\work\sys_prim.h> /* Primitives */
[30] #include <c:\TURBOC.3_0\work\sys_mus.h> /* Music & Sound signals */
[31] #include <c:\TURBOC.3_0\work\sys_mes.h> /* System messages */
[32] /*============================= Includes of the device */
[33] /* Constants & variables, picture(draft), logic, sound signals */
[34] #include <c:\TURBOC.3_0\work\DEV_LIS.h> */
[35] /*------------- Demo (ON/OFF) */
[36] int Demo;
[37] /*###################################### MAIN */
[38] main()
[39] {
[40] /*-------- Variables */
[41] char work_exit[2];
[42] int demo[2];
[43] /**/
[44] Title_sheet();
[45] while(1)
[46] {/*---------------- Top while(1) */
[47] Dev_pct(DISPLAY);
[48] while(2)
[49] {/*-------- Top while(2) Start/Exit */
[50] clrscr(); gotoxy(20,12);
[51] cprintf(" Input 1 (for Work) or 0 (for Exit) --> ");
[52] cscanf("%s",&work_exit);
[53] if(work_exit[0]=='0') exit(EXIT_SUCCESS); /* -> EXIT SUCCESS */
[54] if(work_exit[0]=='1') break; /* -> to START */
[55] ALERT_SIGNAL;/* ERROR of the Input and ^ */
[56] }/*-------- Down while (2) */
[57] /**/
[58] while(3)
[59] {/*-------- Top while(3) Demo ON/OFF */
[60] clrscr(); gotoxy(20,12);
[61] cprintf(" Demo ON/OFF (1/0) --> ");
[62] cscanf("%s",&demo);
[63] if(demo[0]=='0') {Demo=OFF; break;} /* -> to START */
[64] if(demo[0]=='1') {Demo=ON; break;} /* -> to START */
[65] ALERT_SIGNAL;/* ERROR of the Input and ^ */
[66] }/*-------- Down while (3) */
[67] /*-------- START */
[68] Entry_x();
[69] /**/
[70] if(Demo==ON) {SysMes_Start(); SysMes_DateTime();}
[71] Dev_pct(WORK);
[72] /**/
[73] if(Demo==ON) SysMes_End();
[74] }/*---------------- Down while (1) */
[75] }
[76] /*####################################### SUBPROGRAMS */
[77] /*IIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
[78] int Graph_regime()
[79] {
[80] /*-------- Variables */
[81] int gdriver=DETECT,gmode,errorcode;
[82] /*-------- Graph. initialisation */
[83] initgraph(&gdriver,&gmode,"C:\\TURBOC.3_0\\BGI");
[84] /**/
[85] errorcode=graphresult();
[86] if(errorcode != grOk)
[87] {
[88] gotoxy(1,24);
[89] textattr(LIGHTRED+(BLACK<<4));
[90] cprintf("GRAPHICS ERROR: %s\n",grapherrormsg(errorcode));
[91] STOP;
[92] exit(EXIT_FAILURE); /* -> EXIT FAILURE */
[93] }
[94] /* Max. dimensions of the screen in the pixels */
[95] Maxx=getmaxx();
[96] Maxy=getmaxy();
[97] /*----------------------------- Installuserfont */
[98] Font[0]=installuserfont("bold");
[99] Font[1]=installuserfont("euro"); /* Cyr */
[100] Font[2]=installuserfont("lcom"); /* Cyr */
[101] Font[3]=installuserfont("litt");
[102] Font[4]=installuserfont("sans");
[103] Font[5]=installuserfont("scri"); /* Cyr manuscript */
[104] Font[6]=installuserfont("simp"); /* Cyr */
[105] Font[7]=installuserfont("tscr"); /* Cyr manuscript */
[106] /**/
[107] return 0;
[108] }
[109] /*IIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
[110] Text_regime()
[111] {
[112] closegraph();
[113] restorecrtmode();
[114] textbackground(BLACK);
[115] textcolor(WHITE);
[116] /**/
[117] return 0;
[118] }
[119] /*IIIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
[120] int Entry_x()
[121] {
[122] /*-------- Variables */
[123] char ch[80];
[124] /*-------- Input code X0, X1, X2 */
[125] clrscr();
[126] /**/
[127] for(;;)
[128] {
[129] BELL;
[130] gotoxy(29,12);
[131] delline();
[132] cputs(" Command X0 (0 or 1) --> ");
[133] cscanf("%s",&ch);
[134] if(ch[0]=='1') {X0=1; break;}
[135] if(ch[0]=='0') {X0=0; break;}
[136] }
[137] /**/
[138] for(;;)
[139] {
[140] BELL;
[141] gotoxy(29,13);
[142] delline();
[143] cputs(" Command X1 (0 or 1) --> ");
[144] cscanf("%s",&ch);
[145] if(ch[0]=='1') {X1=1; break;}
[146] if(ch[0]=='0') {X1=0; break;}
[147] }
[148] /**/
[149] for(;;)
[150] {
[151] BELL;
[152] gotoxy(29,14);
[153] delline();
[154] cputs(" Command X2 (0 or 1) --> ");
[155] cscanf("%s",&ch);
[156] if(ch[0]=='1') {X2=1; break;}
[157] if(ch[0]=='0') {X2=0; break;}
[158] }
[159] STOP;
[160] /**/
[161] return 0;
[162] }
[163] /*IIIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
[164] int Bit(int x,int y,int bit)
[165] {
[166] /*-------- Variables */
[167] int charsize=6;
[168] /*-------- Set... */
[169] settextstyle(Font[3],HORIZ_DIR,charsize);
[170] settextjustify(CENTER_TEXT,CENTER_TEXT);
[171] setbkcolor(BLACK);
[172] /**/
[173] if(bit==0)
[174] {
[175] setcolor(LIGHTBLUE);
[176] outtextxy(x,y,"0");
[177] }
[178] if(bit==1)
[179] {
[180] setcolor(LIGHTRED);
[181] outtextxy(x,y,"1");
[182] }
[183] /**/
[184] return 0;
[185] }
[186] /*##############################################*/