AVR128的程序——DS18B20
#include
#define uchar unsigned char
#define uint
#define DQ_IN DDRE &= ~(1 < PE6)
#define DQ_OUT DDRE |= (1 < PE6)
#define DQ_CLR PORTE &= ~(1 < PE6)
#define DQ_SET PORTE |= (1 < PE6)
#define DQ_R PINE & (1 < PE6)
uchar TempData[8];
uchar WeiMa[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar led_discode[11]={0xc0,0xf9,0xa4,0xb0,0x99,
void Delayms(uint MS)
{
} void Delayus(uint US) { } void smg_init(void) { PORTA=0XFF; DDRC=0XFF; PORTC=0XFF; DDRF|=0X0E; PORTF|=0X0E; PORTF&=0xF7; DDRB |=0X10; PORTB|=0X10; } unsigned char ds1820_reset(void) { unsigned char i; DQ_OUT; DQ_CLR; Delayus(500); DQ_SET; DQ_IN; Delayus(100); i = DQ_R; Delayus(500); return i; } unsigned char ds1820_read_byte(void) { unsigned char i; unsigned char value = 0; for (i = 0; i < 8; i++) { value >>= 1; DQ_OUT; DQ_CLR; Delayus(10); DQ_SET; DQ_IN; if (DQ_R) value|=0x80; Delayus(60); } return value; } void ds1820_write_byte(unsigned char value) { unsigned char i; for (i = 0; i < 8; i++) { DQ_OUT; DQ_CLR; Delayus(10); if (value & 0x01) DQ_SET; Delayus(100); DQ_SET; value >>= 1; } } void data_pro(uchar data) { } void display(uchar FirstBit,uchar Num) { for(i=0;i { PORTC=led_discode[10]; Delayms(2); } } void display1(uchar FirstBit,uchar Num) { for(i=0;i { PORTC=led_discode[10]; Delayms(2); } } void main(void) { uchar i,j; uint temp; smg_init(); while (1) ds1820_reset(); ds1820_write_byte(0xCC); ds1820_write_byte(0x44); Delayms(2); ds1820_reset(); ds1820_write_byte(0xCC); ds1820_write_byte(0xbe); i=ds1820_read_byte(); j=ds1820_read_byte(); temp=j*256+i; temp=temp*0.625; data_pro(temp); display(5,3); display1(6,1); } }
AVR128DS18B2 相关文章:
- AVR128的程序——DS18B20与12864液晶时钟综合运用(11-22)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)