Пн май 06, 2013 16:43:57
/*****************************************************
CodeWizardAVR V2.05.3 Standard
Chip type : ATmega32A
AVR Core Clock frequency: 4,000000 MHz
*****************************************************/
#include <mega32a.h>
#include <delay.h>
// I2C Bus functions
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
// 1 Wire Bus interface functions
#include <1wire.h>
#include <ds18b20.h>
// Alphanumeric LCD functions
#include <alcd.h>
#include <stdio.h>
unsigned char devices;
int temp;
unsigned char lcd_buffer[16];
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Place your code here
}
// Timer1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Place your code here
}
// Timer2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
// Place your code here
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// 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=Out Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x80;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 3,906 kHz
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x05;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 3,906 kHz
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x05;
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: 125,000 kHz
// Mode: Fast PWM top=0xFF
// OC2 output: Non-Inverted PWM
ASSR=0x00;
TCCR2=0x6B;
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=0x45;
// 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;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// I2C Bus initialization
// I2C Port: PORTC
// I2C SDA bit: 5
// I2C SCL bit: 6
// Bit Rate: 50 kHz
// Note: I2C settings are specified in the
// Project|Configure|C Compiler|Libraries|I2C menu.
i2c_init();
// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: Off
// SQW/OUT pin state: 0
rtc_init(0,0,0);
// 1 Wire Bus initialization
// 1 Wire Data port: PORTB
// 1 Wire Data bit: 0
// Note: 1 Wire port settings are specified in the
// Project|Configure|C Compiler|Libraries|1 Wire menu.
w1_init();
devices=w1_init();
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTD Bit 6
// RD - PORTD Bit 5
// EN - PORTD Bit 4
// D4 - PORTC Bit 0
// D5 - PORTC Bit 1
// D6 - PORTC Bit 2
// D7 - PORTC Bit 3
// Characters/line: 20
lcd_init(16);
lcd_gotoxy(0,0);
lcd_putsf("Perezagruzka?");
lcd_gotoxy(0,1);
lcd_putsf("Perezagruzka?");
delay_ms(5000); //задержка надписи
lcd_clear();
// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/2048k
WDTCR=0x0F;
// Global enable interrupts
#asm("sei")
while (1)
{
// #asm("wdr")
temp=ds18b20_temperature(0);
if (temp>1000){
temp=4096-temp;
temp=-temp;
}
sprintf(lcd_buffer,"t=%i.%u\xdfC",temp,temp%1);
lcd_clear();
lcd_puts(lcd_buffer);
delay_ms(500);
}
}
Пн май 06, 2013 17:47:10
Пн май 06, 2013 18:24:18
Пн май 06, 2013 18:41:41
Пн май 06, 2013 20:16:03
Пн май 06, 2013 21:40:39
Вт май 07, 2013 09:27:14
void delay_ms(unsigned int n)
generates a delay of n milliseconds.
This function automatically resets the watchdog timer every 1ms by generating the wdr instruction.
Вт май 07, 2013 13:33:02
Вт май 07, 2013 13:47:30
Вт май 07, 2013 14:00:35
Вт май 07, 2013 17:25:33
Вт май 07, 2013 17:50:49
Вт май 07, 2013 18:27:28
Вт май 07, 2013 18:58:26
Вт май 07, 2013 20:30:50
if( mcu_failure == TRUE ) //глюк?
{
while(1);//ждать сброса
}
Ср сен 11, 2013 12:15:26
Ср сен 11, 2013 12:37:29
Ср сен 11, 2013 12:44:52
Ср сен 11, 2013 14:17:11
Ср сен 11, 2013 14:29:26