Компиляция программы в WinAvr
Всем привет! Нужна компетентная помощ с одной прграмкой. Битый час уже не могу разобратся. При компиляции почему-то выбивает ошибку:
> "make.exe" program
Compiling: main.c
avr-gcc -c -mmcu=atmega16 -I. -gstabs -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst -std=gnu99 -D TEST_MODULE -D F_CPU=10000000UL -Wp,-M,-MP,-MT,main.o,-MF,.dep/main.o.d main.c -o main.o
main.c:588: fatal error: opening dependency file .dep/main.o.d: No such file or directory
compilation terminated.
make.exe: *** [main.o] Error 1
> Process Exit Code: 2
> Time Taken: 00:00
Код программы:
//#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/sleep.h>
#include <avr/pgmspace.h>
#include <string.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#include <stdio.h>
#include "defines.h"
uint32_t calib_low, calib_high;
uint32_t zero_low, zero_high;
void ReadEeprom(void)
{
eeprom_read_block(&calib_low, (const uint8_t *)0, 4);
eeprom_read_block(&calib_high, (const uint8_t *)4, 4);
eeprom_read_block(&zero_low, (const uint8_t *)8, 4);
eeprom_read_block(&zero_high, (const uint8_t *)12, 4);
if (calib_low==0xFFFFFFFFL)
{
calib_low = 0x074D;
calib_high = 0x06E7;
zero_low = 0x00C3;
zero_high = 0;
}
}
void WriteEeprom(void)
{
eeprom_write_block(&calib_low, (uint8_t *)0, 4);
eeprom_write_block(&calib_high, (uint8_t *)4, 4);
eeprom_write_block(&zero_low, (uint8_t *)8, 4);
eeprom_write_block(&zero_high, (uint8_t *)12, 4);
}
void LcdInit(void)
{
DDRA |= 0b11111111;
PORTA &= ~0b11111111;
DDRB |= 0b11100000;
PORTB &= ~0b11100000;
DDRC |= 0b11111111;
PORTC &= ~0b11111111;
DDRD |= 0b11111111;
PORTD &= ~0b11111111;
// Setup ~76 Hz timer
TCNT0 = 128;
TCCR0 = 0b00000101;
TIMSK |= 1;
}
volatile uint8_t A=0,B=0,C=0,D=0; // Port values to put to the LCD
SIGNAL (SIG_OVERFLOW0)
{
TCNT0 = 128;
static uint8_t phase = 0;
phase = !phase;
if (phase)
{
PORTA = (PORTA & ~0b11111101) | A;
// PORTB = (PORTB & ~0b11110000) | B;
PORTC = (PORTC & ~0b11111111) | C;
PORTD = (PORTD & ~0b10111111) | D;
// Force cbi/sbi instructions
if (B & 128)
PORTB |= 128;
else
PORTB &= ~128;
if (B & 64)
PORTB |= 64;
else
PORTB &= ~64;
if (B & 32)
PORTB |= 32;
else
PORTB &= ~32;
if (B & 1)
PORTD |= 64;
else
PORTD &= ~64;
clrbit(PORTA,1);
}
else
{
PORTA = (PORTA | 0b11111101) & ~A;
// PORTB = (PORTB | 0b11110000) & ~B;
PORTC = (PORTC | 0b11111111) & ~C;
PORTD = (PORTD | 0b10111111) & ~D;
// Force cbi/sbi instructions
if (B & 128)
PORTB &= ~128;
else
PORTB |= 128;
if (B & 64)
PORTB &= ~64;
else
PORTB |= 64;
if (B & 32)
PORTB &= ~32;
else
PORTB |= 32;
if (B & 1)
PORTD &= ~64;
else
PORTD |= 64;
setbit(PORTA,1);
}
}
void NrOut(uint8_t n1, uint8_t n2, uint8_t n3, uint8_t dot_pos, uint8_t units)
{
A = B = C = D = 0;
switch (n1)
{
case 0:
A |= 0b00111001;
B |= 0b00100001;
break;
case 1:
A |= 0b00100000;
B |= 0b00100000;
break;
case 2:
A |= 0b00110101;
B |= 0b00000001;
break;
case 3:
A |= 0b00110100;
B |= 0b00100001;
break;
case 4:
A |= 0b00101100;
B |= 0b00100000;
break;
case 5:
A |= 0b00011100;
B |= 0b00100001;
break;
case 6:
A |= 0b00011101;
B |= 0b00100001;
break;
case 7:
A |= 0b00110000;
B |= 0b00100000;
break;
case 8:
A |= 0b00111101;
B |= 0b00100001;
break;
case 9:
A |= 0b00111100;
B |= 0b00100001;
break;
case 11: // C
A |= 0b00011001;
B |= 0b00000001;
break;
}
switch(n2)
{
case 0:
A |= 0b10000000;
B |= 0b10000000;
C |= 0b11000000;
D |= 0b00000011;
break;
case 1:
C |= 0b01000000;
D |= 0b00000010;
break;
case 2:
A |= 0b01000000;
B |= 0b10000000;
C |= 0b11000000;
D |= 0b00000001;
break;
case 3:
A |= 0b01000000;
C |= 0b11000000;
D |= 0b00000011;
break;
case 4:
A |= 0b11000000;
C |= 0b01000000;
D |= 0b00000010;
break;
case 5:
A |= 0b11000000;
C |= 0b10000000;
D |= 0b00000011;
break;
case 6:
A |= 0b11000000;
B |= 0b10000000;
C |= 0b10000000;
D |= 0b00000011;
break;
case 7:
C |= 0b11000000;
D |= 0b00000010;
break;
case 8:
A |= 0b11000000;
B |= 0b10000000;
C |= 0b11000000;
D |= 0b00000011;
break;
case 9:
A |= 0b11000000;
C |= 0b11000000;
D |= 0b00000011;
break;
case 11: // A
A |= 0b11000000;
B |= 0b10000000;
C |= 0b11000000;
D |= 0b00000010;
break;
}
switch (n3)
{
case 0:
C |= 0b00011100;
D |= 0b00111000;
break;
case 1:
C |= 0b00000100;
D |= 0b00100000;
break;
case 2:
C |= 0b00101100;
D |= 0b00011000;
break;
case 3:
C |= 0b00101100;
D |= 0b00110000;
break;
case 4:
C |= 0b00110100;
D |= 0b00100000;
break;
case 5:
C |= 0b00111000;
D |= 0b00110000;
break;
case 6:
C |= 0b00111000;
D |= 0b00111000;
break;
case 7:
C |= 0b00001100;
D |= 0b00100000;
break;
case 8:
C |= 0b00111100;
D |= 0b00111000;
break;
case 9:
C |= 0b00111100;
D |= 0b00110000;
break;
case 11: // L
C |= 0b00010000;
D |= 0b00011000;
break;
}
switch (dot_pos)
{
case 1:
B |= 0b01000000;
break;
case 2:
D |= 0b00000100;
break;
}
switch (units)
{
case 0: // pF
C |= 0b00000011;
D |= 0b10000000;
break;
case 1: // nF
C |= 0b00000001;
D |= 0b10000000;
break;
case 2: // uF
C |= 0b00000011;
break;
}
}
volatile uint8_t timeout, measured_flag, ovf_flag, ovf_cnt;
volatile uint32_t capt1,capt2;
uint32_t Measure(uint8_t range)
{
setbit(DDRB,1); // Set threshhold to 0.17V
setbit(DDRB,2); // Discharge the capacitor, AIN0 as output
TCNT1 = 0;
if (range) // high range
{
clrbit(PORTB,0); // Set high range
timeout = 152; // 1s for high range
}
else // low range
{
setbit(PORTB,0); // Set low range
timeout = 20 ; // 0.13s for low range
}
//clrbit(DDRB,1); // Set to 0.5V
delay_ms(200); // Some delay to discharge the capacitor
TIFR |= 0b00100100; // Set capture and overflow interrupts
TIMSK |= 0b00100100;
measured_flag = 0;
ovf_flag = 0;
ovf_cnt = 0;
TCCR1B = 0b01000001; // Start timer
clrbit(DDRB,2); // Start charging
while( (!measured_flag) && (!ovf_flag)); // Wait until timeout or successfull measurement
TCCR1B = 0b01000000; // Stop timer
setbit(DDRB,1); // Set threshhold to 0.17V
setbit(DDRB,2); // Discharge the capacitor, AIN0 as output
if (ovf_flag)
return 0;
else
return capt2 - capt1;
}
SIGNAL (SIG_OVERFLOW1)
{
ovf_cnt++;
if (ovf_cnt == timeout)
{
ovf_flag = 1;
TIMSK &= ~0b00000100; // Disable overflow interrupt
}
}
SIGNAL (SIG_INPUT_CAPTURE1)
{
if (getbit(DDRB,1)) // Was 0.17V
{
capt1 = ((uint32_t)ovf_cnt) << 16;
capt1 |= ICR1;
clrbit(DDRB,1); // Set to 0.5V
_delay_loop_1(20);
TIFR |= 0b00100000; // Clear capture interrupt flag
}
else
{
capt2 = ((uint32_t)ovf_cnt) << 16;
capt2 |= ICR1;
// capt2 = ICR1;
// capt2 |= ((uint32_t)ovf_cnt) << 16;
// setbit(DDRB,1); // Set threshhold to 0.17V
// setbit(DDRB,2); // Discharge the capacitor, AIN0 as output
TIMSK &= ~0b00100000; // Disable capture interrupt
measured_flag = 1;
// _delay_loop_1(20);
// TIFR |= 0b00100000; // Clear capture interrupt flag
}
}
void DisplayPf(double c)
{
uint32_t c10 = c*10.0;
if (c<0.0)
{
NrOut(10,0,0,2,0); /// xx.x p
}
else
if (c10<1000) // < 100 nF
{
NrOut((c10/100 > 0) ? (c10/100) : 10,(c10/10)%10,c10%10,2,0); /// xx.x p
}
else
if (c10<10000) // < 1 nF
{
NrOut(c10/1000,(c10/100)%10,(c10/10)%10,3,0); /// xxx p
}
else
if (c10<100000L) // < 10 nF
{
NrOut(c10/10000,(c10/1000)%10,(c10/100)%10,1,1); /// x.xx n
}
else
if (c10<1000000L) // < 100 nF
{
NrOut(c10/100000L,(c10/10000)%10,(c10/1000)%10,2,1); /// xx.x n
}
else
if (c10<10000000L) // < 1 uF
{
NrOut(c10/1000000L,(c10/100000L)%10,(c10/10000)%10,3,1); /// xxx n
}
else
if (c10<100000000L) // < 10 uF
{
NrOut(c10/10000000L,(c10/1000000L)%10,(c10/100000L)%10,1,2); /// x.xx u
}
else
if (c10<1000000000L) // < 100 uF
{
NrOut(c10/100000000L,(c10/10000000L)%10,(c10/1000000L)%10,2,2); /// xx.x u
}
else
NrOut(c10/1000000000L,(c10/100000000L)%10,(c10/10000000L)%10,3,2); /// xxx u
}
int main(void)
{
LcdInit();
ReadEeprom();
// NrOut(0,0,0,3,2); /// 000 uF
// Init other ports
setbit(PORTB,0); // Set low range
setbit(DDRB,0);
clrbit(PORTB, 1); // Set threshhold to 0.17V
setbit(DDRB, 1);
clrbit(PORTB,2); // Discharge the capacitor, AIN0 as output
setbit(DDRB,2);
clrbit(PORTB,3); // AIN1 as input
clrbit(DDRB,3);
ACSR |= 0b00000100; // Enable comparator capture function
sei();
clrbit(DDRB,4); // Input
setbit(PORTB,4);
delay_ms(100);
if (!getbit(PINB,4)) // calibrate
{
NrOut(11,11,11,3,3); /// CAL
Measure(0); // Warm-up
Measure(1);
while(!getbit(PINB,4)); // Wait until button released
delay_ms(500);
// Calibrate at 100 pF
DisplayPf(100);
while(getbit(PINB,4)); // Wait until button pressed
delay_ms(100);
while(!getbit(PINB,4)); // Wait until button released
delay_ms(500);
calib_low = Measure(0); // Measure at low range
calib_low = Measure(0); // Measure at low range
WriteEeprom();
// Calibrate at 100 nF
DisplayPf(100000);
delay_ms(100);
while(getbit(PINB,4)); // Wait until button pressed
delay_ms(100);
while(!getbit(PINB,4)); // Wait until button released
delay_ms(500);
calib_high = Measure(1); // Measure at high range
calib_high = Measure(1); // Measure at high range
WriteEeprom();
}
while(1) // Endless while
{
if (!getbit(PINB,4)) // Button pressed - set zero
{
NrOut(0,0,0,3,3); // 000
delay_ms(100);
while(!getbit(PINB,4)); // Wait until button released
delay_ms(200);
zero_low = Measure(0); // Measure at low range
zero_high = Measure(1); // Measure at high range
WriteEeprom();
}
else // normal measurement
{
uint32_t ticks;
ticks = Measure(0); // Low range
if (ticks) // Low range OK
{
double cpf = (((double)ticks)-zero_low)/(calib_low-zero_low)*100.0;
DisplayPf(cpf);
}
else // Try high range
{
ticks = Measure(1); // High range
if (ticks==0) // Overflow
NrOut(9,9,9,3,2); // 999 uF
else
{
double cpf = (((double)ticks)-zero_high)/(calib_high-zero_high)*100000.0;
DisplayPf(cpf);
}
}
}
}
return(0);
}
Заранее спасибо!
Всем привет! Нужна компетентная помощ с одной прграмкой. Битый час уже не могу разобратся. При компиляции почему-то выбивает ошибку:
> "make.exe" program
Compiling: main.c
avr-gcc -c -mmcu=atmega16 -I. -gstabs -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst -std=gnu99 -D TEST_MODULE -D F_CPU=10000000UL -Wp,-M,-MP,-MT,main.o,-MF,.dep/main.o.d main.c -o main.o
main.c:588: fatal error: opening dependency file .dep/main.o.d: No such file or directory
compilation terminated.
make.exe: *** [main.o] Error 1
> Process Exit Code: 2
> Time Taken: 00:00
Код программы:
//#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/sleep.h>
#include <avr/pgmspace.h>
#include <string.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#include <stdio.h>
#include "defines.h"
uint32_t calib_low, calib_high;
uint32_t zero_low, zero_high;
void ReadEeprom(void)
{
eeprom_read_block(&calib_low, (const uint8_t *)0, 4);
eeprom_read_block(&calib_high, (const uint8_t *)4, 4);
eeprom_read_block(&zero_low, (const uint8_t *)8, 4);
eeprom_read_block(&zero_high, (const uint8_t *)12, 4);
if (calib_low==0xFFFFFFFFL)
{
calib_low = 0x074D;
calib_high = 0x06E7;
zero_low = 0x00C3;
zero_high = 0;
}
}
void WriteEeprom(void)
{
eeprom_write_block(&calib_low, (uint8_t *)0, 4);
eeprom_write_block(&calib_high, (uint8_t *)4, 4);
eeprom_write_block(&zero_low, (uint8_t *)8, 4);
eeprom_write_block(&zero_high, (uint8_t *)12, 4);
}
void LcdInit(void)
{
DDRA |= 0b11111111;
PORTA &= ~0b11111111;
DDRB |= 0b11100000;
PORTB &= ~0b11100000;
DDRC |= 0b11111111;
PORTC &= ~0b11111111;
DDRD |= 0b11111111;
PORTD &= ~0b11111111;
// Setup ~76 Hz timer
TCNT0 = 128;
TCCR0 = 0b00000101;
TIMSK |= 1;
}
volatile uint8_t A=0,B=0,C=0,D=0; // Port values to put to the LCD
SIGNAL (SIG_OVERFLOW0)
{
TCNT0 = 128;
static uint8_t phase = 0;
phase = !phase;
if (phase)
{
PORTA = (PORTA & ~0b11111101) | A;
// PORTB = (PORTB & ~0b11110000) | B;
PORTC = (PORTC & ~0b11111111) | C;
PORTD = (PORTD & ~0b10111111) | D;
// Force cbi/sbi instructions
if (B & 128)
PORTB |= 128;
else
PORTB &= ~128;
if (B & 64)
PORTB |= 64;
else
PORTB &= ~64;
if (B & 32)
PORTB |= 32;
else
PORTB &= ~32;
if (B & 1)
PORTD |= 64;
else
PORTD &= ~64;
clrbit(PORTA,1);
}
else
{
PORTA = (PORTA | 0b11111101) & ~A;
// PORTB = (PORTB | 0b11110000) & ~B;
PORTC = (PORTC | 0b11111111) & ~C;
PORTD = (PORTD | 0b10111111) & ~D;
// Force cbi/sbi instructions
if (B & 128)
PORTB &= ~128;
else
PORTB |= 128;
if (B & 64)
PORTB &= ~64;
else
PORTB |= 64;
if (B & 32)
PORTB &= ~32;
else
PORTB |= 32;
if (B & 1)
PORTD &= ~64;
else
PORTD |= 64;
setbit(PORTA,1);
}
}
void NrOut(uint8_t n1, uint8_t n2, uint8_t n3, uint8_t dot_pos, uint8_t units)
{
A = B = C = D = 0;
switch (n1)
{
case 0:
A |= 0b00111001;
B |= 0b00100001;
break;
case 1:
A |= 0b00100000;
B |= 0b00100000;
break;
case 2:
A |= 0b00110101;
B |= 0b00000001;
break;
case 3:
A |= 0b00110100;
B |= 0b00100001;
break;
case 4:
A |= 0b00101100;
B |= 0b00100000;
break;
case 5:
A |= 0b00011100;
B |= 0b00100001;
break;
case 6:
A |= 0b00011101;
B |= 0b00100001;
break;
case 7:
A |= 0b00110000;
B |= 0b00100000;
break;
case 8:
A |= 0b00111101;
B |= 0b00100001;
break;
case 9:
A |= 0b00111100;
B |= 0b00100001;
break;
case 11: // C
A |= 0b00011001;
B |= 0b00000001;
break;
}
switch(n2)
{
case 0:
A |= 0b10000000;
B |= 0b10000000;
C |= 0b11000000;
D |= 0b00000011;
break;
case 1:
C |= 0b01000000;
D |= 0b00000010;
break;
case 2:
A |= 0b01000000;
B |= 0b10000000;
C |= 0b11000000;
D |= 0b00000001;
break;
case 3:
A |= 0b01000000;
C |= 0b11000000;
D |= 0b00000011;
break;
case 4:
A |= 0b11000000;
C |= 0b01000000;
D |= 0b00000010;
break;
case 5:
A |= 0b11000000;
C |= 0b10000000;
D |= 0b00000011;
break;
case 6:
A |= 0b11000000;
B |= 0b10000000;
C |= 0b10000000;
D |= 0b00000011;
break;
case 7:
C |= 0b11000000;
D |= 0b00000010;
break;
case 8:
A |= 0b11000000;
B |= 0b10000000;
C |= 0b11000000;
D |= 0b00000011;
break;
case 9:
A |= 0b11000000;
C |= 0b11000000;
D |= 0b00000011;
break;
case 11: // A
A |= 0b11000000;
B |= 0b10000000;
C |= 0b11000000;
D |= 0b00000010;
break;
}
switch (n3)
{
case 0:
C |= 0b00011100;
D |= 0b00111000;
break;
case 1:
C |= 0b00000100;
D |= 0b00100000;
break;
case 2:
C |= 0b00101100;
D |= 0b00011000;
break;
case 3:
C |= 0b00101100;
D |= 0b00110000;
break;
case 4:
C |= 0b00110100;
D |= 0b00100000;
break;
case 5:
C |= 0b00111000;
D |= 0b00110000;
break;
case 6:
C |= 0b00111000;
D |= 0b00111000;
break;
case 7:
C |= 0b00001100;
D |= 0b00100000;
break;
case 8:
C |= 0b00111100;
D |= 0b00111000;
break;
case 9:
C |= 0b00111100;
D |= 0b00110000;
break;
case 11: // L
C |= 0b00010000;
D |= 0b00011000;
break;
}
switch (dot_pos)
{
case 1:
B |= 0b01000000;
break;
case 2:
D |= 0b00000100;
break;
}
switch (units)
{
case 0: // pF
C |= 0b00000011;
D |= 0b10000000;
break;
case 1: // nF
C |= 0b00000001;
D |= 0b10000000;
break;
case 2: // uF
C |= 0b00000011;
break;
}
}
volatile uint8_t timeout, measured_flag, ovf_flag, ovf_cnt;
volatile uint32_t capt1,capt2;
uint32_t Measure(uint8_t range)
{
setbit(DDRB,1); // Set threshhold to 0.17V
setbit(DDRB,2); // Discharge the capacitor, AIN0 as output
TCNT1 = 0;
if (range) // high range
{
clrbit(PORTB,0); // Set high range
timeout = 152; // 1s for high range
}
else // low range
{
setbit(PORTB,0); // Set low range
timeout = 20 ; // 0.13s for low range
}
//clrbit(DDRB,1); // Set to 0.5V
delay_ms(200); // Some delay to discharge the capacitor
TIFR |= 0b00100100; // Set capture and overflow interrupts
TIMSK |= 0b00100100;
measured_flag = 0;
ovf_flag = 0;
ovf_cnt = 0;
TCCR1B = 0b01000001; // Start timer
clrbit(DDRB,2); // Start charging
while( (!measured_flag) && (!ovf_flag)); // Wait until timeout or successfull measurement
TCCR1B = 0b01000000; // Stop timer
setbit(DDRB,1); // Set threshhold to 0.17V
setbit(DDRB,2); // Discharge the capacitor, AIN0 as output
if (ovf_flag)
return 0;
else
return capt2 - capt1;
}
SIGNAL (SIG_OVERFLOW1)
{
ovf_cnt++;
if (ovf_cnt == timeout)
{
ovf_flag = 1;
TIMSK &= ~0b00000100; // Disable overflow interrupt
}
}
SIGNAL (SIG_INPUT_CAPTURE1)
{
if (getbit(DDRB,1)) // Was 0.17V
{
capt1 = ((uint32_t)ovf_cnt) << 16;
capt1 |= ICR1;
clrbit(DDRB,1); // Set to 0.5V
_delay_loop_1(20);
TIFR |= 0b00100000; // Clear capture interrupt flag
}
else
{
capt2 = ((uint32_t)ovf_cnt) << 16;
capt2 |= ICR1;
// capt2 = ICR1;
// capt2 |= ((uint32_t)ovf_cnt) << 16;
// setbit(DDRB,1); // Set threshhold to 0.17V
// setbit(DDRB,2); // Discharge the capacitor, AIN0 as output
TIMSK &= ~0b00100000; // Disable capture interrupt
measured_flag = 1;
// _delay_loop_1(20);
// TIFR |= 0b00100000; // Clear capture interrupt flag
}
}
void DisplayPf(double c)
{
uint32_t c10 = c*10.0;
if (c<0.0)
{
NrOut(10,0,0,2,0); /// xx.x p
}
else
if (c10<1000) // < 100 nF
{
NrOut((c10/100 > 0) ? (c10/100) : 10,(c10/10)%10,c10%10,2,0); /// xx.x p
}
else
if (c10<10000) // < 1 nF
{
NrOut(c10/1000,(c10/100)%10,(c10/10)%10,3,0); /// xxx p
}
else
if (c10<100000L) // < 10 nF
{
NrOut(c10/10000,(c10/1000)%10,(c10/100)%10,1,1); /// x.xx n
}
else
if (c10<1000000L) // < 100 nF
{
NrOut(c10/100000L,(c10/10000)%10,(c10/1000)%10,2,1); /// xx.x n
}
else
if (c10<10000000L) // < 1 uF
{
NrOut(c10/1000000L,(c10/100000L)%10,(c10/10000)%10,3,1); /// xxx n
}
else
if (c10<100000000L) // < 10 uF
{
NrOut(c10/10000000L,(c10/1000000L)%10,(c10/100000L)%10,1,2); /// x.xx u
}
else
if (c10<1000000000L) // < 100 uF
{
NrOut(c10/100000000L,(c10/10000000L)%10,(c10/1000000L)%10,2,2); /// xx.x u
}
else
NrOut(c10/1000000000L,(c10/100000000L)%10,(c10/10000000L)%10,3,2); /// xxx u
}
int main(void)
{
LcdInit();
ReadEeprom();
// NrOut(0,0,0,3,2); /// 000 uF
// Init other ports
setbit(PORTB,0); // Set low range
setbit(DDRB,0);
clrbit(PORTB, 1); // Set threshhold to 0.17V
setbit(DDRB, 1);
clrbit(PORTB,2); // Discharge the capacitor, AIN0 as output
setbit(DDRB,2);
clrbit(PORTB,3); // AIN1 as input
clrbit(DDRB,3);
ACSR |= 0b00000100; // Enable comparator capture function
sei();
clrbit(DDRB,4); // Input
setbit(PORTB,4);
delay_ms(100);
if (!getbit(PINB,4)) // calibrate
{
NrOut(11,11,11,3,3); /// CAL
Measure(0); // Warm-up
Measure(1);
while(!getbit(PINB,4)); // Wait until button released
delay_ms(500);
// Calibrate at 100 pF
DisplayPf(100);
while(getbit(PINB,4)); // Wait until button pressed
delay_ms(100);
while(!getbit(PINB,4)); // Wait until button released
delay_ms(500);
calib_low = Measure(0); // Measure at low range
calib_low = Measure(0); // Measure at low range
WriteEeprom();
// Calibrate at 100 nF
DisplayPf(100000);
delay_ms(100);
while(getbit(PINB,4)); // Wait until button pressed
delay_ms(100);
while(!getbit(PINB,4)); // Wait until button released
delay_ms(500);
calib_high = Measure(1); // Measure at high range
calib_high = Measure(1); // Measure at high range
WriteEeprom();
}
while(1) // Endless while
{
if (!getbit(PINB,4)) // Button pressed - set zero
{
NrOut(0,0,0,3,3); // 000
delay_ms(100);
while(!getbit(PINB,4)); // Wait until button released
delay_ms(200);
zero_low = Measure(0); // Measure at low range
zero_high = Measure(1); // Measure at high range
WriteEeprom();
}
else // normal measurement
{
uint32_t ticks;
ticks = Measure(0); // Low range
if (ticks) // Low range OK
{
double cpf = (((double)ticks)-zero_low)/(calib_low-zero_low)*100.0;
DisplayPf(cpf);
}
else // Try high range
{
ticks = Measure(1); // High range
if (ticks==0) // Overflow
NrOut(9,9,9,3,2); // 999 uF
else
{
double cpf = (((double)ticks)-zero_high)/(calib_high-zero_high)*100000.0;
DisplayPf(cpf);
}
}
}
}
return(0);
}
Заранее спасибо!