Page 166 - C Programming
P. 166

ตัวอย่างที่12-6      โปรแกรมตรวจสอบการกดสวิตซ์ถ้าสวิตซ์ใดถูกกดให้มีค่าเป็น 1 และ

                                    สวิตซ์ใดไม่ถูกกดจะมีค่าเป็น 0  โดยทําการตรวจสอบการกดแบบบิต




        #include<stdio.h>

        main()


            {  char psw,sw[5];


                gotoxy(30,11); printf("Program Check switch 5 bit");

                       do{  psw = inport(0x379);


                        psw = ~psw; /*inverse bit */

                        sw[0] = (psw & 0x40)/0x40;


                        sw[1] = !((psw & 0x80)/0x80);


                        sw[2] = (psw & 0x20)/0x20;

                        sw[3] = (psw & 0x10)/0x10;


                        sw[4] = (psw & 0x08)/0x08;

                        gotoxy(38,13); printf("%d %d %d %d %d",sw[0],sw[1],sw[2],sw[3],sw[4]);


                        delay(200);


                     }while(!kbhit());

             }
   161   162   163   164   165   166   167   168   169   170   171