Текст программы:
Код: Выделить всё
/*****************************************************
Chip type : ATmega8
Program type : Application
AVR Core Clock frequency: 8,000000 MHz
Memory model : Small
External RAM 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=0
#endasm
#include <1wire.h>
// DS1820 Temperature Sensor functions
#include <ds18b20.h>
char lcd[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
int disp_1=0,disp_2,mode_k=0; //объявляем переменные дли индикаторов
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
TCNT0=0x03;
// Place your code here
switch(mode_k)
{
case 0:
mode_k=1;
PORTB.0=0;
PORTB.6=0;
PORTB.7=0;
PORTB.4=0;
// PORTD =lcd[4];
// PORTB.0=1;
disp_2=disp_1/1000;
PORTD =lcd[disp_2];
PORTB.0=1;
break;
case 1:
PORTB.0=0;
PORTB.6=0;
PORTB.7=0;
PORTB.4=0;
mode_k=2;
disp_2=disp_1%1000;
disp_2=disp_2/100;
PORTD =lcd[disp_2];
PORTB.4=1;
break;
case 2:
PORTB.0=0;
PORTB.6=0;
PORTB.7=0;
PORTB.4=0;
mode_k=3;
disp_2=disp_1%100;
disp_2=disp_2/10;
PORTD =lcd[disp_2];
PORTB.7=1;
break;
case 3:
PORTB.0=0;
PORTB.6=0;
PORTB.7=0;
PORTB.4=0;
mode_k=0;
//PORTD =lcd[1];
//PORTB.6=1;
disp_2=disp_1%10;
PORTD =lcd[disp_2];
PORTB.6=1;
break;
}
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=Out Func6=Out Func5=In Func4=Out Func3=In Func2=In Func1=In Func0=Out
// State7=0 State6=0 State5=T State4=0 State3=T State2=T State1=T State0=0
PORTB=0x00;
DDRB=0xD1;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=0 State0=T
PORTC=0x00;
DDRC=0x02;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTD=0x00;
DDRD=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 8000,000 kHz
TCCR0=0x01;
TCNT0=0x03;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// 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=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=0x01;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// 1 Wire Bus initialization
#asm("cli")
w1_init();
delay_ms(500);
// Global enable interrupts
#asm("sei")
while (1)
{
#asm("cli")
// Place your code here
disp_1=ds18b20_temperature(0);
#asm("sei")
};
}
Индикаторы с общим Анодом, котоды к PD0...6, аноды на PB0,4,6,7
Датчик на PC0
и сразу вопрос, 1-wire должен стоять на in или out ?


