سلام و خسته نباشید خدمت دوستان
من این کد رو نوشتم ولی مشکل داره اینم اینه که دما رو نشون نمیده و روی LCD مینویسه :
Temp 'C
اما تاریخ و ساعت رو نشون میده درست .
به تنهایی هم برنامه ی ADC رو نوشتم ولی نشون نمیداد دما رو میداد 500.0'C تغییر هم نمیکد .
با مولتی متر هم ولتاژ خروجی ی LM35 رو اندازه گرفتم 291 mV بود.
کمکم کنید ممنون میشم
این هم کد :
Chip type : ATmega16L
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <stdlib.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x18 ;PORTB
.equ __sda_bit=0
.equ __scl_bit=1
#endasm
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x00
// 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;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
char str[10],lcdgo[10];
float tf;
unsigned char h,m,s,y,mo,d;
char buffer[50];
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x80;
PORTC=0x00;
DDRC=0x08;
PORTD=0x00;
DDRD=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
MCUCSR=0x00;
TIMSK=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: AREF pin
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x86;
i2c_init();
rtc_init(0,0,0);
lcd_init(16);
while (1)
{
// Place your code here
rtc_get_time(&h,&m,&s);
rtc_get_date(&y,&mo,&d);
sprintf(buffer,"%2u:%2u:%2u",h,m,s);
lcd_gotoxy(0,0);
lcd_puts(buffer);
sprintf(buffer,"%2u/%2u/%2u",y,mo,d);
lcd_gotoxy(0,1);
lcd_puts(buffer);
delay_ms(200);
if (PIND.4 == 0)
{
PORTC.3 = ~PINC.3;
};
if (PIND.5 == 0)
{
tf=read_adc(0);
tf=(tf*500/1023);
ftoa(tf,2,str);
sprintf(lcdgo,"temp %2 \xdfC",str);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(lcdgo);
delay_ms(2000);
lcd_clear();
}
};
}
من این کد رو نوشتم ولی مشکل داره اینم اینه که دما رو نشون نمیده و روی LCD مینویسه :
Temp 'C
اما تاریخ و ساعت رو نشون میده درست .
به تنهایی هم برنامه ی ADC رو نوشتم ولی نشون نمیداد دما رو میداد 500.0'C تغییر هم نمیکد .
با مولتی متر هم ولتاژ خروجی ی LM35 رو اندازه گرفتم 291 mV بود.
کمکم کنید ممنون میشم
این هم کد :
Chip type : ATmega16L
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <stdlib.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x18 ;PORTB
.equ __sda_bit=0
.equ __scl_bit=1
#endasm
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x00
// 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;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
char str[10],lcdgo[10];
float tf;
unsigned char h,m,s,y,mo,d;
char buffer[50];
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x80;
PORTC=0x00;
DDRC=0x08;
PORTD=0x00;
DDRD=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
MCUCSR=0x00;
TIMSK=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: AREF pin
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x86;
i2c_init();
rtc_init(0,0,0);
lcd_init(16);
while (1)
{
// Place your code here
rtc_get_time(&h,&m,&s);
rtc_get_date(&y,&mo,&d);
sprintf(buffer,"%2u:%2u:%2u",h,m,s);
lcd_gotoxy(0,0);
lcd_puts(buffer);
sprintf(buffer,"%2u/%2u/%2u",y,mo,d);
lcd_gotoxy(0,1);
lcd_puts(buffer);
delay_ms(200);
if (PIND.4 == 0)
{
PORTC.3 = ~PINC.3;
};
if (PIND.5 == 0)
{
tf=read_adc(0);
tf=(tf*500/1023);
ftoa(tf,2,str);
sprintf(lcdgo,"temp %2 \xdfC",str);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(lcdgo);
delay_ms(2000);
lcd_clear();
}
};
}
دیدگاه