rendered paste body/*------------------- ADC_driver ----------------------------------- PURPOSE - Gives one sensor reading COMPILE to binary st as below- gcc -o run_ADC ADC_driver_rev4.c RUN ./lp_tty_start ./ADC_driver_rev4*///#include <asm/io.h>#include <sys/io.h>#include <sys/time.h>#include <stdio.h>#include <stdlib.h>//------- Parallel port data.static short lp_base_addr;#define status_offset 1#define control_offset 2#define high 1#define low 0//-------Parallel port pins-------------------------#define CS 0x02 //pin 3#define CLK 0x01 //pin 2#define all_low 0x00static char save_data ; // save of original values.static char save_control ;static char image_data ; // use image as master record of port.static char image_control ;int DOUT = 0;short cycle = 0;// init du port parallèlevoid lp_init() { printf("lp_init()\n"); lp_base_addr = 0x378 ; image_data = save_data = inb( lp_base_addr) ; image_control = save_control = inb( lp_base_addr+2) ; outb( (image_control &= 0xEF), lp_base_addr + control_offset) ; }// restore du port parallèlevoid lp_restore(){ printf("lp_restore()\n"); outb( save_data, lp_base_addr) ; outb( save_control, lp_base_addr + control_offset);}int horloge(char lecture){ printf("horloge()\n"); short clk = 0; outb(all_low, lp_base_addr); // tout à 0 if(lecture == 0); { for(clk=1; clk<=8; clk++) { outb(0, lp_base_addr); outb(CLK, lp_base_addr); // printf("clk %d\n", clk); } } else if(lecture == 1); { for(clk=1; clk<=8; clk++) { outb(0, lp_base_addr); outb(CLK, lp_base_addr); // printf("clk %d\n", clk); } } else { return(0); } outb(CS, lp_base_addr); // CS à 1 usleep(500000); // attente de 500000µs (500ms) outb(0, lp_base_addr); //CS à 0}/*void horloge_lecture(){ printf("horloge()\n"); short clk = 0; outb(all_low, lp_base_addr); // tout à 0 for(cycle=1; cycle <=2; cycle++) { outb(CS, lp_base_addr); // CS à 1 // sleep(1); //attente de 1s usleep(500000); // attente de 500000µs (500ms) outb(0, lp_base_addr); //CS à 0 for(clk=1; clk<=8; clk++) { outb(0, lp_base_addr); outb(CLK, lp_base_addr); // printf("clk %d\n", clk); } printf("fin du cycle d\'horloge %d\n", cycle); outb(CS, lp_base_addr); // CS à 1 usleep(500000); // attente de 500000µs (500ms) outb(0, lp_base_addr); //CS à 0 horloge_clk(0); // cycle d'horloge horloge_clk(1); // horloge + lecture }}*//*int lecture(){ printf("lecture()\n"); ordre[8] ={6,5,4,3,2,1,0,7}; return(DOUT);}*/void affichage(){ printf("affichage()\n"); if(DOUT != 4095) { printf("Tension: %d\n", DOUT); } else printf("Lecture impossible\n"); usleep(500000);}int main(){ lp_init(); //init du port parallèle short i = 0; for(i=0; i<1; i++) { //horloge_lecture(); horloge_clk(0); // cycle d'horloge horloge_clk(1); // horloge + lecture } affichage();// lp_restore(); // restauration du port parallèle return(0);}