#include <mega16.h> #include <delay.h>
#asm // 1 Wire Bus functions .equ __w1_port=0x15 ;PORTC .equ __w1_bit=5 #endasm #include <1wire.h> #include <ds1820.h> // DS1820 Temperature Sensor functions
#define uchar unsigned char #define uint unsigned int flash uchar tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; flash uchar wei_tab[]={0x00,0xf7,0xef,0xdf,0xbf}; //高到低 // Declare your global variables here
void display(uchar pos,uchar num) { //uint k; PORTA=tab[num]; PORTC|=0x80; //开锁存 PORTD=wei_tab[pos]; //WEI1开 delay_ms(4); //延时 PORTC&=0xef; //锁存 delay_ms(2); //延时 PORTA=0x00; //灭灯 }
void main(void) { // Declare your local variables here uchar teml,temh,a,b; uint tem; float tt;
PORTA=0xff; DDRA=0xff; PORTB=0x00; DDRB=0x00; PORTC=0x00; DDRC=0xff; PORTD=0x00; DDRD=0xff;
// Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0 output: Disconnected TCCR0=0x00; TCNT0=0x00; OCR0=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 // INT2: Off MCUCR=0x00; MCUCSR=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;
// 1 Wire Bus initialization //w1_init(); while (1) { // Place your code here w1_init(); w1_write(0xcc); //发转换命令 w1_write(0x44); //启动 delay_ms(750); w1_init(); w1_write(0xcc); //读 w1_write(0xbe); teml=w1_read(); temh=w1_read(); delay_ms(750); //延时 tem=temh; tem=tem*256; tem|=teml; tt=tem*0.0625; tem=tt*10+0.5; ///tem=ds1820_read_spd(0xbe); ///tem=0x16; a=tem/100; b=tem%100/10; //a=4;b=5; display(1,a); delay_ms(2); //延时 display(2,b); } }
|