All pastes #994401 Raw Edit

manx86

public c v1 · immutable
#994401 ·published 2008-04-23 11:45 UTC
rendered paste body
/*------------------- ADC_driver -----------------------------------  PURPOSE - Gives ten sensor readings over 10 seconds.    COMPILE to binary st as below-            gcc -o run_ADC ADC_driver_rev3.c  RUN       ./lp_tty_start ./ADC_driver_rev3*/#include <asm/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;// 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);}void horloge(){	printf("horloge()\n");	short count = 0;	outb(all_low, lp_base_addr); // tout à 0	outb(CS, lp_base_addr); // CS à 1	sleep(1);	outb(0, lp_base_addr); //CS à 0	for(count=1; count<=8; count++)	{	  outb(0, lp_base_addr);	  outb(CLK, lp_base_addr);	}}int lecture(){	printf("lecture()\n");	return(DOUT);}void affichage(){	printf("affichage()\n");	if(DOUT != 4095)	{	  printf("Tension: %d\n", DOUT);	}	else	printf("Lecture impossible\n");	sleep(1);}int main(){	lp_init(); //init du port parallèle	short i = 0;	for(i=0; i<2; i++)	{		horloge();	}	lecture(); //	affichage();//	lp_restore(); // restauration du port parallèle	return(0);}