سلام
در بخش winavr.kavirelectronic.ir در قسمت انالوگ به دیجیتال دو مثال هست که دقیقا یادم نیست کدومه در بخش سورس ها هر دو سورس رو بگیرید من برای main.c کد رو تغییر دادم و پین pinb.0 رو به رله وصل کنید البنته با کمک یک ترانزیستور
[align=left]
کد:
/*! \file maain.c \brief Help farsi for win avr by www.kavirelectronic.ir */
//*****************************************************************************
//
// File Name : 'main.c' sample 1 for ADC
// Title : Analog-to-digital converter functions
// Author : kavirelectronic.ir - Copyright (C) 2008
// Created : 2008-05-09
// Revised : 2008-05-09
// Version : 1.0
// Target MCU : Atmel AVR series
// Editor Tabs : 1
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
// Example ADC
//! Initializes the A/D converter.
#include <avr>
#include <avr>
#include <avr>
#include <conf>
#include <inttypes>
#include <stdlib>
#include <stdio>
#include <avrlibdefs>
#include <avrlibtypes>
#include <avr>
#include <avr>
#include "a2d.h"
#include "lcd4bit.h"
#define High 34;
#define Low 30;
#define Relayon() PORTB = 1; // LowLowLowLowLowLowLowHi;
#define Relayoff() PORTB = 0; // LowLowLowLowLowLowLowLow
const uint8_t Title[] PROGMEM="sample For Temp:\0";
unsigned char temp=0;
unsigned char temp2=0;
int main(){
DDRB = 1; //for relay
DDRA=0b11111110;
PORTA=0b00000001;
LCDinit();
LCDclr();
LCDcursorOFF();
CopyStringtoLCD(Title,0,0);
a2dInit();
a2dSetPrescaler(ADC_PRESCALE_DIV64);
a2dSetReference(ADC_REFERENCE_256V);
a2dSetChannel(ADC_CH_ADC0);
while(1){
a2dStartConvert();
temp=a2dConvert8bit(ADC_CH_ADC0);
if(temp>High||temp<Low){
Relayon();
}esle{
Relayoff();
}
LCDGotoXY(0, 1);
u32 format="%u\n";
LCDprintData(format,temp);
}
}//main
[php]