День Добрый!
Написал прогу для вывода температуры на lcd.
Мега работает на 1мгц.
Пишу в CV_AVR.
Датчик подрублен к PC5 с подтяжкой на 4.7к, внутренняя подтяжка в меге выключена.
Вот код:
/************************************************** ***
This program was produced by the
CodeWizardAVR V1.25.2 Beta1 Standard
Automatic Program Generator
© Copyright 1998-2006 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 06.06.2007
Author : Pavel
Company : Home
Comments:
Chip type : ATmega8
Program type : Application
Clock frequency : 1,000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
************************************************** ***/
#include ‹mega8.h›
#include ‹delay.h›
// 1 Wire Bus functions
#asm
.equ __w1_port=0x15 ;PORTC
.equ __w1_bit=5
#endasm
#include ‹1wire.h›
// DS1820 Temperature Sensor functions
#include ‹ds18b20.h›
/* include the printf function prototype */
#include ‹stdio.h›
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include ‹lcd.h›
/* maximum number of DS18B20 connected to the bus */
#define MAX_DEVICES 8
/* DS18B20 devices ROM code storage area,
9 bytes are used for each device
(see the w1_search function description),
but only the first 8 bytes contain the ROM code
and CRC */
unsigned char rom_codes[MAX_DEVICES][9];
char lcd_buffer[33];
/* allocate space for ROM codes of the devices
which generate an alarm */
unsigned char alarm_rom_codes[MAX_DEVICES][9];
// Declare your global variables here
char buffer2[15];
void main(void)
{
// Declare your local variables here
unsigned char i,j,devices;
// Input/Output Ports initialization
// 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
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// 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
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 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: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
lcd_init(16);
#asm("cli");
w1_init();
// 1 Wire Bus initialization
/*if (w1_init() == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("1-Wire devices not found");
//printf("1-Wire devices not found
");
}
else
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("1-Wire devices found");
}*/
#asm("sei");
// LCD module initialization
//lcd_gotoxy(0,0);
// lcd_putsf("test1");
//delay_ms(1000);
/* detect how many DS18B20 devices
are connected to the bus and
store their ROM codes in the rom_codes array */
#asm("cli");
devices=w1_search(0xf0,rom_codes);
#asm("sei");
lcd_clear();
sprintf(lcd_buffer,"%u DS18B20
Device detected",devices);
lcd_puts(lcd_buffer);
delay_ms(2000);
if (devices)
{
for (i=0;i‹devices;i++)
{
sprintf(lcd_buffer,"Device #%u ROM
Code is:",i+1);
lcd_clear();
lcd_puts(lcd_buffer);
delay_ms(2000);
lcd_clear();
for (j=0;j‹8;j++)
{
sprintf(lcd_buffer,"%02X ",rom_codes[i][j]);
lcd_puts(lcd_buffer);
if (j==3) lcd_gotoxy(0,1);
};
delay_ms(5000);
};
}
else
while (1); /* stop here if no devices were found */
/*delay_ms(2000);
if(devices==1)
{ lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("d18b20");
}
else
{ lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("no_way");
}
*/
/* set the temperature alarms & temperature
measurement resolutions for all the devices
temp_low=25°C temp_high=35°C resolution 12bits */
/*for (i=0;i‹devices;i++)
{
sprintf(buffer2,"ID #%-u" ,i+1);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(buffer2);
delay_ms(3000);
// printf("INITIALIZING DEVICE #%-u ",i+1);
if (ds18b20_init(&rom_codes[i][0],25,35,DS18B20_12BIT_RES))
{
lcd_clear();
lcd_gotoxy(0,0);
putsf("OK");delay_ms(3000);
}
else
{
lcd_clear();
lcd_gotoxy(0,0);
putsf("ERROR");delay_ms(3000);
}
}; */
while (1)
{
};
}
Датчик не видно..(((