Forum Sains Indonesia

Ilmu Terapan => Ilmu Teknik => Teknik Elektro => Topik dimulai oleh: aldemilano pada Januari 19, 2011, 05:37:31 AM

Judul: tanya tentang adc atmega8535 pake codevision avr
Ditulis oleh: aldemilano pada Januari 19, 2011, 05:37:31 AM
selamat sore semua....mau minta bantuan nih buat listing program konversi tegangan adc ke biner 10 bit atmega8535 menggunakan codevision avr..terimakasih...
Judul: Re: tanya tentang adc atmega8535 pake codevision avr
Ditulis oleh: N.A.T.O pada April 12, 2011, 02:33:14 PM
float nilai_ADC;
 char temp[16];

#include <mega8535.h>
#include <stdlib.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>


#include <stdio.h>
#include <delay.h>

#define ADC_VREF_TYPE 0x40

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}

// Declare your global variables here

void main(void)
{
// Declare your local variables here


PORTA=0x00;
DDRA=0x00;


PORTB=0x00;
DDRB=0x00;

PORTC=0x00;
DDRC=0x00;

 
PORTD=0x00;
DDRD=0xff;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x4D;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 750.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
SFIOR&=0xEF;

// LCD module initialization
lcd_init(16);

while (1)
      {
        nilai_ADC= read_adc(0);

        lcd_clear();
   lcd_gotoxy(0,0);
        ftoa(nilai_ADC,0,temp);
        lcd_puts(temp);
   delay_ms(500);

      };
}
Judul: Re: tanya tentang adc atmega8535 pake codevision avr
Ditulis oleh: deny pada Mei 20, 2011, 09:39:55 AM
numpang ya,,,

ada yang pny tutorial code visio AVR buat pemula gag??
bru pgn belajar neh,,
Judul: Re: tanya tentang adc atmega8535 pake codevision avr
Ditulis oleh: N.A.T.O pada Juni 02, 2011, 03:32:01 AM
lihat di blog ini aja gan:
electrocontrol.wordpress.com
Judul: Re: tanya tentang adc atmega8535 pake codevision avr
Ditulis oleh: deny pada Juni 12, 2011, 01:32:42 AM
terimaksih mas,,,,,
Judul: Re: tanya tentang adc atmega8535 pake codevision avr
Ditulis oleh: spartakook pada Oktober 26, 2011, 05:10:45 AM
saya mencoba program yang N.A.T.O berikan.,
namun sebelum mikro saya beri tegangan dari luar.,
pada LCD sudah ada angka yang muncul seperti 154,257,341 dsb.,
mengapa hal tsb terjadi ya??
mohon pencerahannya

thanks b4