8255a_2.cpp

来自「在纯DOS下运行的TurboC3_ucos2_ucgui bug改进版本」· C++ 代码 · 共 100 行

CPP
100
字号
/*   8255a_2.c
   display red light, green light  and flashing
  HD 97413083   YanGuangMing
*/

#include "interfac.h"
#include "stdio.h"
#include "conio.h"
void main()
 {  int inbyte,i;
    printf("press any key to start 8255a_2.\n");
    getch();
    inbyte=0x80;         /* 1000 0000 */
    outp(port_8255A,inbyte);
    printf("South red ,East  red , North red , West red.\n");
    inbyte=0x01;       /* 0 000 000 1 */
    outp(port_8255A,inbyte);
    inbyte=0x03;       /* 0 000 001 1 */
    outp(port_8255A,inbyte);
    inbyte=0x05;       /* 0 000 010 1 */
    outp(port_8255A,inbyte);
    inbyte=0x07;       /* 0 000 011 1 */
    outp(port_8255A,inbyte);
    sleep(3);
    printf(" any key to exit to dos . \n");
    while(!kbhit())
    {
	printf(" South green on, Nouth green on.\n");
        inbyte=0x09; /* 0 000 100 1 */
        outp(port_8255A,inbyte);
        inbyte=0x0d;    /* 0 000 110 1 */
        outp(port_8255A,inbyte);
	sleep(3);

	printf(" South green off, Nouth green off .\n");
        inbyte=0x08; /* 0 000 100 0 */
        outp(port_8255A,inbyte);
        inbyte=0x0c;    /* 0 000 110 0 */
        outp(port_8255A,inbyte);

         /* yellow light flash 8 times */
        for(i=0;i<8;i++)
          {  outp(port_B_of_8255A,0x50);
             delay(100);
             outp(port_B_of_8255A,0x0);
             delay(100);
         }

    printf("South red ,East  red , North red , West red.\n");
    inbyte=0x01;       /* 0 000 000 1 */
    outp(port_8255A,inbyte);
    inbyte=0x03;       /* 0 000 001 1 */
    outp(port_8255A,inbyte);
    inbyte=0x05;       /* 0 000 010 1 */
    outp(port_8255A,inbyte);
    inbyte=0x07;       /* 0 000 011 1 */
    outp(port_8255A,inbyte);
    sleep(3);

	printf(" East green on, West green on.\n");
        inbyte=0x0b; /* 0 000 101 1 */
        outp(port_8255A,inbyte);
        inbyte=0x0f;    /* 0 000 111 1 */
        outp(port_8255A,inbyte);
	sleep(3);

	printf(" East green off, West green off.\n");
        inbyte=0x0a; /* 0 000 101 0 */
        outp(port_8255A,inbyte);
        inbyte=0x0e;    /* 0 000 111 0 */
        outp(port_8255A,inbyte);
	sleep(3);

        /* yellow light flash 8 times */
        for(i=0;i<8;i++)
          {  outp(port_B_of_8255A,0x50);
             delay(100);
             outp(port_B_of_8255A,0x0);
             delay(100);
         }

    printf("South red ,East  red , North red , West red.\n");
    inbyte=0x01;       /* 0 000 000 1 */
    outp(port_8255A,inbyte);
    inbyte=0x03;       /* 0 000 001 1 */
    outp(port_8255A,inbyte);
    inbyte=0x05;       /* 0 000 010 1 */
    outp(port_8255A,inbyte);
    inbyte=0x07;       /* 0 000 011 1 */
    outp(port_8255A,inbyte);
    sleep(3);

 }

}




⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?