Delpi10
Newbie level 6
Hi everyone, i need to reed values from tree different ADC ports ,and i dont know how to do it,i'm quit stuck .
I know how to read from one port, but when it comes to read from more ports, i dont know how to set it.
this is the code i made until now :
Can anyone help?
Sorry for the bad English.
I know how to read from one port, but when it comes to read from more ports, i dont know how to set it.
this is the code i made until now :
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 #define F_CPU 1000000 // #include "lcd.h"// LCD library #include <stdio.h> #include <stdlib.h> #include <avr/io.h> #include <util/delay.h> #include<avr/interrupt.h> unsigned char leitura_AD_1,leitura_AD_2,leitura_AD_3,flag=0; void inic_hardware(void); void inic_hardware(void) { DDRC = 0b00000001; // Port D pin 0 ouput DDRB = 0b00001000; DDRC = 0b11100000; PORTD= 0b00000010; SREG=0b10000000; // INT GLOBAL TCCR2A=0b10000011; // Fast PWM, Clear OC2A on Compare Match TCCR2B=0b00000010; } char ler_AD(void) { ADMUX=0b00100000; ADCSRA=0b11001011; //Inicia a conversão if(flag==1) { while(ADCSRA==0b11001011); //Espera o fim da conversão } return(leitura_AD_1); flag=2; ler_AD1(); } char ler_AD_1(void) { ADMUX=0b00100001; ADCSRA=0b11001011; //start the conv if(flag==2) { while(ADCSRA==0b11001011); //wait until the end of the conv } return(leitura_AD_2); flag=0; } ISR(ADC_vect) { flag=1; leitura_AD_1=ADCH; //Leitura de 8 bits leitura_AD_2=ADCH; //leitura_AD_3=ADCH; } int main(void) { //inicializacao do hardware. int a=0,b=0,v_caudal=0; //unsigned char sw=0; // variavel para o switch inic_hardware(); // inicializa o hardware lcd_init(LCD_DISP_ON); // inicializa o display lcd_clrscr(); // limpa o ecra sw=PORTD&0b00000000; // define o botão switch que corresponde ao PORTD pino 2 char buffer[30]; // buffer para utilizar no envio de msg para o LCD while(1) // ciclo infinito { a=ler_AD(); b=ler_AD_1(); OCR2A=a; OCR1B=b; v_caudal=a; //OCR2A=140; // coloca o OCR2A a 0,o que faz com que o LED esteja desligado lcd_gotoxy(0,0); // faz com que os caracteces sejam escritos na primeira posição do LCD lcd_puts("Volcaudal:"); lcd_gotoxy(16,0); lcd_puts(" l\s "); lcd_gotoxy(11,0); // faz com que os carateres sejam escritos na linha de baixo sprintf(buffer,"%d",v_caudal); lcd_puts(buffer); } }
Can anyone help?
Sorry for the bad English.
Last edited by a moderator: