Interfacing DAC0808 dengan ATMEGA8535
http://downloads.ziddu.com/download/23827531/DAC0808.rar.html
listing programnya:
#include <mega8535.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x60
// Read the 8 most significant bits
// of the AD conversion result
unsigned char 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 ADCH;}
// Declare your global variables here
void main(void){
PORTB=0x00;
DDRB=0xFF;
PORTC=0x00;
DDRC=0xFF;
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: ADC Stopped
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
SFIOR&=0xEF;
while (1){
PORTB = read_adc(0);
PORTC = read_adc(1);}}
//end program----------
http://downloads.ziddu.com/download/23827531/DAC0808.rar.html
listing programnya:
#include <mega8535.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x60
// Read the 8 most significant bits
// of the AD conversion result
unsigned char 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 ADCH;}
// Declare your global variables here
void main(void){
PORTB=0x00;
DDRB=0xFF;
PORTC=0x00;
DDRC=0xFF;
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: ADC Stopped
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
SFIOR&=0xEF;
while (1){
PORTB = read_adc(0);
PORTC = read_adc(1);}}
//end program----------
INTERRUPT TIMER 1 DENGAN ATMEGA 8535
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.9 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 10/06/2014
Author : BAKHTIAR
Company : CUNDA
Comments:
Chip type : ATmega8535
Program type : Application
AVR Core Clock frequency: 12,000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 128
*****************************************************/
#include <mega8535.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>
#include <mega8535.h>
#include <stdio.h>
unsigned char buff[30];
unsigned long detik;
// sub rutin saat terjadi interrupt Timer 1
interrupt [TIM1_OVF] void timer1_ovf_isr(void){
TCNT1H=0x48;
TCNT1L=0xe5;
detik++;
lcd_clear();
sprintf(buff,"detik %d",detik);
lcd_puts(buff);}
void main(void){
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: kHz
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x04;
TCNT1H=0xC2;
TCNT1L=0xF7;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
SFIOR=0x00;
// LCD module initialization
lcd_init(16);
// Global enable interrupts
#asm("sei")
lcd_putsf("Tiar menunggu...");
while (1){};}
//end program
Lengkap simulasi download aja di http://www.4shared.com/rar/DbpDHG5_ce/interrups.html?
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.9 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 10/06/2014
Author : BAKHTIAR
Company : CUNDA
Comments:
Chip type : ATmega8535
Program type : Application
AVR Core Clock frequency: 12,000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 128
*****************************************************/
#include <mega8535.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>
#include <mega8535.h>
#include <stdio.h>
unsigned char buff[30];
unsigned long detik;
// sub rutin saat terjadi interrupt Timer 1
interrupt [TIM1_OVF] void timer1_ovf_isr(void){
TCNT1H=0x48;
TCNT1L=0xe5;
detik++;
lcd_clear();
sprintf(buff,"detik %d",detik);
lcd_puts(buff);}
void main(void){
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: kHz
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x04;
TCNT1H=0xC2;
TCNT1L=0xF7;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
SFIOR=0x00;
// LCD module initialization
lcd_init(16);
// Global enable interrupts
#asm("sei")
lcd_putsf("Tiar menunggu...");
while (1){};}
//end program
Lengkap simulasi download aja di http://www.4shared.com/rar/DbpDHG5_ce/interrups.html?
Perbedaan dari Timer 8 bit dengan 16 bit?
- Timer 8 bit yakni pada Timer0 dan Timer2, sesuai
dengan namanya timer 8 bit yakni timer yang dapat mencacah dari 0 - 255
atau 0x00 - 0xFF.
- Timer 16 bit yakni pada Timer1, sesuai dengan
namanya timer 16 bit yakni timer yang dapat mencacah dari 0 - 65535 atau
0x0000 - 0xFFFF.
Jika
kita ingin menggunakan prescaller 256 maka nilai TCCR1B = 0x04.
- Sedangkan
TCNT1H dan TCNT1L adalah besarnya nilai timer yang akan kita gunakan.
Untuk perhitungan pada Timer 1 yakni
TCNT
= (1+0xFFFF) - (waktu *( XTAL / prescaler) )
waktu
= waktu yg kita inginkan
XTAL = frekuensi xtal yg dipakai
prescaler = nilai prescaler
XTAL = frekuensi xtal yg dipakai
prescaler = nilai prescaler
Perhatikan pada nilai
TCNT1A dan TCNT1B serta TCCR0B.
karena kita akan
membuat timer 1 bekerja pada 1 detik dengan XTAL 12MHz maka
perhitungannya
TCNT
= (1+0xFFFF) - (1 *( 12000000 /256) )
Jika kita hitung maka
nilai TCNT = 0x48E5, sehingga TCNT1H = 0x48 dan TCNT1L = 0xE5dan karena
menggunakan prescaller 256 maka nilai TCCR1B = 0x04.
bagaimana prinsip kerjanya pak ?
BalasHapus