?? parrell_port.cpp
字號:
#include <sys/io.h>#include <sys/ioctl.h>#include <termios.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <pthread.h>//#include < sched.h>#include <signal.h>#include <sys/types.h>#include <time.h>pthread_mutex_t mutex;struct timespec delay;void *TimerOpenThread(void * arg){ while(1) { pthread_mutex_lock(&mutex); unsigned char nstate_out = 0x04; outb(0x04,0x37a); unsigned char a =(nstate_out&&0x80)*5; printf("the NO 16 is %d v \n ",a); pthread_mutex_unlock(&mutex); //pthread_delay_np(&delay); delay.tv_sec=5; delay.tv_nsec=0; nanosleep(&delay,NULL); sleep(5); } }void Timer_Close(){ while(1){ pthread_mutex_lock(&mutex); unsigned char nstate_out = 0x0; outb(0x0,0x37a); unsigned char a =(nstate_out&&0x80)*5; printf("the NO 16 is %d v \n ",a); pthread_mutex_unlock(&mutex); //pthread_delay_np(&delay); delay.tv_sec=5; delay.tv_nsec=0; nanosleep(&delay,NULL); sleep(3); } } int main(void){ unsigned char nstate = 0; unsigned char nstate_out = 0; iopl(3);//open all the port ///// pthread_t tid_open; pthread_attr_t attr; pthread_attr_init( &attr ); pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); //delay.tv_sec = 2 ; //delay.tv_nsec = 0 ; //default to init mutex object pthread_mutex_init(&mutex,NULL); pthread_create(&tid_open,&attr,TimerOpenThread,(void *)0); Timer_Close(); ///// //while(1) { nstate = inb(0x379); if( nstate&&0x40 == 0) { printf("the input value is zero\n"); } } return 0; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -