Добрый день, помогите разобраться, не пойму чей глюк, мой или программный. Коде вижен выдал код для последовательного опроса двух портов АЦП и закидывания результата в массив, я вставил простенький код (красным изменения), откомпилировал коде вижен без ошибок и предупреждений, в протеусе накидал схемку, при запуске выдаёт предупреждение "эмуляция не может происходить в реальном времени т.к. процессор перегружен", даже когда на листе просто один контроллер с прошивкой подцепленной пишет о загрузке CPU почти 100%, посмотрите пожалуйста может чего не так: #include <tiny13.h>
#include <delay.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
// ADC interrupt service routine // with auto input scanning interrupt [ADC_INT] void adc_isr(void) { static unsigned char input_index=0; // Read the AD conversion result adc_data[input_index]=ADCW; // 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; }
// Declare your global variables here
void main(void) { // Declare your local variables here unsigned char adc_a=0; unsigned char adc_b=0; // Crystal Oscillator division factor: 1 #pragma optsize- CLKPR=0x80; CLKPR=0x00; #ifdef _OPTIMIZE_SIZE_ #pragma optsize+ #endif
// Input/Output Ports initialization // Port B initialization // Func5=In Func4=Out Func3=Out Func2=In Func1=Out Func0=Out // State5=T State4=0 State3=0 State2=T State1=1 State0=1 PORTB=0x03; DDRB=0x1B;
// Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0A output: Disconnected // OC0B output: Disconnected TCCR0A=0x00; TCCR0B=0x00; TCNT0=0x00; OCR0A=0x00; OCR0B=0x00;
// External Interrupt(s) initialization // INT0: Off // Interrupt on any change on pins PCINT0-5: Off GIMSK=0x00; MCUCR=0x00;
// Timer/Counter 0 Interrupt(s) initialization TIMSK0=0x00;
// Analog Comparator initialization // Analog Comparator: Off ACSR=0x80; ADCSRB=0x00;
// ADC initialization // ADC Clock frequency: 1000,000 kHz // ADC Bandgap Voltage Reference: Off // ADC Auto Trigger Source: None // Digital input buffers on ADC0: Off, ADC1: Off, ADC2: On, ADC3: On DIDR0&=0x03; DIDR0|=0x24; ADMUX=FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff); ADCSRA=0xCB;
// Global enable interrupts #asm("sei")
while (1) { adc_a=(unsigned char)~(adc_data[0]>>2); adc_b=(unsigned char)~(adc_data[1]>>2); if(adc_a>(638/5)) {PINB.0=0;} else {PINB.0=1;} if(adc_b>(638/5)) {PINB.1=0;} else {PINB.1=1;} }; }
Сообщение отредактировал Botanic - Sep 14 2010, 17:44
|