با سلام
تو برنامه زیر که از مبدل انالوگ به دیجیتال میکرو استفاده شده .بعد از کامپایل شدن ارور میده که مبدل های کانال صفر و یک را نمیتونه بشناسه.میتونید کمکم کنید
/************************************************** ***
#include <mega8.h>
#include <delay.h>
#include <alcd.h>
#define FIRST_ADC_INPUT 0
#define LAST_ADC_INPUT 1
unsigned int adc_data[LAST_ADC_INPUT-FIRST_ADC_INPUT+1];
#define ADC_VREF_TYPE 0x00
interrupt [ADC_INT] void adc_isr(void)
{
static unsigned char input_index=0;
adc_data[input_index]=ADCW;
if (++input_index > (LAST_ADC_INPUT-FIRST_ADC_INPUT))
input_index=0;
ADMUX=(FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff))+input_index;
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
ADCSRA|=0x40;
}
void main(void)
{
float line[];
float main_negative=0;
float main_possitive=0;
char p=0;
char fault=10;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
SPCR=0x00;
lcd_init(8);
#asm("sei"
while (1)
{
lcd_clear();
lcd_puts("Press Key(1)"
;
delay_ms(200);
if(PIND.7==0){
lcd_clear();
p=0;
//+P(Main) reading
main_possitive=read_adc(0);
//(Force line P 1)
delay_ms(100);
PORTD=0x01;
delay_ms(2000);
line[p]=read_adc(0);
p++;
//(Force line P 2)
delay_ms(100);
PORTD=0x02;
delay_ms(2000);
line[p]=read_adc(0);
PORTD=0x00;
p++;
main_negative=read_adc(1);
//(Force line N 1)
delay_ms(100);
PORTD=0x04;
delay_ms(2000);
line[p]=read_adc(1);
p++;
//(Force line N 2)
delay_ms(100);
PORTD=0x08;
delay_ms(2000);
line[p]=read_adc(1);
for(p=0;p<2;p++){
if (line[p]>main_possitive)
fault=p;
}
for(p=2;p<4;p++){
if (line[p]>main_negative)
fault=p;
else
fault=10;
}
switch (fault){
case 0:
lcd_puts("DC Ground"
;
lcd_gotoxy(16,1);
lcd_puts("SOL 1"
;
break;
case 1:
lcd_puts("DC Ground"
;
lcd_gotoxy(16,1);
lcd_puts("SOL 2"
;
break;
case 2:
lcd_puts("DC Ground"
;
lcd_gotoxy(16,1);
lcd_puts("SOL 1"
;
case 3:
lcd_puts("DC Ground"
;
lcd_gotoxy(16,1);
lcd_puts("SOL 2"
;
case 10:
lcd_clear();
lcd_puts("SYSTEM NORMAL"
;
delay_ms(2000);
}
}
}
}
این هم خطایی که میده
http://s7.picofile.com/file/8238792034/22.jpg
تو برنامه زیر که از مبدل انالوگ به دیجیتال میکرو استفاده شده .بعد از کامپایل شدن ارور میده که مبدل های کانال صفر و یک را نمیتونه بشناسه.میتونید کمکم کنید
/************************************************** ***
#include <mega8.h>
#include <delay.h>
#include <alcd.h>
#define FIRST_ADC_INPUT 0
#define LAST_ADC_INPUT 1
unsigned int adc_data[LAST_ADC_INPUT-FIRST_ADC_INPUT+1];
#define ADC_VREF_TYPE 0x00
interrupt [ADC_INT] void adc_isr(void)
{
static unsigned char input_index=0;
adc_data[input_index]=ADCW;
if (++input_index > (LAST_ADC_INPUT-FIRST_ADC_INPUT))
input_index=0;
ADMUX=(FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff))+input_index;
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
ADCSRA|=0x40;
}
void main(void)
{
float line[];
float main_negative=0;
float main_possitive=0;
char p=0;
char fault=10;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
SPCR=0x00;
lcd_init(8);
#asm("sei"

while (1)
{
lcd_clear();
lcd_puts("Press Key(1)"

delay_ms(200);
if(PIND.7==0){
lcd_clear();
p=0;
//+P(Main) reading
main_possitive=read_adc(0);
//(Force line P 1)
delay_ms(100);
PORTD=0x01;
delay_ms(2000);
line[p]=read_adc(0);
p++;
//(Force line P 2)
delay_ms(100);
PORTD=0x02;
delay_ms(2000);
line[p]=read_adc(0);
PORTD=0x00;
p++;
main_negative=read_adc(1);
//(Force line N 1)
delay_ms(100);
PORTD=0x04;
delay_ms(2000);
line[p]=read_adc(1);
p++;
//(Force line N 2)
delay_ms(100);
PORTD=0x08;
delay_ms(2000);
line[p]=read_adc(1);
for(p=0;p<2;p++){
if (line[p]>main_possitive)
fault=p;
}
for(p=2;p<4;p++){
if (line[p]>main_negative)
fault=p;
else
fault=10;
}
switch (fault){
case 0:
lcd_puts("DC Ground"

lcd_gotoxy(16,1);
lcd_puts("SOL 1"

break;
case 1:
lcd_puts("DC Ground"

lcd_gotoxy(16,1);
lcd_puts("SOL 2"

break;
case 2:
lcd_puts("DC Ground"

lcd_gotoxy(16,1);
lcd_puts("SOL 1"

case 3:
lcd_puts("DC Ground"

lcd_gotoxy(16,1);
lcd_puts("SOL 2"

case 10:
lcd_clear();
lcd_puts("SYSTEM NORMAL"

delay_ms(2000);
}
}
}
}
این هم خطایی که میده
http://s7.picofile.com/file/8238792034/22.jpg
دیدگاه