Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 16.

Similar presentations


Presentation on theme: "Lecture 16."— Presentation transcript:

1 Lecture 16

2 Example: #include<BIOS.H> #include<DOS.H> char ch1, ch2;
void initialize (int pno) { _AH=0; _AL=0x57; _DX=pno; geninterrupt(0x14); }

3 char receivechar (int pno)
{ char ch; _DX = pno; _AH = 2; geninterrupt (0x14); ch = _AL; return ch; }

4 void sendchar (char ch, int pno)
{ _DX = pno; _AH = 1; _AL = ch; geninterrupt (0x14); } unsigned int getcomstatus (int pno) unsigned int temp; _AH = 03; *((char*)(&temp)) = _AL; *(((char*)(&temp)) + 1) = _AH; return temp;

5 void main() { while(1) { i = getcomstatus (0); if (((*(((char*)(&i)) + 1)&0x20) == 0x20) && (kbhit())) ch1 = getche(); sendchar (ch1, 0); } if ((*(((char*)(&i)) +1) & 0x01) == 0x01) { ch2 = receivechar (0); putch (ch2); if ((ch1 == 27) || (ch2 ==27)) break;

6 Line Control Register 7 6 5 4 3 2 1 Word Length 0 Load THR 00 = 5 BITS
Word Length 0 Load THR 1Load Divisor Value 00 = 5 BITS 01 = 6 BITS 10 = 7 BITS 11 = 8 BITS Stop Communication =1 Resume Communication =0 Length of Stop BITS 0 = one BIT 1 =1-5 for 5 bit Word Constant Parity 0 =NO constant Parity 1 =Constant Parity 0 if bit 4 =1 1 if bit 4 =0 Parity Check and generation on Parity O = odd 1 = Even.

7 #include <dos.h>
#include <bios.h> void initialize (unsigned int far *com) { outportb ( (*com)+3, inport ((*com)+3) | 0x80); outportb ( (*com),0x80); outportb( (*com) +1, 0x01); outportb ( (*com)+3, 0x1b); } void SelfTestOn(unsigned int far * com) outportb((*com)+4,inport((*com)+4)|0x10);

8 void SelfTestOff(unsigned int far * com)
{ outportb( (*com)+4, inport((*com)+4) & 0xEf); } void writechar( char ch, unsigned int far * com) while ( !((inportb((*com)+5) & 0x20) == 0x20)); outport(*com,ch); char readchar( unsigned int far *com) while (!((inportb((*com)+5) & 0x01)==0x01)); return inportb(*com);

9 unsigned int far *com=(unsigned int far*) 0x00400000;
void main () { char ch = 0; int i = 1;int j= 1; char ch2='A'; initialize( com); SelfTestOn(com); clrscr(); while (ch!=27) if (i==80) j++; i=0; }

10 if (j==13) j=0; gotoxy(i,j); ch=getche(); writechar(ch,com); ch2=readchar(com); gotoxy(i,j+14); putch(ch2); i++; } SelfTestOff (com);

11 hello how r u ? whats new about systems programming?

12 #include <dos.h>
#include <bios.h> void initialize (unsigned int far *com) { outportb ( (*com)+3, inport ((*com)+3) | 0x80); outportb ( (*com),0x80); outportb( (*com) +1, 0x01); outportb ( (*com)+3, 0x1b); } void SelfTestOn(unsigned int far * com) outportb((*com)+4,inport((*com)+4)|0x18);

13 void SelfTestOff(unsigned int far * com) {
outportb( (*com)+4, inport((*com)+4) & 0xE7); } void writechar( char ch, unsigned int far * com) //while ( !((inportb((*com)+5) & 0x20) == 0x20)); outport(*com,ch); char readchar( unsigned int far *com) //while (!((inportb((*com)+5) & 0x01)==0x01)); return inportb(*com);

14 unsigned int far *com=(unsigned int far*) 0x00400000;
unsigned char far *scr=(unsigned char far*) 0xB ; int i =0,j=0;char ch;int k; void interrupt (*oldint)(); void interrupt newint(); void main () { initialize(com); SelfTestOn(com); oldint = getvect(0x0c); setvect(0x0c,newint); outport((*com)+1,1); outport(0x21,inport(0x21)&0xEF); keep(0,1000); }

15 void interrupt newint()
{ ch= readchar(com); if (i==80) j++; i=0; } if (j==13) j=0; k = i*2+(j+14)*80*2; *(scr+k)=ch; i++; outport(0x20,0x20);

16 C:\>DEBUG -o 3f8 41 -o 3f8 42 -o 3f8 56 -o 3f8 55 -q C:\>

17 #include <bios. h> #include <dos. h> void interrupt (
#include <bios.h> #include <dos.h> void interrupt (*oldint)(); void interrupt newint(); unsigned char far *scr= (unsigned char far *)0xB ; void initialize (unsigned int far *com) { outportb ( (*com)+3, inport ((*com)+3) | 0x80); outportb ( (*com),0x80); outportb( (*com) +1, 0x01); outportb ( (*com)+3, 0x1b); }

18 void main (void) { oldint = getvect(0x0C); setvect (0x0C,newint); initialize (*com); outport ((*com)+4, inport ((*com)+4) | 0x08); outport (0x21,inport (0x21)&0xEF); outport ((*com) + 1, 1); keep(0,1000); } void interrupt newint () { *scr = inport(*com); outport (0x20,0x20);


Download ppt "Lecture 16."

Similar presentations


Ads by Google