我做的万年历(m8 1302 18b20 1602)
mega8+1602+1302+18b20做的电子万年历编程环境是cvavr
还望各位高手多多指点
先上图
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_543706.jpg
(原文件名:20100404001.jpg)
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_543707.jpg
(原文件名:20100404002.jpg)
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_543708.jpg
(原文件名:20100404003.jpg)
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_543709.jpg
(原文件名:20100404009.jpg)
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_543710.jpg
(原文件名:20100404010.jpg)
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_543711.jpg
(原文件名:20100404011.jpg)
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_543712.jpg
(原文件名:20100404012.jpg)
1602
#define RSPORTD.7
#define RWPORTD.6
#define ENPORTD.5
#define LCD_DAT PORTC
unsigned char lcd_buffer[];
void wr_lcd_inf(unsigned char com,unsigned char inf)
{
unsigned char com_temp,data_temp;
DDRD=0b11100001;//lcd控制引脚
if(com==0)
{
delay_ms(3);
RS=0;
RW=0;
EN=0;
DDRC=0x0f;//lcd数据引脚
com_temp=inf;
LCD_DAT=0x0f&com_temp>>4;//消除对PORTC.4的影响
EN=1;
EN=0;
com_temp=inf;
LCD_DAT=0x0f&com_temp;
EN=1;
EN=0;
}
else
{
delay_ms(3);
RS=1;
RW=0;
EN=0;
DDRC=0x0f;//lcd数据引脚
data_temp=inf;
LCD_DAT=0x0f&data_temp>>4;
EN=1;
EN=0;
data_temp=inf;
LCD_DAT=0x0f&data_temp;
EN=1;
EN=0;
}
}
void wr_address(unsigned char x,unsigned char y)
{
unsigned char address;
if(y>0)
address=0xc0+x;
else
address=0x80+x;
wr_lcd_inf(0,address);
}
void wr_lcd_word(unsigned char x,unsigned char y,unsigned char s)
{
wr_address(x,y);
wr_lcd_inf(1,s);
}
void wr_lcd_string(unsigned char x,unsigned char y,unsigned char *s)
{
wr_address(x,y);
while(*s)
{
wr_lcd_inf(1,*s);
s++;
}
}
void lcd_init()
{
wr_lcd_inf(0,0x28);//设置为4线,2行,5*7字型
wr_lcd_inf(0,0x06);//AC+1
wr_lcd_inf(0,0x0c);//开启显示屏,光标关闭,不闪烁
wr_lcd_inf(0,0x01);//清楚显示屏
}
18b20
#defineTEMP_DAT PORTD.4
unsigned char buffer[];//显示字符串缓存
unsigned char temper;
void ds18b20_init(void)
{
TEMP_DAT=1;
DDRD.4=0;
delay_us(50);
TEMP_DAT=0;
DDRD.4=1;//设置输出口
delay_us(900);
TEMP_DAT=1;
DDRD.4=0;//设置输出口
delay_us(50);
while(PIND.4)
{
wr_lcd_inf(0,0x01);
sprintf(buffer,"no ds18b20");
wr_lcd_string(2,0,buffer);
}
delay_us(500);
TEMP_DAT=1;
DDRD.4=0;
}
void wr_ds18b20_dat(unsigned char ds18b20_dat)//写数据
{
unsigned char i;
for(i=0;i<8;i++)
{
TEMP_DAT=1;
DDRD.4=1;
delay_us(10);
TEMP_DAT=0;
delay_us(10);
TEMP_DAT=0x1&ds18b20_dat;//与
delay_us(60);
ds18b20_dat=ds18b20_dat>>1;
}
TEMP_DAT=1;
DDRD.4=1;
delay_us(30);
}
unsigned char re_ds18b20_dat()
{
unsigned char i,ds18b20_dat=0;
for(i=0;i<8;i++)
{
TEMP_DAT=1;
DDRD.4=1;
delay_us(10);
ds18b20_dat=ds18b20_dat>>1;
TEMP_DAT=0;
DDRD.4=1;
delay_us(10);
TEMP_DAT=1;
DDRD.4=0;
delay_us(10);
if(PIND.4)
{
ds18b20_dat=0x80|ds18b20_dat;
}
delay_us(60);
}
TEMP_DAT=1;
DDRD.4=1;
delay_us(30);
return ds18b20_dat;
}
void set_ds18b20()//设定精度
{
ds18b20_init();
wr_ds18b20_dat(0xcc);
wr_ds18b20_dat(0x4e);
wr_ds18b20_dat(0x00);
wr_ds18b20_dat(0x00);
wr_ds18b20_dat(0x7f);//精度为12位
}
unsigned int get_ds18b20()
{
unsigned char teml,temh,wm;
unsigned int warm, cold;
set_ds18b20();
ds18b20_init();
wr_ds18b20_dat(0xcc);
wr_ds18b20_dat(0x44);//开始转换
delay_ms(1000);
ds18b20_init();
wr_ds18b20_dat(0xcc);//跳过ROM
wr_ds18b20_dat(0xbe);//读可擦写芯片(9 byte)
teml=re_ds18b20_dat();//低8位
temh=re_ds18b20_dat();//高8位
wm=temh;
wm=wm>>7;
if(!wm)
{
temh&=0b00000111;
warm=(unsigned int)((temh*256+teml)*0.0625*100);
return warm;
}
else
{
temh&=0b00000111;
cold=(unsigned int)((~(temh*256+teml)+1)*0.0625*100);
cold+=20000; //0下-号显示标记
return cold;
}
}
void trans_ds18b20()
{
unsigned int T;
T=get_ds18b20();
temper=T/10000+48;
temper=T/1000%10+48;
temper=T/100%10+48;
temper=T/10%10+48;
temper=T%10+48;
}
1302
#define SCLK PORTB.0
#define RST PORTB.1
#define IO PORTB.2
unsigned char time;
void ds1302_wdat(unsigned char ds1302_wdat)
{
unsigned char i;
for(i=0;i<8;i++)
{
IO=0;
DDRB.2=1;
SCLK=0;
DDRB.0=1;
if(ds1302_wdat&0x01)//与
IO=1;
SCLK=1;
ds1302_wdat=ds1302_wdat>>1;
}
}
unsigned char ds1302_rdat()
{
unsigned char i,ds1302_dat=0;
for(i=0;i<8;i++)
{
DDRB.2=0;
IO=1;
DDRB.0=1;
SCLK=1;
SCLK=0;
ds1302_dat=ds1302_dat>>1;
if(PINB.2)
ds1302_dat=ds1302_dat|0b10000000;//或
}
return(ds1302_dat);
}
unsigned char re_ds1302(unsigned char ds1302_address)
{
unsigned char ds1302_dat;
DDRB.1=1;
RST=0;
DDRB.0=1;
SCLK=0;
RST=1;
ds1302_wdat(ds1302_address);
ds1302_dat=ds1302_rdat();
RST=0;
return(ds1302_dat);
}
void wr_ds1302(unsigned char ds1302_address,unsigned char ds1302_dat)
{
DDRB.1=1;
RST=0;
DDRB.0=1;
SCLK=0;
RST=1;
ds1302_wdat(ds1302_address);
ds1302_wdat(ds1302_dat);
RST=0;
}
/*
void set_ds1302()
{
wr_ds1302(0x8e,0x00);
ds1302_wdat(0xbe);
ds1302_wdat(0x50);
ds1302_wdat(0x00);
ds1302_wdat(0x00);
ds1302_wdat(0x02);
ds1302_wdat(0x04);
ds1302_wdat(0x05);
ds1302_wdat(0x10);
ds1302_wdat(0x8e);
}
*/
void set_ds1302()
{
wr_ds1302(0x8e,0x80);
wr_ds1302(0x80,0x50);
wr_ds1302(0x82,0x59);
wr_ds1302(0x84,0x22);
wr_ds1302(0x86,0x02);
wr_ds1302(0x88,0x04);
wr_ds1302(0x8a,0x05);
wr_ds1302(0x8c,0x10);
wr_ds1302(0x8e,0x80);
wr_ds1302(0x90,0xab);
}
void read_ds1302()
{
time=re_ds1302(0x81);//秒
time=re_ds1302(0x83);//分
time=re_ds1302(0x85);//小时
time=re_ds1302(0x87);//日期
time=re_ds1302(0x89);//月份
time=re_ds1302(0x8b);//星期
time=re_ds1302(0x8d);//年份
}
还没有写按键程序
下面是pcb和程序
点击此处下载 ourdev_543690.rar(文件大小:17K) (原文件名:avr mega8数字表.rar)
点击此处下载 ourdev_543691.rar(文件大小:94K) (原文件名:mega8.rar) 棒est! 记号 mark mark 记号 mark 记下! 楼主 很猛啊, 我也想做一个,不知楼主可否指教一二呢?
先谢谢啦。 楼主真有钱,下载器都做俩,用一个看一个! 不错!Mark! 回复【楼主位】b57203493
-----------------------------------------------------------------------
牛》 mark!!!
热转印做得很漂亮 void set_ds1302()
{
wr_ds1302(0x8e,0x80);//这里应该写0x00吧
wr_ds1302(0x80,0x50);
wr_ds1302(0x82,0x59);
wr_ds1302(0x84,0x22);
wr_ds1302(0x86,0x02);
wr_ds1302(0x88,0x04);
wr_ds1302(0x8a,0x05);
wr_ds1302(0x8c,0x10);
wr_ds1302(0x8e,0x80);
wr_ds1302(0x90,0xab);
} 回复【13楼】zj_t
void set_ds1302()
{
wr_ds1302(0x8e,0x80);//这里应该写0x00吧
wr_ds1302(0x80,0x50);
wr_ds1302(0x82,0x59);
wr_ds1302(0x84,0x22);
wr_ds1302(0x86,0x02);
wr_ds1302(0x88,0x04);
wr_ds1302(0x8a,0x05);
wr_ds1302(0x8c,0x10);
wr_ds1302(0x8e,0x80);
wr_ds1302(0x90,0xab);
}
-----------------------------------------------------------------------
哦
这个是我是我使用涡流充电以后改的
所以禁止了时间的再次写入
写时间应为
void set_ds1302()
{
wr_ds1302(0x8e,0x00); wr_ds1302(0x80,0x50);
wr_ds1302(0x82,0x59);
wr_ds1302(0x84,0x22);
wr_ds1302(0x86,0x02);
wr_ds1302(0x88,0x04);
wr_ds1302(0x8a,0x05);
wr_ds1302(0x8c,0x10);
wr_ds1302(0x8e,0x80);
wr_ds1302(0x90,0xab);
} mark 日期后面再加个星期比较好。 刚刚完成1302的编程,正需要CV写的18B20程序,谢谢楼主。 我也是再弄按键程序啊 很难弄 楼主,wr_lcd_inf(1,223); wr_lcd_inf(1,'C'); 这是温度单位吗?223好像已经超出ASCII的值了吧? 回复【19楼】gshuang1
-----------------------------------------------------------------------
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_546836.png
(原文件名:截图1271400896.png)
233是是温度符号的那个圈,它与字母“c”组成温度符号 楼主:那个蜂鸣器下面的IC是做什么的? 与按键预处理有关? 回复【21楼】ldj7501
-----------------------------------------------------------------------
148是编码器,8线3线。
gs触发中断,中断扫描按键。 不错,顶一下。 楼主能否给下载器的资料我 真是强悍啊 顶 猛泰太! 楼主,pcb能不能转一下格式啊,我用的protel99se打不开啊 mark 时间精确么 这个覆铜板做的太漂亮了 终于写完了
2级菜单+调时+温度报警+高低温记录+闹铃+闹铃设定+报警温度设定
献丑
点击此处下载 ourdev_551131.rar(文件大小:184K) (原文件名:mega8.rar)
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
?Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 2010-5-1
Author: bianbo
Company :
Comments:
Chip type : ATmega8L
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
//PB0-PB7:PB0-DS1302_SCLK,PB1-DS1302_/RST,PB2-DS1302_I/O,PB3-MOSI,PB4-MISO,PB5-SCK
//PC0-PC6:PC0-LCM1602_D4,PC1-LCM1602_D5,PC2-LCM1602_D6,PC3-LCM1602_D7,PC4-BEEP,PC6-REST
//PD0-PD7:PD0-LCM1602_LED,PD1-OUT1,PD2-OUT0,PD3-GS,PD4-TEMP_DAT,PD5-LCM1602_RE,PD6-LCM1602_RW,PD7-LCM1602_RS
*****************************************************/
#include <mega8.h>
#include <delay.h>
#include <stdio.h>
#include <lcd1602.c>
#include <ds18b20.c>
#include <ds1302.c>
unsigned char menu_num,num2,num3,i,start,page,point,select,max_time,min_time,MAX=31,MIN=29,alarm_hour=19,alarm_minute=22;
unsigned int max_temper,min_temper;
unsigned char key();//键盘扫描
interrupt void ext_int1_isr(void)
{
delay_ms(80);//消除毛刺
if( start==0)
{
start=1;
while(PIND.3==0);
}
else
{
if(PIND.3==0)
{
switch(key())
{
case 0b00000110:
while(PIND.3==0);
PORTD.0=~PORTD.0;
break;
case 0b00000010:
while(PIND.3==0);
num2++;
break;
case 0b00000100:
while(PIND.3==0);
num3++;
break;
case 0b00000000:
while(PIND.3==0);
select=0;
break;
}
};
}
}
unsigned char key()//键盘扫描
{
unsigned char temp_portd;
DDRD=DDRD&0b111110011;
temp_portd=PIND&0b00000110;
return (temp_portd);
}
void temper_warning()
{
unsigned char tem;
tem=(temper-48)*10+(temper-48);
if(temper==49)
{
sprintf(lcd_buffer,"hot");
wr_lcd_string(13,1,lcd_buffer);
PORTC.4=1;
}
else
{
if(temper==50)
{
sprintf(lcd_buffer,"cold");
wr_lcd_string(12,1,lcd_buffer);
PORTC.4=1;
}
else
{
if(tem<MAX&tem>MIN)
{
sprintf(lcd_buffer," ");
wr_lcd_string(12,1,lcd_buffer);
PORTC.4=0;
}
else
{
if(tem>=MAX)
{
sprintf(lcd_buffer,"hot");
wr_lcd_string(13,1,lcd_buffer);
PORTC.4=1;
}
else
{
sprintf(lcd_buffer,"cold");
wr_lcd_string(12,1,lcd_buffer);
PORTC.4=1;
}
}
}
}
}
void time_alarm()
{
trans_ds1302();
if(tr_time==alarm_hour&&tr_time==alarm_minute)
PORTC.4=1;
}
void dis_time()
{
unsigned char TH,TL;
wr_lcd_word(1,0,'2');
wr_lcd_word(2,0,'0');
wr_lcd_word(5,0,'-');
wr_lcd_word(8,0,'-');
wr_lcd_word(6,1,':');
wr_lcd_word(9,1,':');
TH=((time&0x70)>>4)%10+48;//秒译码,消除CH
TL=(time&0x0f)%10+48;
wr_address(10,1);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
TH=((time&0xf0)>>4)%10+48;//分译码
TL=(time&0x0f)%10+48;
wr_address(7,1);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
TH=((time&0xf0)>>4)%10+48;//时译码
TL=(time&0x0f)%10+48;
wr_address(4,1);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
TH=((time&0xf0)>>4)%10+48;//日译码
TL=(time&0x0f)%10+48;
wr_address(9,0);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
TH=((time&0xf0)>>4)%10+48;//月译码
TL=(time&0x0f)%10+48;
wr_address(6,0);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
TL=(time&0x0f)%10+48;//星期译码
wr_address(12,0);
switch(TL)
{
case '7':
sprintf(lcd_buffer,"SUN");
wr_lcd_string(12,0,lcd_buffer);
break;
case '1':
sprintf(lcd_buffer,"MON");
wr_lcd_string(12,0,lcd_buffer);
break;
case '2':
sprintf(lcd_buffer,"TUES");
wr_lcd_string(12,0,lcd_buffer);
break;
case '3':
sprintf(lcd_buffer,"WED");
wr_lcd_string(12,0,lcd_buffer);
break;
case '4':
sprintf(lcd_buffer,"THURS");
wr_lcd_string(12,0,lcd_buffer);
break;
case '5':
sprintf(lcd_buffer,"FRI");
wr_lcd_string(12,0,lcd_buffer);
break;
case '6':
sprintf(lcd_buffer,"SAT");
wr_lcd_string(12,0,lcd_buffer);
break;
}
TH=((time&0xf0)>>4)%10+48;//年译码
TL=(time&0x0f)%10+48;
wr_address(3,0);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
}
void main(void)
{
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
PORTD.0=0;
DDRD.0=1;//背光i/o设为输入输出口
DDRC.4=1;//蜂鸣器i/o设为输入输出口
PORTD.0=0;
//************************************************************************************************
GICR|=0x80;//中断开
MCUCR=0x80;//中断触发方式
GIFR=0x80;//中断标志位
#asm("sei")//开放全局中断
set_ds1302();
lcd_init();
start=0;
sprintf(lcd_buffer,"HELLO!");
wr_lcd_string(5,0,lcd_buffer);
sprintf(lcd_buffer,"Press Any Key To Continue! ");
while(1)
{
unsigned char i,j=0;
for(i=0;i<28;i++)
{
wr_address(0,1);
while(lcd_buffer)
{
wr_lcd_inf(1,lcd_buffer);
if(start==1)
{
break;
}
}
delay_ms(500);
j=i;
if(start==1)
break;
};
if(start==1)
{
wr_lcd_inf(0,0x01);//清屏
break;
}
};
//************************************************************************************************
#asm("cli");//关闭全局中断
sprintf(lcd_buffer," By Ma Zhanwang");
wr_lcd_string(0,0,lcd_buffer);
sprintf(lcd_buffer,"Wait!");
wr_lcd_string(0,1,lcd_buffer);
wr_address(5,1);
for(i=0;i<12;i++)
{
wr_lcd_inf(1,0xa5);
delay_ms(500);
}
wr_lcd_inf(0,0x01);//清屏
//************************************************************************************************
sprintf(lcd_buffer,"1.Temperature2.Time 3.Tem Recorder 4.Time Set 5.Tem Alarm S6.Time Alarm S ");
page=0;
point=0;
menu_num=1;
select=0;
while(1)
{
wr_lcd_full(1,15,lcd_buffer+page);
wr_lcd_word(0,point,'*');
wr_lcd_word(0,~point,' ');
if(select==1)
{
wr_lcd_inf(0,0x01);//清屏
if(menu_num==1)//菜单1
{
sprintf(lcd_buffer,"Temperature");
wr_lcd_string(2,0,lcd_buffer);
num2=0;
num3=0;
GICR|=0x80;//中断开
MCUCR=0x80;//中断触发方式
GIFR=0x80;//中断标志位
#asm("sei")//开放全局中断
while(1)
{
trans_ds18b20(get_ds18b20());
if(num2==1)
{
wr_lcd_word(1,1,'^');
temper_warning();
}
if(num2==2)
{
PORTC.4=0;
num2=0;
wr_lcd_word(1,1,' ');
wr_address(12,1);
wr_lcd_inf(1,' ');
wr_lcd_inf(1,' ');
wr_lcd_inf(1,' ');
wr_lcd_inf(1,' ');
}
wr_address(3,1);
if(temper==49)
wr_lcd_inf(1,temper);
else
{
if(temper==50)
wr_lcd_inf(1,'-');
else
wr_lcd_inf(1,' ');
}
wr_lcd_inf(1,temper);
wr_lcd_inf(1,temper);
wr_lcd_inf(1,'.');//小数点
wr_lcd_inf(1,temper);
wr_lcd_inf(1,temper);
wr_lcd_inf(1,223);
wr_lcd_inf(1,'C');
if(select==0)
{
#asm("cli");//关闭全局中断
PORTC.4=0;
wr_lcd_inf(0,0x01);//清屏
sprintf(lcd_buffer,"1.Temperature2.Time 3.Tem Recorder 4.Time Set 5.Tem Alarm S6.Time Alarm S ");
break;
}
}
}
else if(menu_num==2)//菜单2
{
num2=0;
num3=0;
GICR|=0x80;//中断开
MCUCR=0x80;//中断触发方式
GIFR=0x80;//中断标志位
#asm("sei")//开放全局中断
while(1)
{
read_ds1302();
if(num2==1)
{
wr_lcd_word(2,1,'&');
time_alarm();
if(num3==1)
{
num3=0;
++alarm_minute;
PORTC.4=0;
}
}
if(num2==2)
{
PORTC.4=0;
wr_lcd_word(2,1,' ');
num2=0;
}
dis_time();
if(select==0)
{
#asm("cli");//关闭全局中断
wr_lcd_inf(0,0x01);//清屏
sprintf(lcd_buffer,"1.Temperature2.Time 3.Tem Recorder 4.Time Set 5.Tem Alarm S6.Time Alarm S ");
break;
}
}
}
else if(menu_num==3)//菜单3
{
GICR|=0x80;//中断开
MCUCR=0x80;//中断触发方式
GIFR=0x80;//中断标志位
#asm("sei")//开放全局中断
sprintf(lcd_buffer,"MAX:");
wr_lcd_string(0,0,lcd_buffer);
sprintf(lcd_buffer,"MIN:");
wr_lcd_string(0,1,lcd_buffer);
max_temper=get_ds18b20();
min_temper=get_ds18b20();
read_ds1302();
for(i=0;i<6;i++)
{
max_time=time;
};
for(i=0;i<6;i++)
{
min_time=time;
};
num2=0;
num3=0;
while(1)
{
unsigned int T;
T=get_ds18b20();
if(T>max_temper)
{
max_temper=T;
read_ds1302();
for(i=0;i<6;i++)
{
max_time=time;
}
};
if(T<min_temper)
{
min_temper=T;
for(i=0;i<6;i++)
{
min_time=time;
}
};
for(i=0;i<2;i++)
{
if(!i)
trans_ds18b20(max_temper);
else
trans_ds18b20(min_temper);
wr_address(4,i);
if(temper==49)
wr_lcd_inf(1,temper);
else if(temper==50)
wr_lcd_inf(1,'-');
else
wr_lcd_inf(1,' ');
wr_lcd_inf(1,temper);
wr_lcd_inf(1,temper);
wr_lcd_inf(1,'.');//小数点
wr_lcd_inf(1,temper);
wr_lcd_inf(1,temper);
wr_lcd_inf(1,223);
wr_lcd_inf(1,'C');
}
if(num2)
{
wr_lcd_inf(0,0x01);//清屏
for(i=0;i<6;i++)
{
time=max_time;
}
while(num2)
{
dis_time();
if(num2==2)
num2=0;
num3=0;
}
wr_lcd_inf(0,0x01);//清屏
}
if(num3)
{
wr_lcd_inf(0,0x01);//清屏
for(i=0;i<6;i++)
{
time=min_time;
}
while(num3)
{
dis_time();
if(num3==2)
num3=0;
num2=0;
}
wr_lcd_inf(0,0x01);//清屏
}
sprintf(lcd_buffer,"MAX:");
wr_lcd_string(0,0,lcd_buffer);
sprintf(lcd_buffer,"MIN:");
wr_lcd_string(0,1,lcd_buffer);
if(select==0)
{
#asm("cli");//关闭全局中断
wr_lcd_inf(0,0x01);//清屏
sprintf(lcd_buffer,"1.Temperature2.Time 3.Tem Recorder 4.Time Set 5.Tem Alarm S6.Time Alarm S ");
break;
}
}
}
else if(menu_num==4)//菜单4
{
unsigned char TH,TL;
wr_ds1302(0x8e,0x00);//0x80禁止写入,0x00允许写入
read_ds1302();
trans_ds1302();
dis_time();
num2=0;
num3=0;
GICR|=0x80;//中断开
MCUCR=0x80;//中断触发方式
GIFR=0x80;//中断标志位
#asm("sei")//开放全局中断
while(1)
{
if(num2==1)//年
{
time=re_ds1302(0x81);//秒
wr_ds1302(0x80,time|0x80);//停止振荡
num3=tr_time;
while(num2==1)
{
wr_lcd_word(3,0,' ');
wr_lcd_word(4,0,' ');
delay_ms(300);
if(num3>99) num3=1;
tr_time=num3;
TH=tr_time/10+48;//年译码
TL=tr_time%10+48;
wr_address(3,0);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
delay_ms(200);
}
time=((TH-48)<<4)|(TL-48);
wr_ds1302(0x8c,time);//年,高四位年十位,第四位年个位
}
else if(num2==2)//月
{
num3=tr_time;
while(num2==2)
{
wr_lcd_word(6,0,' ');
wr_lcd_word(7,0,' ');
delay_ms(300);
if(num3>12) num3=1;
tr_time=num3;
TH=tr_time/10+48;//月译码
TL=tr_time%10+48;
wr_address(6,0);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
delay_ms(200);
}
time=((TH-48)<<4)|(TL-48);
wr_ds1302(0x88,time);//月,第4秒十位,后四月分个位
}
else if(num2==3)//日
{
unsigned char max_dat;
time=re_ds1302(0x89);//月份
time=re_ds1302(0x8d);//年份
tr_time=((time&0x10)>>4)*10+(time&0x0f);//月份
tr_time=((time&0xf0)>>4)*10+(time&0x0f);//年份
switch(tr_time)
{
case 1:
max_dat=31;
break;
case 2:
if(tr_time%4==0)
max_dat=29;
else
max_dat=28;
break;
case 3:
max_dat=31;
break;
case 4:
max_dat=30;
break;
case 5:
max_dat=31;
break;
case 6:
max_dat=30;
break;
case 7:
max_dat=31;
break;
case 8:
max_dat=31;
break;
case 9:
max_dat=30;
break;
case 10:
max_dat=31;
break;
case 11:
max_dat=30;
break;
case 12:
max_dat=31;
break;
}
num3=tr_time;
while(num2==3)
{
wr_lcd_word(9,0,' ');
wr_lcd_word(10,0,' ');
delay_ms(300);
if(num3>max_dat) num3=1;
tr_time=num3;
TH=tr_time/10+48;//月译码
TL=tr_time%10+48;
wr_address(9,0);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
delay_ms(200);
}
time=((TH-48)<<4)|(TL-48);
wr_ds1302(0x86,time);//日,第5,4秒十位,后四位日个位
}
else if(num2==4)//星期
{
num3=tr_time;
while(num2==4)
{
wr_lcd_word(12,0,' ');
wr_lcd_word(13,0,' ');
wr_lcd_word(14,0,' ');
wr_lcd_word(15,0,' ');
delay_ms(300);
if(num3>7) num3=1;
tr_time=num3;
TH=tr_time/10+48;
TL=tr_time%10+48;
switch(tr_time)
{
case 7:
sprintf(lcd_buffer,"SUN");
wr_lcd_string(12,0,lcd_buffer);
break;
case 1:
sprintf(lcd_buffer,"MON");
wr_lcd_string(12,0,lcd_buffer);
break;
case 2:
sprintf(lcd_buffer,"TUES");
wr_lcd_string(12,0,lcd_buffer);
break;
case 3:
sprintf(lcd_buffer,"WED");
wr_lcd_string(12,0,lcd_buffer);
break;
case 4:
sprintf(lcd_buffer,"THURS");
wr_lcd_string(12,0,lcd_buffer);
break;
case 5:
sprintf(lcd_buffer,"FRI");
wr_lcd_string(12,0,lcd_buffer);
break;
case 6:
sprintf(lcd_buffer,"SAT");
wr_lcd_string(12,0,lcd_buffer);
break;
}
delay_ms(200);
}
time=((TH-48)<<4)|(TL-48);
wr_ds1302(0x8a,time);//星期,后三位
}
else if(num2==5)//时
{
num3=tr_time;
while(num2==5)
{
wr_lcd_word(4,1,' ');
wr_lcd_word(5,1,' ');
delay_ms(300);
if(num3>23) num3=0;
tr_time=num3;
TH=tr_time/10+48;
TL=tr_time%10+48;
wr_address(4,1);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
delay_ms(200);
}
time=((TH-48)<<4)|(TL-48);
wr_ds1302(0x84,time);//时,第7 位12/24 小时标志,bit7=1,12 小时模式,bit7=0,24 小时模式,第5 位:AM/PM 定义,AP=1 下午模式,AP=0 上午模式
}
else if(num2==6)//分
{
num3=tr_time;
while(num2==6)
{
wr_lcd_word(7,1,' ');
wr_lcd_word(8,1,' ');
delay_ms(300);
if(num3>59) num3=0;
tr_time=num3;
TH=tr_time/10+48;
TL=tr_time%10+48;
wr_address(7,1);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
delay_ms(200);
}
time=((TH-48)<<4)|(TL-48);
wr_ds1302(0x82,time);//分,第6,5,4秒十位,后四位分个位
}
else if(num2==7)//秒
{
num3=tr_time&0x7f;
while(num2==7)
{
wr_lcd_word(10,1,' ');
wr_lcd_word(11,1,' ');
delay_ms(300);
if(num3>59) num3=0;
tr_time=num3;
TH=tr_time/10+48;
TL=tr_time%10+48;
wr_address(10,1);
wr_lcd_inf(1,TH);
wr_lcd_inf(1,TL);
delay_ms(200);
}
time=((TH-48)<<4)|(TL-48)|0x80;
wr_ds1302(0x80,time);//秒,第7位ch=0工作允许,第6,5,4秒十位,后四位秒个位
}
else if(num2==8)
{
time=re_ds1302(0x81);//秒
wr_ds1302(0x80,time&0x7f);//开始振荡
num2=0;
}
read_ds1302();
dis_time();
if(select==0)
{
#asm("cli");//关闭全局中断
wr_lcd_inf(0,0x01);//清屏
time=re_ds1302(0x81);//秒
wr_ds1302(0x80,time&0x7f);//开始振荡
wr_ds1302(0x8e,0x80);//0x80禁止写入,0x00允许写入
sprintf(lcd_buffer,"1.Temperature2.Time 3.Tem Recorder 4.Time Set 5.Tem Alarm S6.Time Alarm S ");
break;
}
}
}
else if(menu_num==5)//菜单5
{
unsigned char MAX_TH,MAX_TL,MIN_TH,MIN_TL;
sprintf(lcd_buffer,"Alarm Temperatue");
wr_lcd_string(0,0,lcd_buffer);
sprintf(lcd_buffer,"MAX:");
wr_lcd_string(0,1,lcd_buffer);
sprintf(lcd_buffer,"MIN:");
wr_lcd_string(8,1,lcd_buffer);
num2=0;
num3=0;
MAX_TH=MAX/10+48;
MAX_TL=MAX%10+48;
MIN_TH=MIN/10+48;
MIN_TL=MIN%10+48;
wr_address(5,1);
wr_lcd_inf(1,MAX_TH);
wr_lcd_inf(1,MAX_TL);
wr_address(13,1);
wr_lcd_inf(1,MIN_TH);
wr_lcd_inf(1,MIN_TL);
GICR|=0x80;//中断开
MCUCR=0x80;//中断触发方式
GIFR=0x80;//中断标志位
#asm("sei")//开放全局中断
while(1)
{
if(num2==1)
{
num3=MAX_TH;
while(num2==1)
{
wr_lcd_word(5,1,' ');
delay_ms(300);
if(num3>57) num3=48;
MAX_TH=num3;
wr_lcd_word(5,1,MAX_TH);
delay_ms(200);
}
MAX=(MAX_TH-48)*10+(MAX_TL-48);
}
else if(num2==2)
{
num3=MAX_TL;
while(num2==2)
{
wr_lcd_word(6,1,' ');
delay_ms(300);
if(num3>57) num3=48;
MAX_TL=num3;
wr_lcd_word(6,1,MAX_TL);
delay_ms(200);
}
MAX=(MAX_TH-48)*10+(MAX_TL-48);
}
else if(num2==3)
{
num3=MIN_TH;
while(num2==3)
{
wr_lcd_word(13,1,' ');
delay_ms(300);
if(num3>57) num3=48;
MIN_TH=num3;
wr_lcd_word(13,1,MIN_TH);
delay_ms(200);
}
MIN=(MIN_TH-48)*10+(MIN_TL-48);
}
else if(num2==4)
{
num3=MIN_TL;
while(num2==4)
{
wr_lcd_word(14,1,' ');
delay_ms(300);
if(num3>57) num3=48;
MIN_TL=num3;
wr_lcd_word(14,1,MIN_TL);
delay_ms(200);
}
MIN=(MIN_TH-48)*10+(MIN_TL-48);
}
else if(num2==5)
{
num2=0;
}
if(select==0)
{
#asm("cli");//关闭全局中断
wr_lcd_inf(0,0x01);//清屏
sprintf(lcd_buffer,"1.Temperature2.Time 3.Tem Recorder 4.Time Set 5.Tem Alarm S6.Time Alarm S ");
break;
}
}
}
else if(menu_num==6)//菜单6
{
unsigned char H_TH,H_TL,M_TH,M_TL,H;
sprintf(lcd_buffer,"Alarm Time");
wr_lcd_string(3,0,lcd_buffer);
wr_lcd_word(7,1,':');
H_TH=alarm_hour/10+48;
H_TL=alarm_hour%10+48;
M_TH=alarm_minute/10+48;
M_TL=alarm_minute%10+48;
wr_lcd_word(5,1,H_TH);
wr_lcd_word(6,1,H_TL);
wr_lcd_word(8,1,M_TH);
wr_lcd_word(9,1,M_TL);
num2=0;
num3=0;
GICR|=0x80;//中断开
MCUCR=0x80;//中断触发方式
GIFR=0x80;//中断标志位
#asm("sei")//开放全局中断
while(1)
{
if(num2==1)
{
num3=H_TH;
while(num2==1)
{
wr_lcd_word(5,1,' ');
delay_ms(300);
if(num3>50) num3=48;
H_TH=num3;
wr_lcd_word(5,1,H_TH);
delay_ms(200);
}
alarm_hour=(H_TH-48)*10+(H_TL-48);
}
else if(num2==2)
{
if(H_TH==50)
H=51;
else
H=57;
num3=H_TL;
while(num2==2)
{
wr_lcd_word(6,1,' ');
delay_ms(300);
if(num3>H) num3=48;
H_TL=num3;
wr_lcd_word(6,1,H_TL);
delay_ms(200);
}
alarm_hour=(H_TH-48)*10+(H_TL-48);
}
else if(num2==3)
{
num3=M_TH;
while(num2==3)
{
wr_lcd_word(8,1,' ');
delay_ms(300);
if(num3>53) num3=48;
M_TH=num3;
wr_lcd_word(8,1,M_TH);
delay_ms(200);
}
alarm_minute=(M_TH-48)*10+(M_TL-48);
}
else if(num2==4)
{
while(num2==4)
{
wr_lcd_word(9,1,' ');
delay_ms(300);
if(num3>57) num3=48;
M_TL=num3;
wr_lcd_word(9,1,M_TL);
delay_ms(200);
}
alarm_minute=(M_TH-48)*10+(M_TL-48);
}
else if(num2==5)
{
num2=0;
}
if(select==0)
{
#asm("cli");//关闭全局中断
wr_lcd_inf(0,0x01);//清屏
sprintf(lcd_buffer,"1.Temperature2.Time 3.Tem Recorder 4.Time Set 5.Tem Alarm S6.Time Alarm S ");
break;
}
}
}
}
else
{
if(PIND.3==0)
{
switch(key())
{
case 0b00000110:
while(PIND.3==0);
PORTD.0=~PORTD.0;
break;
case 0b00000010:
while(PIND.3==0);
page+=30;
menu_num+=2;
if(page>60)
{
page=0;
menu_num-=6;
}
break;
case 0b00000100:
while(PIND.3==0);
menu_num++;
point=~point;
if(menu_num>(page/30+1)*2)
menu_num-=2;
break;
case 0b00000000:
while(PIND.3==0);
select=1;
//wr_lcd_word(0,point,menu_num+48);
//delay_ms(1000);
break;
}
}
}
}
} 牛!! 回复【楼主位】b57203493
-----------------------------------------------------------------------
楼主能不能重新发一份pcb的图啊,附件里的pcb没办法用,急用,感谢 LZ能发个原理图来看看,三极管是干啥用的? 真不错。支持 回复【楼主位】b57203493
-----------------------------------------------------------------------
为啥我照做显示不了,能指教一下不 嗯哈 WANCHANG 调一下1602的电阻 实验成功,谢谢 看看 检测不到18b20,这是啥原因? 回复【39楼】b57203493
-----------------------------------------------------------------------
检测不到18b20,这是啥原因?谢谢。。。 mark 排阻是10K还是470欧?? 温度出来了,就是不变,问题挺多的,0.0 热转印做得很漂亮
页:
[1]