单片机驱动DS1302时间DS18B20温度12864液晶显示完整程序设计
总线上读取一个字节
byte read_byte(void)
{
byte i;
byte value = 0;
for (i=8;i>0;i--)
{
value>>=1;
KEY = 0; // pull DQ low to start timeslot
KEY = 1; // then return high
delay1(1); //for (i=0; i3; i++);
if(KEY)value|=0x80;
delay1(6); // wait for rest of timeslot
}
return(value);
}
//向 1-WIRE 总线上写一个字节
void write_byte(char val)
{
byte i;
for (i=8; i>0; i--) // writes byte, one bit at a time
{
KEY = 0; // pull DQ low to start timeslot
KEY = val0x01;
delay1(5); // hold value for remainder of timeslot
KEY = 1;
val=val/2;
}
delay1(5);
}
//读取温度
float wendu(void)
{
float tem;
union{
byte c[2];
int x;
}temp;
ow_reset();
write_byte(0xCC); // Skip ROM
write_byte(0xBE); // Read Scratch Pad
temp.c[1]=read_byte(); //lsd
temp.c[0]=read_byte(); //msd
ow_reset();
write_byte(0xCC); //Skip ROM
write_byte(0x44); // Start Conversion
tem=0.0;
if(temp.x 0x01) tem+=0.0625;temp.x>>=1;
if(temp.x 0x01) tem+=0.125;temp.x>>=1;
if(temp.x 0x01) tem+=0.25;temp.x>>=1;
if(temp.x 0x01) tem+=0.5;temp.x>>=1;
tem+=temp.x;
return tem;
}
void cs1_lcd(){ ////////选择左边
bit a=1;
cs1=a;
cs2=!a;
}
void cs2_lcd(){ ////////选择右边
bit a=1;
cs1=!a;
cs2=a;
}
void busy_lcd(){//////判断忙
bit a=1;
di=!a;
rw=a;
e=a;
while(P07==a);
}
w_lcd(unsigned b){ ///写a到12864
bit a=1;
busy_lcd();
rw =!a;
di =a;
P0=b;
e=a;
e=!a;
}
void dis_lcd(){//打开显示选择第一行显示
bit a=1;
busy_lcd();
rw=!a;
di=!a;
P0=0x3f;
e=a;
e=!a;
P0=0xc0;
e=a;
e=!a;
}
y_lcd(unsigned a){///由A确定y轴
bit b=1;
busy_lcd();
rw=!b;
di=!b;
P0=a;
P07=b;
P06=!b;
P05=b;
P04=b;
P03=b;
e=b;
e=!b;
}
x_lcd(unsigned a){//由a确定X轴
bit b=1;
busy_lcd();
rw=!b;
di=!b;
P0=a;
P07=!b;
P06=b;
e=b;
e=!b;
}
void clr_lcd(){///清屏
bit a=0;
unsigned x,y,date,i;
cs1_lcd();
date=0x00;
for(i=0;i2;i++){
for(y=0;y8;y++)
for(x=0;x64;x++){
x_lcd(x);
y_lcd(y);
w_lcd(date);
}
cs2_lcd();}
}
unsigned char code shu[18][16]={///0到9数字
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},//0
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},//1
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},//2
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},//3
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},///4
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},//5
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},//6
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},//7
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},//8
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00},//9
{0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},// :
{0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},// /
};
unsigned char code shu1[9][32]={///
{0x02,0x42,0x42,0xFE,0x42,0x42,0xFE,0x02,0x02,0xFA,0x02,0x02,0xFE,0x00,0x00,0x00,0x08,0x08,0x08,0x07,0x84,0x44,0x23,0x18,0x06,0x01,0x3E,0x40,0x43,0x40,0x78,0x00},//现12
{0x00,0x04,0x04,0xC4,0x64,0x9C,0x87,0x84,0x84,0xE4,0x84,0x84,0x84,0x84,0x04,0x00,0x04,0x02,0x01,0x7F,0x00,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x00},//在 13
{0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00},//时 14
{0x00,0xF8,0x01,0x06,0x00,0xF0,0x92,0x92,0x92,0x92,0xF2,0x02,0x02,0xFE,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x07,0x04,0x04,0x04,0x04,0x07,0x40,0x80,0x7F,0x00,0x00},//间 15
{0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,0x48,0x46,0x41,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x49,0x41,0x40,0x00},//星 16
{0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,0x00},//期 17
{0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00},//温18
{0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00},//度19
};
单片机 DS1302 DS18B20 12864液晶显示 相关文章:
- FPGA的DSP性能揭秘(06-16)
- 基于单片机通用引脚的软件UART设计(10-16)
- 分时操作系统思想在单片机中的具体应用 (10-30)
- 基于AT89C51+DSP的双CPU伺服运动控制器的研究(05-26)
- 关于RTX51 TINY的分析与探讨(05-30)
- 基于MC9S12DGl28单片机的智能寻迹车设计(04-03)