[ บทความ : ทดลองใช้บอร์ด ET-DIO ตอนที่ 6 ] - Test 8253 (Pascal)

	{
	    Filename : Test8253.PAS
	    Author   : ETT
	               www.etteam.com
	    Hardware : ET-DIO
	    Compiler : Turbo Pascal / DOS

	}

	program timertest;
	uses crt;

	var  cnt0,cnt1,cnt2 : integer;

	Const  Ch0M0 = $10;     Ch0M3 = $16;
	       Ch1M0 = $50;     Ch1M3 = $56;
	       Ch2M0 = $90;     Ch2M3 = $96;

	       Ch0M1 = $12;     Ch0M4 = $18;
	       Ch1M1 = $52;     Ch1M4 = $58;
	       Ch2M1 = $92;     Ch2M4 = $98;

	       Ch0M2 = $14;     Ch0M5 = $1A;
	       Ch1M2 = $54;     Ch1M5 = $5A;
	       Ch2M2 = $94;     Ch2M5 = $9A;
	       Count = $0F;


	procedure mode0;
	begin
	  gotoxy(5,5);write(' 8253 test Mode 0 ( Interrupe On Terminal Count )');
	  port[$307] := Ch0M0;
	  port[$307] := Ch1M0;
	  port[$307] := Ch2M0;
	  port[$304] := Count;
	  port[$305] := Count;
	  port[$306] := Count;
	  port[$300] := $01;
	  repeat
	    port[$307] := $0F;
	    port[$307] := $4F;
	    port[$307] := $8F;
	    cnt0 := port[$304];gotoxy(15,10);write('Counter 0  : ',cnt0:8);
	    cnt1 := port[$305];gotoxy(15,15);write('Counter 1  : ',cnt1:8);
	    cnt2 := port[$306];gotoxy(15,20);write('Counter 2  : ',cnt2:8);
	    clreol;
	  until keypressed;
	end;

	procedure mode1;
	begin
	  gotoxy(5,5);write(' 8253 test Mode 1 ( Programmable One Short )');
	  port[$307] := $12; { program cnt 0 work in mode1 (program one short) }
	  port[$307] := $52; { program cnt 0 work in mode1 (program one short) }
	  port[$307] := $92; { program cnt 0 work in mode1 (program one short) }
	  port[$304] := $0F; { set value of countint for cnt0 = 15 }
	  port[$305] := $0F; { set value of countint for cnt1 = 15 }
	  port[$306] := $0F; { set value of countint for cnt2 = 15 }
	  port[$300] := $01;
	  repeat
	    port[$307] := $0F;
	    port[$307] := $4F;
	    port[$307] := $8F;
	    cnt0 := port[$304];gotoxy(15,10);write('Counter 0  : ',cnt0:8);
	    cnt1 := port[$305];gotoxy(15,15);write('Counter 1  : ',cnt1:8);
	    cnt2 := port[$306];gotoxy(15,20);write('Counter 2  : ',cnt2:8);
	    gotoxy(5,23);write(' press anakey to continue ');
	    clreol;
	  until Keypressed;
	end;
	
	procedure mode2;
	begin
	  gotoxy(5,5);write(' 8253 test Mode 2 ( Rate Generator ) ');
	  port[$307] := $14; { program cnt 0 work in mode2 (rate gen) }
	  port[$307] := $54; { program cnt 0 work in mode2 (rate gen) }
	  port[$307] := $94; { program cnt 0 work in mode2 (rate gen) }
	  port[$304] := $0F; { set value of countint for cnt0 = 15 }
	  port[$305] := $0F; { set value of countint for cnt1 = 15 }
	  port[$306] := $0F; { set value of countint for cnt2 = 15 }
	  port[$300] := $01;
	  repeat
	    port[$307] := $0F;
	    port[$307] := $4F;
	    port[$307] := $8F;
	    cnt0 := port[$304];gotoxy(15,10);write('Counter 0  : ',cnt0:8);
	    cnt1 := port[$305];gotoxy(15,15);write('Counter 1  : ',cnt1:8);
	    cnt2 := port[$306];gotoxy(15,20);write('Counter 2  : ',cnt2:8);
	    gotoxy(5,23);write(' press anakey to continue ');
	    clreol;
	  until keypressed;
	end;

	procedure mode3;
	begin
	  gotoxy(5,5);write(' 8253 test Mode 3  ( Squre Wave Rate Generator ) ');
	  port[$307] := $16; { program cnt 0 work in mode3 (square wave gen) }
	  port[$307] := $56; { program cnt 0 work in mode3 (square wave gen) }
	  port[$307] := $96; { program cnt 0 work in mode3 (square wave gen) }
	  port[$304] := $0F; { set value of countint for cnt0 = 15 }
	  port[$305] := $0F; { set value of countint for cnt1 = 15 }
	  port[$306] := $0F; { set value of countint for cnt2 = 15 }
	  port[$300] := $01;
	  repeat
	    port[$307] := $0F;
	    port[$307] := $4F;
	    port[$307] := $8F;
	    cnt0 := port[$304];gotoxy(15,10);write('Counter 0  : ',cnt0:8);
	    cnt1 := port[$305];gotoxy(15,15);write('Counter 1  : ',cnt1:8);
	    cnt2 := port[$306];gotoxy(15,20);write('Counter 2  : ',cnt2:8);
	    gotoxy(5,23);write(' press anakey to continue ');
	    clreol;
	  until keypressed;
	end;

	procedure mode4;
	begin
	  gotoxy(5,5);write(' 8253 test Mode 4 ( Soft Ware Trigger Strobe ) ');
	  port[$307] := $18; { program cnt 0 work in mode4 (soft ware trig) }
	  port[$307] := $58; { program cnt 0 work in mode4 (soft ware trig) }
	  port[$307] := $98; { program cnt 0 work in mode4 (soft ware trig) }
	  port[$304] := $0F; { set value of countint for cnt0 = 15 }
	  port[$305] := $0F; { set value of countint for cnt1 = 15 }
	  port[$306] := $0F; { set value of countint for cnt2 = 15 }
	  port[$300] := $01;
	  repeat
	    port[$307] := $0F;
	    port[$307] := $4F;
	    port[$307] := $8F;
	    cnt0 := port[$304];gotoxy(15,10);write('Counter 0  : ',cnt0:8);
	    cnt1 := port[$305];gotoxy(15,15);write('Counter 1  : ',cnt1:8);
	    cnt2 := port[$306];gotoxy(15,20);write('Counter 2  : ',cnt2:8);
	    gotoxy(5,23);write(' press anakey to continue ');
	    clreol;
	  until Keypressed;
	end;

	procedure mode5;
	begin
	  gotoxy(5,5);write(' 8253 test Mode 5 ( Hard Ware Trigger Strobe ) ');
	  port[$307] := $1A; { program cnt 0 work in mode5 (hard ware trig) }
	  port[$307] := $5A; { program cnt 0 work in mode5 (hard ware trig) }
	  port[$307] := $9A; { program cnt 0 work in mode5 (hard ware trig) }
	  port[$304] := $0F; { set value of countint for cnt0 = 15 }
	  port[$305] := $0F; { set value of countint for cnt1 = 15 }
	  port[$306] := $0F; { set value of countint for cnt2 = 15 }
	  port[$300] := $01;
	  repeat
	    port[$307] := $0F;
	    port[$307] := $4F;
	    port[$307] := $8F;
	    cnt0 := port[$304];gotoxy(15,10);write('Counter 0  : ',cnt0:8);
	    cnt1 := port[$305];gotoxy(15,15);write('Counter 1  : ',cnt1:8);
	    cnt2 := port[$306];gotoxy(15,20);write('Counter 2  : ',cnt2:8);
	    gotoxy(5,23);write(' press anakey to continue ');
	    clreol;
	  until keypressed;
	end;

	begin
	  clrscr;
	  port[$303] := $82;
	  mode0;
	  port[$300] := $00;
	  clrscr;
	  mode1;
	  port[$300] := $00;
	  clrscr;
	  mode2;
	  port[$300] := $00;
	  clrscr;
	  mode3;
	  port[$300] := $00;
	  clrscr;
	  mode4;
	  port[$300] := $00;
	  clrscr;
	  mode5;
	  writeln;readln;
	  port[$300] := $00;
	end.

DOWNLOAD
1. Pascal DOS : 51.7 KB
2. Delphi 2 : 134.0 KB
3. Visual BASIC 4 : 60.9 KB


เขียนโดย : ETT Team
Author : ETT Team
e-mail : sales@etteam.com
วันที่ทำการปรับปรุง : Nov 1, 2000