Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » TSR ProgrammingRSS Feeds

Program to Print English Alphabets from Printer using Interrupts

Posted By: Easy Tutor     Category: C Programming     Views: 3968

Write a Program to Print English Alphabets from Printer using Interrupts.

Code for Program to Print English Alphabets from Printer using Interrupts in C Programming

 # include <stdio.h>
 # include <conio.h>
 # include   <dos.h>

 unsigned char InitPrinter(int iPortNumber);
 unsigned char PrintCharacter(int iPortNumber,char cCharacter);
 unsigned char GetStatus(int iPortNumber);

 void ShowStatus(unsigned char ucStatus);

 int main( )
 {
    int iPortNumber=0;
    unsigned char ucStatus=0x00;
    char cEnglishAlphabet='A';

    clrscr( );

    ucStatus=InitPrinter(iPortNumber);
    ShowStatus(ucStatus);

    if((ucStatus&0x80)==0x80 && (ucStatus&0x10)==0x10)
    {
       printf("\nStarting Printing...\n\n");

       while(cEnglishAlphabet<='Z')
       {
      ucStatus=PrintCharacter(iPortNumber,cEnglishAlphabet);

      printf("%c",cEnglishAlphabet);

      cEnglishAlphabet++;
       }

       if(cEnglishAlphabet==91)
      printf("\n\nPrinting Completed.");

       else
       {
      printf("\nPrinting Terminated due to an Error\n");

      ShowStatus(ucStatus);
       }
    }

    getch( );
    return 0;
 }

 /*************************************************************************//*************************************************************************///------------------------  Funcion Definitions  ------------------------///*************************************************************************//*************************************************************************//*************************************************************************///-----------------------------  InitPrinter( )  ---------------------------///*************************************************************************/

 unsigned char InitPrinter(int iPortNumber)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.h.ah=0x01;
    InReg.x.dx=iPortNumber;

    int86(0x17,&InReg,&OutReg);

    return OutReg.h.ah;
 }

 /*************************************************************************///--------------------------  PrintCharacter( )  -------------------------///*************************************************************************/

 unsigned char PrintCharacter(int iPortNumber,char cCharacter)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.h.ah=0x00;
    InReg.h.al=cCharacter;
    InReg.x.dx=iPortNumber;

    int86(0x17,&InReg,&OutReg);

    return OutReg.h.ah;
 }

 /*************************************************************************///----------------------------  GetStatus( )  ---------------------------///*************************************************************************/

 unsigned char GetStatus(int iPortNumber)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.h.ah=0x02;
    InReg.x.dx=iPortNumber;

    int86(0x17,&InReg,&OutReg);

    return OutReg.h.ah;
 }

 /*************************************************************************///---------------------------  ShowStatus( )  ---------------------------///*************************************************************************/void ShowStatus(unsigned char ucStatus)
 {
    printf("Printer Status ::\n");

    if((ucStatus&0x80)==0x80)
       printf("- Printer Not Busy\n");

    if((ucStatus&0x40)==0x40)
       printf("- Acknowledgement from Printer\n");

    if((ucStatus&0x20)==0x20)
       printf("- Out of Paper\n");

    if((ucStatus&0x10)==0x10)
       printf("- Printer Selected\n");

    if((ucStatus&0x08)==0x08)
       printf("- I/O Error\n");

    if((ucStatus&0x01)==0x01)
       printf("- Time-Out Error\n");
 }
  
Share: 



Easy Tutor
Easy Tutor author of Program to Print English Alphabets from Printer using Interrupts is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!