By | 17/02/2018

Hello Sahabat Anak Kendali.

pada kesempatan kali ini saya akan menulis tentang Cara mengakses ADC dengan CVAVR dan kali ini saya juga menggunakan Multiplexer sehingga hanya membutuhkan PIN mikrokontrollernya lebih sedikit atau lebih hemat, jadi multiplexer adalah IC yang memiliki input banyak dan outputnya lebih sedikit sedangkan demuxtiplexer kebalikanya, Input lebih sedikit dibanding Outputnya.

langsung saja ini dia gambar rangkainya,

Cara Membaca ADC CVAVR Atmega Multiplexer

bagi yang belum download ISIS 7 nya bisa di download pada postingan sebelumnya disini

baiklah selanjutnya buka dulu CVAVR nya, jangan lupa untuk inisialisasi PORT,
dan pengaturan LCD nya juga !

ini gambar bekas coding ane sendiri.

Cara Membaca ADC CVAVR Atmega Multiplexer

 oke selanjutnya membuat program dengan CVAVR saya ingatin lagi jangan COPY PASTE tulis ulang supaya terbiasa membuat PROGRAM !

ini dia program nya !

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date    : 21/02/2017
Author  : Chaerul Anam
Company : Unisi Robotik
Comments:

Chip type               : ATmega16
Program type            : Application
AVR Core Clock frequency: 8,000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

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

// Alphanumeric LCD functions
#include <alcd.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
int mux[8];
char data [8];

#define sel1 PORTA.5
#define sel2 PORTA.6
#define sel3 PORTA.7

void selector(int c, int b, int a) {
  sel1= a;
  sel2= b;
  sel3= c;
}

void baca_adc() {
selector (0,0,0);
mux[0] = read_adc (0);
selector (0,0,1);
mux[1] = read_adc (0);
selector (0,1,0);
mux[2] = read_adc (0);
selector (0,1,1);
mux[3] = read_adc (0);
selector (1,0,0);
mux[4] = read_adc (0);
selector (1,0,1);
mux[5] = read_adc (0);
selector (1,1,0);
mux[6] = read_adc (0);
selector (1,1,1);
mux[7] = read_adc (0);

   }
  
   void tampil (){
   baca_adc (); 
   lcd_clear (); 
  lcd_gotoxy (0,0);
  sprintf (data, “%d”, mux[0]);
  lcd_puts (data); 
  lcd_gotoxy (4,0);
  sprintf (data, “%d”, mux[1]);
  lcd_puts (data);
  lcd_gotoxy (8,0);
  sprintf (data, “%d”, mux[2]);
  lcd_puts (data); 
  lcd_gotoxy (12,0);
  sprintf (data, “%d”, mux[3]);
  lcd_puts (data); 
  lcd_gotoxy (0,1);
  sprintf (data, “%d”, mux[4]);
  lcd_puts (data);
  lcd_gotoxy (4,1);
  sprintf (data, “%d”, mux[5]);
  lcd_puts (data); 
   lcd_gotoxy (8,1);
  sprintf (data, “%d”, mux[6]);
  lcd_puts (data);
    lcd_gotoxy (12,1);
  sprintf (data, “%d”, mux[7]);
  lcd_puts (data);
   delay_ms (100);

                  }

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

// Input/Output Ports initialization
// Port A initialization
// Func7=Out Func6=Out Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=1 State6=1 State5=1 State4=T State3=T State2=T State1=T State0=T
PORTA=0xE0;
DDRA=0xE0;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

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

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 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: Timer2 Stopped
// Mode: Normal top=0xFF
// 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
// USART disabled
UCSRB=0x00;

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

// ADC initialization
// ADC Clock frequency: 1000,000 kHz
// ADC Voltage Reference: AVCC pin
// ADC Auto Trigger Source: ADC Stopped
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS – PORTC Bit 0
// RD – PORTC Bit 1
// EN – PORTC Bit 2
// D4 – PORTC Bit 4
// D5 – PORTC Bit 5
// D6 – PORTC Bit 6
// D7 – PORTC Bit 7
// Characters/line: 16
lcd_init(16);

while (1)
      {
      // Place your code here
         tampil();
      }
}

mungkin cukup sekian artikel kali ini, kurang lebihnya mohon maaf, semoga bermanfaat !

keyword:
cara mengakses Multiplexer dengan CVAVR
mengakses IC 4051 dengan CVAVR
cara membaca adc atmega
membaca adc cvavr
multiplexer cvavr
multiplexer atmega
anak kendali

Leave a Reply

Your email address will not be published. Required fields are marked *