Code:
#include <mega16.h> #include <delay.h> #define ADC_VREF_TYPE 0x00 unsigned int read_adc(unsigned char adc_input) {ADMUX=adc_input|ADC_VREF_TYPE; ADCSRA=0x40; //01000000 ADSC=1 duoc giu trong suot qua trinh chuyen doi while((ADCSRA&0x10)==0) ADCSRA|=0X10; return ADCW; } void main(void) {unsigned i=0; DDRA=0x00; PORTA=0x00; DDRB=0XFF; PORTB=0X00; DDRD=0XFF; PORTD=0X00; ADMUX=ADC_VREF_TYPE; ADCSRA=0X87; //10000111 he so chia xung nhip den bo adc la 128,ADEN=1 adc duoc sd while(1) {i=read_adc(0); PORTB=i&0xff; PORTD=i>>8; delay_ms(500); } }
Comment