Но почему то значения каналов коррелируются между собой. Где ошибка, подскажите пожалуйста.
При этом в протеусе все правильно, а в железе вот такое...
- Код: Выделить всё • Развернуть
#include <mega32.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
#include <stdio.h>
// 1 Wire Bus interface functions
#include <1wire.h>
// DS1820 Temperature Sensor functions
#include <ds18b20.h>
// Graphic LCD functions
#include <glcd.h>
// Font used for displaying text
// on the graphic LCD
#include <font5x7.h>
#include <verdana_bold.h>
// Function used for reading image
// data from external memory
unsigned char read_ext_memory(GLCDMEMADDR_t addr)
{
unsigned char data;
// Place your code here
return data;
}
// Function used for writing image
// data to external memory
void write_ext_memory(GLCDMEMADDR_t addr, unsigned char data)
{
// Place your code here
}
// Declare your global variables here
long int temper, temp_minus;
float volt, pressure, pressure_oper, volt_oper;
unsigned char lcdBuff[16];
void main(void)
{
// Declare your local variables here
// Graphic LCD initialization data
GLCDINIT_t glcd_init_data;
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 125,000 kHz
// ADC Voltage Reference: AVCC pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x87;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Graphic LCD initialization
// The PCD8544 connections are specified in the
// Project|Configure|C Compiler|Libraries|Graphic LCD menu:
// SDIN - PORTB Bit 3
// SCLK - PORTB Bit 4
// D /C - PORTB Bit 2
// /SCE - PORTB Bit 1
// /RES - PORTB Bit 0
// Specify the current font for displaying text
glcd_init_data.font=font5x7;
// No function is used for reading
// image data from external memory
glcd_init_data.readxmem=NULL;
// No function is used for writing
// image data to external memory
glcd_init_data.writexmem=NULL;
// Set the LCD temperature coefficient
glcd_init_data.temp_coef=PCD8544_DEFAULT_TEMP_COEF;
// Set the LCD bias
glcd_init_data.bias=PCD8544_DEFAULT_BIAS;
// Set the LCD contrast control voltage VLCD
glcd_init_data.vlcd=PCD8544_DEFAULT_VLCD;
glcd_init(&glcd_init_data);
// 1 Wire Bus initialization
// 1 Wire Data port: PORTA
// 1 Wire Data bit: 0
// Note: 1 Wire port settings are specified in the
// Project|Configure|C Compiler|Libraries|1 Wire menu.
w1_init();
// Global enable interrupts
#asm("sei")
ds18b20_init( 0, -30, 120 , DS18B20_9BIT_RES );
pcd8544_setvlcd(0x47);
while (1)
{
glcd_setfont(font5x7);
//вывод температуры !!!!!!!!!!!!!!!!
glcd_outtextxy(5,1,"TEMP");
temper=ds18b20_temperature( 0 );//Чтение температуры, адрес нуль
delay_ms( 30 );
temper=10;
if(temper>=0)
{
sprintf(lcdBuff,"+%u\xdf", temper);
glcd_outtextxy(4,10,lcdBuff);
}
if(temper<0)
{
temp_minus=temper;
sprintf(lcdBuff,"-%u\xdf", temp_minus);
glcd_outtextxy(4,10,lcdBuff);
}
//вывод напряжения !!!!!!!!!!!!!!!!
glcd_outtextxy(55,1,"VOLT");
//adc_data(0);
volt=((14.7*read_adc(0))/1024.00);
if(volt<=10)
{
sprintf(lcdBuff,"%.2f\xdf", volt);
glcd_outtextxy(55,10,lcdBuff);
}
else
{
sprintf(lcdBuff,"%.1f\xdf", volt);
glcd_outtextxy(55,10,lcdBuff);
}
volt_oper=0;
//вывод давления !!!!!!!!!!!!!!!!
// adc_data(1);
glcd_outtextxy(33,18,"Hot");
pressure=(((5*read_adc(1))/1024.00)*2.665);
{
glcd_setfont(verdana_bold);
sprintf(lcdBuff,"%.1f\xdf", pressure);
glcd_outtextxy(25,25,lcdBuff);
}
pressure_oper=0;
}
}
Добавлено спустя 5 минут 2 секунды:
- Код: Выделить всё • Развернуть
volt=((14.7*[b]read_adc(0)[/b])/1024.00);
if(volt<=10)
{
sprintf(lcdBuff,"%.2f\xdf", volt);
glcd_outtextxy(55,10,lcdBuff);
- Код: Выделить всё • Развернуть
pressure=(((5*[b]read_adc(1)[/b])/1024.00)*2.665);
{
glcd_setfont(verdana_bold);
sprintf(lcdBuff,"%.1f\xdf", pressure);
glcd_outtextxy(25,25,lcdBuff);