Good trang web để tìm hiểu interfacing với C

E

electrojit

Guest
http://www.learn-c.com/

tải về toàn bộ trang web với "Offline Explorer" và tận hưởng những nội dung offline tại convinence của bạn

 
đọc kinh nghiệm của tôi tại cổng song song interfacing từ nhóm yahoo-booksbybibin
http://tech.groups.yahoo.com/group/booksbybibin/

Bibin John
www.bibinjohn.tk

 
thử chương trình này
Mã số:

# include "stdio.h"

# include "conio.h"

# include "graphics.h"

# include "dos.h"

# include "stdlib.h"

# define esc 27

# define outport 0x378

# define 0xFF ledon

# define 0x00 ledoff

int tĩnh không có [8] = (0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80);

int c,f=0;
void button (int, int, int, int, char []);

void blink (int, int, int, int);

void display (void);

void main (void)

(

int dr = phát hiện, m, a, b;

initgraph (& dr, & m, "c: \ \ tc \ \ BGI");

char ch, name [10];

chính:

cleardevice ();

hiển thị ();

nút (80,75,130,100, "A");

nút (80.125.130.150, "B");

nút (80.175.130.200, "C");

nút (80.225.130.250, "D");

nút (80.275.130.300, "E");

nút (80.325.130.350, "F");

nút (80.375.130.400, "Exit");

setcolor (1);

settextstyle (11,0,3);

outtextxy (140.390, "Press ESC ĐỂ THOÁT");

outtextxy (140,90, "Glow LED OF YOUR CHOICE");

outtextxy (140.140, "đèn LED nhấp nháy");

outtextxy (140.190, "Xoay trái");

outtextxy (140.240, "Xoay phải");

outtextxy (140.290, "xoay LEFT RIGHT");

outtextxy (140.340, "ONE ON ONE OFF");

ch = getch ();

if (ch == 27) / / cho lối ra

(

closegraph ();

exit (0);

)

khác

if (ch == 'a' | | ch == 'A') / / Nhập Led Không có Một

(

Đại diện:

cleardevice ();

hiển thị ();

setcolor (1);

setfillstyle (1,0);

hình chữ nhật (100.100.550.300); / / đen

floodfill (120,120,1);

setcolor (1);

hình chữ nhật (315.140.330.160); / / nhỏ màu xanh

setcolor (4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

setcolor (1);

settextstyle (10,0,1);

outtextxy (180.100, "ENTER LED NO 0-7");

if (41,10);

gets (tên);

if (name [0] == 48) / / dẫn 0 sáng

(

outportb (outport, không có [0]);

setcolor (4);

setfillstyle (1,4);

floodfill (261,181,4);

)

if (name [0] == 49) / / dẫn 1 sáng

(

outportb (outport, không có [1]);

setcolor (4);

setfillstyle (1,4);

floodfill (281,181,4);

)

if (name [0] == 50) / / dẫn 2 sáng

(

outportb (outport, không có [2]);

setcolor (4);

setfillstyle (1,4);

floodfill (301,181,4);

)

if (name [0] == 51) / / dẫn 3 sáng

(

outportb (outport, không có [3]);

setcolor (4);

setfillstyle (1,4);

floodfill (321,181,4);

)

if (name [0] == 52) / / 4 dẫn sáng

(

outportb (outport, không [4]);

setcolor (4);

setfillstyle (1,4);

floodfill (341,181,4);

)

if (name [0] == 53) / / 5 đã dẫn sáng

(

outportb (outport, không có [5]);

setcolor (4);

setfillstyle (1,4);

floodfill (361,181,4);

)

if (name [0] == 54) / / 6 dẫn sáng

(

outportb (outport, không có [6]);

setcolor (4);

setfillstyle (1,4);

floodfill (381,181,4);

)

if (name [0] == 55) / / 7 dẫn sáng

(

outportb (outport, không có [7]);

setcolor (4);

setfillstyle (1,4);

floodfill (401,181,4);

)

setcolor (1);

settextstyle (11,0,10);

outtextxy (210.350, "Press R TO RETURN TO MAIN");

outtextxy (240.370, "Press ESC ĐỂ THOÁT");

ch = getch ();

if (ch == 'r' | | R == 'ch')

goto chính;

khác

if (ch == 27) / / cho lối ra

(

closegraph ();

exit (0);

)

khác

goto rep;

) / / A END

////////// LED NO B

if (ch == 'b' | | ch == 'B')

(cleardevice ();

hiển thị ();

setcolor (1);

setfillstyle (1,0);

hình chữ nhật (100.100.550.300); / / đen

floodfill (120,120,1);

setcolor (4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0setcolor (14);

settextstyle (10,0,1);

outtextxy (145.100, "BÁO CHÍ BẤT CỨ KEY TO STOP");

setcolor (1);

settextstyle (11,0,10);

outtextxy (210.350, "Press R TO RETURN TO MAIN");

outtextxy (240.370, "Press ESC ĐỂ THOÁT");

int a = 4;

trong khi (! kbhit ())

(

/ / harware giao diện

outportb (outport, ledon);

setcolor (11);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

setfillstyle (1, a);

floodfill (261,181,11);

floodfill (281,181,11);

floodfill (301,181,11);

floodfill (321,181,11);

floodfill (341,181,11);

floodfill (361,181,11);

floodfill (381,181,11);

floodfill (401,181,11);

trì hoãn (800);

outportb (outport, ledoff);

một = 0,

setcolor (11);

setfillstyle (1, a);

floodfill (261,181,11);

floodfill (281,181,11);

floodfill (301,181,11);

floodfill (321,181,11);

floodfill (341,181,11);

floodfill (361,181,11);

floodfill (381,181,11);

floodfill (401,181,11);

a = 4;

trì hoãn (800);

)ch = getch ();

if (ch == 'r' | | R == 'ch')

goto chính;

khác

if (ch == 27) / / cho lối ra

(

closegraph ();

exit (0);

)

) ///////// B END

/ / dẫn không có C

if (ch == 'c' | | ch == 'C')

(

cleardevice ();

hiển thị ();

setcolor (1);

setfillstyle (1,0);

hình chữ nhật (100.100.550.300); / / đen

floodfill (120,120,1);

setcolor (4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

setcolor (14);

settextstyle (10,0,1);

outtextxy (145.100, "BÁO CHÍ BẤT CỨ KEY TO STOP");

setcolor (1);

settextstyle (11,0,10);

outtextxy (210.350, "Press R TO RETURN TO MAIN");

outtextxy (240.370, "Press ESC ĐỂ THOÁT");

c = 401;

trong khi (! kbhit ())

(

setcolor (11);

setfillstyle (1,4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

floodfill (c, 181,11);

trì hoãn (200);

setfillstyle (1,0);

floodfill (c, 181,11);

trì hoãn (200);

c-= 20;

nếu (c == 241)

c = 401;/ / Phần cứng

for (a = 0; a <= 7; một )

(

outportb (outport, không có [a]);

trì hoãn (800);

)

)

ch = getch ();

if (ch == 'r' | | R == 'ch')

goto chính;

khác

if (ch == 27) / / cho lối ra

(

closegraph ();

exit (0);

}////////////// C kết thúc

)

////////////////////// D

if (ch == 'd' | | ch == 'D')

(

cleardevice ();

hiển thị ();

setcolor (1);

setfillstyle (1,0);

hình chữ nhật (100.100.550.300); / / đen

floodfill (120,120,1);

setcolor (4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

setcolor (14);

settextstyle (10,0,1);

outtextxy (145.100, "BÁO CHÍ BẤT CỨ KEY TO STOP");

setcolor (1);

settextstyle (11,0,10);

outtextxy (210.350, "Press R TO RETURN TO MAIN");

outtextxy (240.370, "Press ESC ĐỂ THOÁT");

c = 261;

trong khi (! kbhit ())

(

setcolor (11);

setfillstyle (1,4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

floodfill (c, 181,11);

trì hoãn (500);

setfillstyle (1,0);

floodfill (c, 181,11);

trì hoãn (500);

c = 20;

nếu (c == 421)

c = 261;

/ / Hard ware

for (a = 7; a> = 0; một -)

(

outportb (outport, không có [a]);

trì hoãn (800);

)

)

ch = getch ();

if (ch == 'r' | | R == 'ch')

goto chính;

khác

if (ch == 27) / / cho lối ra

(

closegraph ();

exit (0);

}///////////

) ////////// D cuối

////////////////////// E

if (ch == 'e' | | ch == 'E')

(

cleardevice ();

hiển thị ();

setcolor (1);

setfillstyle (1,0);

hình chữ nhật (100.100.550.300); / / đen

floodfill (120,120,1);

setcolor (4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

setcolor (14);

settextstyle (10,0,1);

outtextxy (145.100, "BÁO CHÍ BẤT CỨ KEY TO STOP");

setcolor (1);

settextstyle (11,0,10);

outtextxy (210.350, "Press R TO RETURN TO MAIN");

outtextxy (240.370, "Press ESC ĐỂ THOÁT");

c = 401;

trong khi (! kbhit ())

(

setcolor (11);

setfillstyle (1,4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

if (f == 0)

(

floodfill (c, 181,11);

trì hoãn (100);

setfillstyle (1,0);

floodfill (c, 181,11);

trì hoãn (100);

c-= 20;

nếu (c == 241)

(

f = 1;

c = 261;

)

)

if (f == 1)

(

floodfill (c, 181,11);

trì hoãn (5);

setfillstyle (1,0);

floodfill (c, 181,11);

trì hoãn (5);

c = 20;

nếu (c == 421)

(

f = 0;

c = 401;

)

)

/ / Hard ware

for (a = 7; a> = 0; một -)

(

outportb (outport, không có [a]);

trì hoãn (800);

)

for (a = 0; a <= 7; một )

(

outportb (outport, không có [a]);

trì hoãn (800);

)

)

ch = getch ();

if (ch == 'r' | | R == 'ch')

goto chính;

khác

if (ch == 27) / / cho lối ra

(

closegraph ();

exit (0);

}///////////

) ////////// E kết thúc

////////////////////// F

if (ch == 'e' | | F == 'ch')

(

cleardevice ();

hiển thị ();

setcolor (1);

setfillstyle (1,0);

hình chữ nhật (100.100.550.300); / / đen

floodfill (120,120,1);

setcolor (4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

setcolor (14);

settextstyle (10,0,1);

outtextxy (145.100, "BÁO CHÍ BẤT CỨ KEY TO STOP");

setcolor (1);

settextstyle (11,0,10);

outtextxy (210.350, "Press R TO RETURN TO MAIN");

outtextxy (240.370, "Press ESC ĐỂ THOÁT");

trong khi (! kbhit ())

(

setcolor (11);

setfillstyle (1,4);

circle (400,180,5); / / dẫn 7

circle (380,180,5); / / dẫn 6

circle (360,180,5); / / dẫn 5

circle (340,180,5); / / dẫn 4

circle (320,180,5); / / dẫn 3

circle (300,180,5); / / dẫn 2

circle (280,180,5); / / dẫn 1

circle (260,180,5); / / dẫn 0

floodfill (401,181,11);

floodfill (361,181,11);

floodfill (321,181,11);

floodfill (281,181,11);

trì hoãn (500);

setfillstyle (1,0);

floodfill (401,181,11);

floodfill (361,181,11);

floodfill (321,181,11);

floodfill (281,181,11);

trì hoãn (500);

setfillstyle (1,4);

floodfill (381,181,11);

floodfill (341,181,11);

floodfill (301,181,11);

floodfill (261,181,11);

trì hoãn (500);

setfillstyle (1,0);

floodfill (381,181,11);

floodfill (341,181,11);

floodfill (301,181,11);

floodfill (261,181,11);

trì hoãn (500);/ / Hard wareoutportb (outport, không có [0xAA]);

trì hoãn (800);

outportb (outport, không có [0x55]);)

ch = getch ();

if (ch == 'r' | | R == 'ch')

goto chính;

khác

if (ch == 27) / / cho lối ra

(

closegraph ();

exit (0);

}///////////

) ////////// F kết thúcgetch ();

closegraph ();

) / / Chính kết thúcvoid display (void)

(

int i, f [10] = (7,7,100,30,320,60,520,30,629,7);

setcolor (13);

setfillstyle (1,3);

hình chữ nhật (1,1,638,478);

floodfill (5,5,13);

setcolor (11);

setfillstyle (7,9); / * Text nền * /

fillpoly (5, f); / * Text Fillpoly * /

setcolor (14);

settextstyle (7,0,3);

outtextxy (170,6, "đèn LED - Displa Y");

setcolor (1);

settextstyle (11,0,3);

outtextxy (150.445, "Bản quyền Hasan & Atif PRODUCTIONS 2006");

outtextxy (220.457, "Tất cả các quyền");

)void nút (int c1, int r1, int c2, int r2, char ch [])

(

setcolor (0);

hình chữ nhật (c1 1, r1 1, c2 2, r2 2);

setcolor (8);

hình chữ nhật (c1 2, r1 2, c2 1, r2 1);

setcolor (15);

hình chữ nhật (c1-1, r1-1, c2, r2);

setcolor (7);

setfillstyle (1,7);

hình chữ nhật (c1, r1, c2, r2);

floodfill (c1 5, r1 5,7);

setcolor (0);

outtextxy (c1 11, r1 7, ch);

)

void blink (int c1, int r1, int c2, int r2)

(

setcolor (8);

hình chữ nhật (c1-1, r1-1, c2-2, r2-2);

setcolor (0);

hình chữ nhật (c1-2, r1-2, c2-1, r2-1);

setcolor (15);

hình chữ nhật (c1, r1, c2 1, r2 1);

setcolor (7);

setfillstyle (1,7);

hình chữ nhật (c1, r1, c2, r2);

floodfill (c1 5, r1 5,7);

)
 

Welcome to EDABoard.com

Sponsor

Back
Top