You are on page 1of 2

/***************************************************** This program was produced by the CodeWizardAVR V2.05.

0 Professional Automatic Program Generator Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Version : Date : 13/07/2013 Author : NeVaDa Company : Comments: 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 interface functions #include <1wire.h> // DS1820 Temperature Sensor functions #include <ds18b20.h> // Declare your global variables here int font[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; void main(void) { // Declare your local variables here int i,chuc,tram,nghin,dvi; float temp; unsigned char *T=0; // Input/Output Ports initialization // Port B initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=O ut // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTB=0x00; DDRB=0xFF; // Port C initialization // Func6=In Func5=Out Func4=Out Func3=In Func2=Out Func1=Out Func0=In // State6=T State5=0 State4=0 State3=T State2=0 State1=0 State0=T PORTC=0x00; DDRC=0x36; // 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; // 1 Wire Bus initialization

// 1 Wire Data port: PORTC // 1 Wire Data bit: 0 // Note: 1 Wire port settings must be specified in the // Project|Configure|C Compiler|Libraries|1 Wire IDE menu. w1_init(); ds18b20_init(T,0,100,DS18B20_12BIT_RES); // Khoi tao DS18b20, do phan giai 12bi t while (1) { // Place your code here temp=ds18b20_temperature(T); nghin=(int)(temp/1000); tram=(int)((temp-nghin*1000)/100); chuc=(int)((temp-nghin*1000-tram*100)/10); dvi=(int)(temp-nghin*1000-tram*100-chuc*10); for(i=0;i<125;i++) { //PORTC=0b00000010; //PORTB=font[nghin]; //delay_ms(1); //PORTC=0b00000100; //PORTB=font[tram]; //delay_ms(1); PORTC=0b00010000; PORTB=font[chuc]; delay_ms(1); PORTC=0b00100000; PORTB=font[dvi]; delay_ms(1); } } }

You might also like