Gunakan MimeTex/LaTex untuk menulis simbol dan persamaan matematika.

Welcome to Forum Sains Indonesia. Please login or sign up.

Maret 28, 2024, 09:33:44 PM

Login with username, password and session length

Topik Baru

Artikel Sains

Anggota
Stats
  • Total Tulisan: 139,653
  • Total Topik: 10,405
  • Online today: 116
  • Online ever: 1,582
  • (Desember 22, 2022, 06:39:12 AM)
Pengguna Online
Users: 0
Guests: 91
Total: 91

Aku Cinta ForSa

ForSa on FB ForSa on Twitter

tanya tentang adc atmega8535 pake codevision avr

Dimulai oleh aldemilano, Januari 18, 2011, 02:37:31 PM

« sebelumnya - berikutnya »

0 Anggota dan 1 Pengunjung sedang melihat topik ini.

aldemilano

selamat sore semua....mau minta bantuan nih buat listing program konversi tegangan adc ke biner 10 bit atmega8535 menggunakan codevision avr..terimakasih...

N.A.T.O

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);

      };
}

deny

numpang ya,,,

ada yang pny tutorial code visio AVR buat pemula gag??
bru pgn belajar neh,,

N.A.T.O

lihat di blog ini aja gan:
electrocontrol.wordpress.com

deny


spartakook

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