What is System Programming? - WordPress.com

coleslawokraΛογισμικό & κατασκευή λογ/κού

1 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

102 εμφανίσεις

System Programming

Lecture
-
10

Hardware Programming

Dated: April
18,
2011


By

Somia

Razzaq






Note: Some slides and images of following lecture are taken from VU

NFC
-
IET
-
2011

Parallel Ports (PPI)

Parallel Communication

Parallel Out Put Device

Output

D0

D7

Strobe

Busy

CPU

D1

D2

Parallel Communication

Parallel Input Device

CPU

D0

I/O

Controller

Input

D7

DR

CPU

D1

D2

Parallel Communication


Faster


Only Economically Feasible For
Small Distances

Programmable Peripheral Interface
(PPI)


Programmable Peripheral Interface (PPI)



Device Used as Parallel port Interface (I/O
controller) is PPI


Programmable Peripheral Interface (PPI)



CPU



PPI


Parallel

I/O Device
Printer

Accessing the Parallel Port Through
BIOS Functions



INT 17H


Services

00

Display Characters

01

Initialize Printer

02

Request Printer

DX
register

Port Interface Number

0=LPT1,1=LPT2,2=LPT3

Accessing the Parallel Port Through
BIOS Functions


All the function Return in AH the Current Printer Status

7

6

5

4

3

2

1

0

Printer Busy

Receive Mode Selected


Out of Paper

Time out

Transfer Error

Printer OffLine

Accessing the Parallel Port Through
BIOS Functions


Time Out Byte

0040:0078

LPT1

0040:0079

LPT2

0040:007A

LPT3

Accessing the Parallel Port
Through BIOS Functions



Specify the number of Attempts BIOS perform
before giving a time out Error


This byte Varies Depending upon the speed of the
PC


Busy =0 Printer is Busy


Busy =1 Printer is not Busy



Importance of the Status
Byte


The status of the printer can be
used in the above described manner
to check if the printer can perform
printing or not

Importance of the Status Byte

If((pstate&0x29)!=0)or
((pstate&0x80)==0) or

((pstate&0x10)==0)

{printerok=FALSE;}

else

{printerok=TRUE;}


Importance of the Status Byte


In case there is a transfer error , the printer is
out of paper or there is a timeout the printer
could not be
accessed or


if the printer is busy
or



if the printer is
offline

Importance of the Status Byte

17H/00H Write

a character on entry

AH=00

AL=ASCII code

DX=Interface#

On exit

AH=Status Byte

17H/01H Initialize Printer

on entry

AH=01

DX=Interface#

On exit

AH=Status Byte

17H/02H Get Printer Status

on entry

AH=02, DX=Interface# On exit AH=Status Byte

Printing Program

Printing Program

REGS regs; FILE *fptr;

void main(void)

{

fptr=fopen(“c:
\
\
temp
\
\
abc.text”,”rb”);

regs.h.ah=1;

regs.x.dx=0;

int86(0x17,&regs,&regs);

while(!feof(fptr))

{regs.h.ah=2;

regs.x.dx=0;


int86(0x17,&regs,&regs);


if ((regs.h.ah & 0x80)==0x80)


{ regs.h.ah=0;


regs.h.al=getc(fptr);


int86(0x17,&regs,&regs);

}}}

#include <dos.h>

void interrupt (*old)( );

void interrupt newint ( );

main( )

{


old = getvect(0x17);


setvect(0x17,newint);


keep(0,1000);

}

void interrupt new ()

{

if (_AH==0)


{



if ((_AL>='A')&&(_AL<='Z'))




return;


}


(*old)();

}

Printing Program 1

#include <dos.h>

void interrupt (*old)( );

void interrupt newfunc ( );

main( )

{


old=getvect(0x17);


setvect(0x17,newfunc);


keep(0,1000);

}

void interrupt newfunc( )

{


if (_AH==0)


{



if ( _AL != ‘ ‘ )


}


(*old)();

}

Printing Program 2

void interrupt (*old)( );

void interrupt newfunc ( );

main()

{

old=getvect(0x17);


setvect(0x17,newfunc);


keep(0,1000);

}

void interrupt newfunc ( )

{

if ( _AH == 0 ) {



(*old)();



_AH=0;



(*old)();



_AH=0;



(*old)();


}


else



(*old)();

}

Printing Program 3

Direct Parallel Port Programming

Direct Parallel Port Programming


BIOS support up to
three parallel ports


Address of these LPT
ports is Stored in BIOS
Data Area



40:08

word

LPT1

40:0A

word

LPT2

40:0C

word

LPT3

40:0E

word

LPT4

Direct Parallel Port Programming

Dump File Text


Direct Parallel Port Programming


unsigned int far * lpt =


(unsigned int far *) 0x00400008 ;

unsigned int temp;

temp=*(lpt);

*lpt=*(lpt + 1);

*(lpt + 1)=temp;

Direct Parallel Port Programming

Port Registers



40:08 store the base address for lpt1


The parallel port interface has 3 ports
internally


If the Base address is 0X378 then the three
Ports will be 0x378,0x379 0x37A


Printer Data Port

7

6

5

4

3

2

1

0

Base +0 = Data Port

Printer Status Register

Busy=0

ACK=0

PE=1

SL=1

ERR=0

0

0

0

Base + 1 = Printer Status

Printer Online

Out of Paper

Printer is ready for Next Character

Printer is Busy


7 6 5 4 3 2 1 0

7

6

5

4

3

2

1

0

0

0

0

IRQ

SI

IN

ALF

ST

Printer Control Register = Base + 2

STROB

Auto

Line

Field

initialize

IRQ ENABLE

SELECT InLine

Turn Computer on line

Printer Control Register

Execute Interrupt

When ACK=0;

Direct Parallel Port Programming


file *
fptr
;

unsigned far *base=(unsigned
int

far *)0x00400008

void main ( )

{

fptr
=
fopen
(“c:
\
\
abc.txt”,”rb
”);

while( !
feof

(
fptr
) )

{ if((
inport

(*base + 1 ) & 0x80) == 0x80) //
printer idle


{


outport
(*base,
getc
(
fptr
));

//to activate strobe signal

outport
((*base)+2,
inport
((*base+2) & 0xFE
);
// strobe signal 0

outport
((*base)+2,
inport
((*base+2) | 0x01
);
//strobe signal 1


}

}}


PIC

Printer

Interface

Printer

IRQ7

INT

ACK
(
now printer is free)

Printer Interface




To enable the interrupt 0x0f three things are
required to be done

1.The interrupt should be enabled in the
printer control register

2. Secondly it should also be unmasked in the
IMR in PIC

3.The program can then intercept or set the
vector of interrupt 0x0f by placing the address
of its function
newint
();




Interrupt Driven Printer I/O


char
buf

[1024];
int

i

= 0;

void interrupt (*
oldint
)( );

void interrupt
newint

();

void main (void)

{

outport
(( *
lpt
),
inport
( *
lpt
) | 4);
//printer is initialized

outport
(( *
lpt
),
inport
( *
lpt
) | 0x10);
//here printer
interrupt
is initialized

oldint

=
getvect

(0x0F);

setvect

(0x0F,
newint
);

outport
(0x21,
inport
( 0x21) & 0x7F);

keep(0,1000);

}


void interrupt
newint

( )

{

outport
( *
lpt
,
Buf
[
i
]);

outport
(( *
lpt
)+2,
inport
(( *
lpt
)+2) &0xFE);

outport
(( *
lpt
)+2,
inport
(( *
lpt
)+2) | 1);

i
++;


if(
i
== 1024)


{

// in PIC mask register address is 0x21 and 0x80 is used to unmask the IRQ7. It means
interrupt through IRQ7 can be generated


outport
(0x21
,
inport
(0x21)|0x80);


setvect
(0x0F,oldint);


freemem
(_
psp
); //
program Segment Prefix macro


}

}


//Program to take print at background

#include <
stdio.h
>

#include <
dos.h
>

#include <
bios.h
>

#include <
conio.h
>

#include <
stdlib.h
>

void interrupt (*
oldint
)();

void interrupt
newint
();

unsigned
int

far *
lpt

= (unsigned
int

far *)0x00400008;

char
st
[80]= "this is a test print string !!!!!!!!!!!";

int

i

;

void main ()

{


oldint

=
getvect
(0x08);


setvect
(0x08,newint);


keep(0,1000);

}


void interrupt
newint
()

{


if (((
inport
((*
lpt
) +1)) & 0x80) == 0x80)


{



outport

(*
lpt,st
[
i
++]);



outport

((*
lpt
)+2,
inport
((*
lpt
)+2) & 0xfe);



outport

((*
lpt
)+2,
inport
((*
lpt
)+2) | 1);


}


if (
i
==32)


{



setvect

(0x08,oldint);



freemem
(_
psp
);


}


(*
oldint
) ();

}


Printer Cable Connectivity

1

STROB

2

D0

3

D1

4

D2

5

D3

6

D4

7

D5

8

D6

9

D7

10

ACK

11

BUSY

12

PE

13

SLCT

14

AUTO FEED

15

ERROR

16

INIT

17

SLCT IN

18
-
25

GND

Computer to Computer Connectivity

P0 2 15 Q3

P1 3 13 Q4

P2 4 12 Q5

P3 5 10 Q6

P4 6 11 Q7


Q3 15 2 P0

Q4 13 3 P1

Q5 12 4 P2

Q6 10 5 P3

Q7 11 6 P4

1

B3

B2

B1

B0

0

B3

B2

B1

B0

Sender

Receiver

BUSY ACK PE SLC ER


D4 D3 D2 D1 D0


E7 E6 E5 E4 E3

Sender sends
LOW Nibble
and D4 = 0

received as
BUSY = 1

0

B3

B2

B1

B0

1

B3

B2

B1

B0

Sender

Receiver

BUSY ACK PE SLC ER


D4 D3 D2 D1 D0

Receiver send
back LOW
Nibble and D4=0

received as
BUSY = 1 by
Sender

0

B7

B6

B5

B4

1

B7

B6

B5

B4

Sender

Receiver

BUSY ACK PE SLC ER


D4 D3 D2 D1 D0

Sender sends Hi
Nibble and turns
D4 = 1 received
as BUSY = 0 by
Receiver

1

B7

B6

B5

B4

0

B7

B6

B5

B4

Sender

Receiver

BUSY ACK PE SLC ER


D4 D3 D2 D1 D0

Receiver send
back Hi Nibble
and turns

D4 = 1 received
as BUSY = 0 by
Sender