|
#include "io430.h"
#include "18B20_pei_zhi.c"
#include "18B20.h"
#include "18B20.c"
#include "1602_pei_zhi.c"
unsigned char Set[3];
unsigned int A0=0;
void zi_ding_yi()
{
unsigned char i;
for(i=0;i<8;i++)
lcd1602_write_pic(i,pic[i]);
LCD_write_com(0xc0+0X0e);
LCD_write_data(0);
}
/******************按键识别0/1 子函数********************/
unsigned char key_scan(void)
{ unsigned char ji;
if(!(P1IN&0x01))
{
__delay_cycles(2000);
if(!(P1IN&0x01)) ji=1;
}
if(!(P1IN&0x02))
{
__delay_cycles(2000);
if(!(P1IN&0x02)) ji=2;
}
return ji;
}
//***********************************************************************
// 液晶显示温度值,xx.xC格式
//***********************************************************************
void LCD_DisplayTemp(unsigned char temp1,unsigned char temp2,unsigned char temp3)
{
LCD_write_char(0x09,1,0x30+A0);
LCD_write_char(0x0a,1,0x30+A1);
LCD_write_char(0x0b,1,0x30+A2);
LCD_write_char(0x0c,1,'.');
LCD_write_char(0x0d,1,0X30+A3);
LCD_write_char(0x0f,1,'C');
}
//***********************************************************************
// 主程序
//***********************************************************************
int main( void )
{
// Stop watchdog timer to prevent time out reset
unsigned int n=27,j,ji;
WDTCTL = WDTPW + WDTHOLD;
P2DIR = 0XFF;
P6DIR = 0xff;
Clock_Init(); //系统时钟设置
Port_init(); //系统初始化,设置IO口属性
delay_ms(100); //延时100ms
LCD_init(); //液晶参数初始化设置
LCD_clear(); //清屏
LCD_Desk();
write_str(0x80+0x40,"Set:",4);
DS18B20_Reset(); //复位D18B20
while(1)
{
ds1820_start(); //启动一次转换
ds1820_read_temp(); //读取温度数值
data_do(temp_value); //处理数据,得到要显示的值
LCD_DisplayTemp(A1,A2,A3);
zi_ding_yi();
Set[0] = n/10+0x30;
Set[1] = n%10+0x30;
Set[2] = 'C';
write_str(0x80+0x44,Set,3);
j=100*A0+10*A1+A2;
if(j>=n)
{
P2OUT=0X01;
P6OUT&=0xfe;
}
else
{
P2OUT=0X00;
P6OUT|=0xff;
}
ji=key_scan();
if(ji==1) n++;
if(ji==2) n--;
}
}
|
|