Вот код:
Code
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.9 Evaluation
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 31.08.2009
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
Chip type : ATmega8
Program type : Application
AVR Core Clock frequency: 8,000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega8.h>
#include <delay.h>
#define FIRST_ADC_INPUT 0
#define LAST_ADC_INPUT 0
#define SET_B(x) |= (1<<x)
#define CLR_B(x) &=~(1<<x)
unsigned char adc_data[LAST_ADC_INPUT-FIRST_ADC_INPUT+1];
#define ADC_VREF_TYPE 0x20
unsigned int count,count1,count2,m,i;
interrupt [ADC_INT] void adc_isr(void) //стандартное прерывание по ADC от CVAVR
{
static unsigned char input_index=0;
// Read the 8 most significant bits
// of the AD conversion result
adc_data[input_index]=ADCH;
// Select next ADC input
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);
// Start the AD conversion
ADCSRA|=0x40;
}
void main(void)
{
count=0;
count1=0;
count2=0;
m=0;
PORTB=0x00;
DDRB=0xFF;
PORTD=0x00;
DDRD=0xFC;
PORTB = 0b11111111;
ADMUX=FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff);
ADCSRA=0xCC;
#asm("sei")
delay_ms(200);
while (1)
{
if (PIND.0==0) {count2=count2+1;while(PIND.0==0){};}
if (count2==2) {
PORTD SET_B(7);
count=count+1;
delay_ms(50);
if (count==1) {while (PIND.1==1) {PORTB = 0b00000000;}}
if (count==2) {while (PIND.1==1) {PORTB = 0b00000001;}}
if (count==3) {count=0;}
count1=count1+1;
count2=0;
PORTB = 0b11111111;
PORTD CLR_B(7);
};
};
}
Не включается условие count==2 Работает только при count==1
Тестил в (Шпроте) там все нормально
Может что то с Ватчдогом , надо юзать?
Пробывал reset (1)
АЦП может как то влиять ?