با سلام برنامه ای نوشتم که میخوام هر 1 یک دقیق یکبار ورودی adc0 رو بخونه که همون vkey هست اما برنامه کار نمیکنه ممنون میشم راهنمایی کنید :
#include <mega16.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
float vkey;
// Timer1 overflow interrupt service routine
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
vkey=read_adc(0);
vkey=(vkey*5)/1024;
}
void main(void)
{
TCCR1A=0x00;
TCCR1B=0x05;
TCNT1H=0x1B;
TCNT1L=0x1E;
DDRB.0=1;
DDRB.1=1;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 15.625 kHz
// ADC Voltage Reference: AVCC pin
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x86;
// Global enable interrupts
#asm("sei"
while (1)
{
TCCR1B=0x05;
vkey=(vkey*5)/1024;
if(vkey<1.80)
{
PORTB.0=1;
PORTB.1=0;
}
else if(vkey>3.5)
{
PORTB.0=0;
PORTB.1=1;
}
};
}
اضافه شده در تاریخ :
لطفا راهنمایی کنید .
#include <mega16.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
float vkey;
// Timer1 overflow interrupt service routine
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
vkey=read_adc(0);
vkey=(vkey*5)/1024;
}
void main(void)
{
TCCR1A=0x00;
TCCR1B=0x05;
TCNT1H=0x1B;
TCNT1L=0x1E;
DDRB.0=1;
DDRB.1=1;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 15.625 kHz
// ADC Voltage Reference: AVCC pin
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x86;
// Global enable interrupts
#asm("sei"

while (1)
{
TCCR1B=0x05;
vkey=(vkey*5)/1024;
if(vkey<1.80)
{
PORTB.0=1;
PORTB.1=0;
}
else if(vkey>3.5)
{
PORTB.0=0;
PORTB.1=1;
}
};
}
اضافه شده در تاریخ :
لطفا راهنمایی کنید .
دیدگاه