faraz101
Full Member level 1
- Joined
- Mar 7, 2007
- Messages
- 96
- Helped
- 7
- Reputation
- 14
- Reaction score
- 5
- Trophy points
- 1,288
- Activity points
- 1,872
#include "16f877.h"
#device ADC=8
#use delay(clock=4000000)
#use fast_io(B)
void main(void)
{
set_tris_b(0);
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(5);
while(1)
{
output_b(read_adc()); //read data
delay_us(20);
}
}
void main() {
float volt,press,calc,adc_value;
char inter, deci;
ADCON1 = 0x80; // Configure analog inputs and Vref
TRISA = 0xFF; // PORTA is input
TRISB = 0x3F; // Pins RB7, RB6 are outputs
TRISD = 0; // PORTD is output
usart_init(2400);
do {
adc_value = Adc_Read(2); // Get results of AD conversion
press = adc_value*0.005;
inter = (int) press;
deci= (int) (press*10.0) - inter*10;
usart_write('V');
usart_write('O');
usart_write('L');
usart_write('T');
usart_write('=');
usart_write(inter | 0x30);
usart_write('.');
usart_write(deci | 0x30);
usart_write(13);
usart_write(10);
delay_ms(1000);
} while(1);
}
'mikroBASIC:
dim ADR as word
ADR = ADC_Read(0) 'Read from channel 0 and copy digital value to ADR
'mikroC:
unsigned int word;
ADR = ADC_Read(0);
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?