📄 dac_backup.c
字号:
lcd_gotoxy(6,1);
display_bcd(temp.hours);
lcd_putc(":");
display_bcd(temp.minutes);
//?V????乬???乬?-?????///////
temp = hours_input(cancel);
result = check_hours(temp);
if((result==0)||(cancel)) return 0;
///DS1307???乪??////
update_time(temp);
return 1;
}
#org 0x1800
void day_of_week(struct_date_time &temp){
byte date, month,year;
int8 day_of_week=5;//monday,...,satuday,sunday = 0,....5,6
int8 std_month = 1;
int8 step_year ;
date = temp.date;
month= temp.month;
year = temp.year;
date = (date>>4)*10+(date&0x0F);
month = (month>>4)*10+(month&0x0F);
year = (year>>4)*10+(year&0x0F);
step_year = (year-1)/4;
////dich chuyen thu toi 01/01/year///
day_of_week = day_of_week + year + step_year ;
if(year>0) day_of_week++;
for(;std_month<month;std_month++){
if((std_month ==1)||(std_month ==3)||(std_month ==5)||(std_month ==7)
||(std_month ==8)||(std_month ==10)||(std_month ==12))
day_of_week = day_of_week+ 3;
else if(std_month ==2){
if( (year%4) == 0) day_of_week++;
}
else day_of_week = day_of_week + 2;
}
// tinh so ngay chenh lech///
day_of_week = day_of_week + date - 1;
day_of_week = day_of_week%7;
day_of_week = day_of_week +1;//tang len 1 thanh 1,2,...7
//update to struc_day_time
temp.day = day_of_week;
}
//#org 0x1000
void display_day(byte param,char* temp)
{
switch(param){
case 0x01:
{
temp[0]= 'M';
temp[1]= 'o';
temp[2]= 'n';
//lcd_putc("\f Mon");
break;
}
case 0x02:
{
temp[0]= 'T';
temp[1]= 'u';
temp[2]= 'e';
//lcd_putc("\f Tue");
break;
}
case 0x03:
{
temp[0]='W' ;
temp[1]= 'e';
temp[2]= 'd';
//lcd_putc("\f Wed");
break;
}
case 0x04:
{
temp[0]='T' ;
temp[1]= 'h';
temp[2]= 'u';
//lcd_putc("\f Thu");
break;
}
case 0x05:
{
temp[0]='F';
temp[1]= 'r';
temp[2]= 'i';
// lcd_putc("\f Fri");
break;
}
case 0x06:
{
temp[0]= 'S';
temp[1]= 'a';
temp[2]= 't';
// lcd_putc("\f Sat");
break;
}
case 0x07:
{
temp[0]= 'S';
temp[1]= 'u';
temp[2]= 'n';
// lcd_putc("\f Sun");
break;
}
default :
{
temp[0] = 'E';
break;
}
}
return ;
}
#org 0x1000
void display_all(struct_date_time temp)
{
char day_of[4];
display_day(temp.day,day_of);
lcd_putc("\f ");
// display_bcd(temp.day);
lcd_putc(day_of[0]);
lcd_putc(day_of[1]);
lcd_putc(day_of[2]);
lcd_putc(" ");
display_bcd(temp.date);
lcd_putc("/");
display_bcd(temp.month);
lcd_putc("/20");
display_bcd(temp.year);
lcd_putc("\n ");
display_bcd(temp.hours);
lcd_putc(":");
display_bcd(temp.minutes);
lcd_putc(":");
display_bcd(temp.seconds);
}
#org 0x1800
void send_message()
//void send_message(char asdfa[])
{
int8 i=0;
int8 j=0;
char c;
char message[] = "Alarm";
while(message[i] != '\0') {
j = putc(message[i]);
c = message[i];
i++;
}
delay_ms(10);
}
#org 0x1000
byte rd_time(byte m_addr, struct_time_eeprom &m_time)
{
byte temp;
temp = read_eeprom(m_addr);
m_time.h_hour = temp>>4;
m_time.l_hour = temp<<4>>4;
temp = read_eeprom(m_addr + 1);
m_time.h_minute = temp>>4;
m_time.l_minute = temp<<4>>4;
return m_addr;
}
///////////////////////////////
#org 0x1000
#INT_EXT
void display_time()
{
struct_date_time temp;
//--------------Bien luu phut hien tai------------
byte minute,hour,m_day;
int8 m_repeat;
int1 m_hop;
byte m_addr;
struct_time_eeprom m_time;
//--------lay gio tu RTC len---------------------------
temp = read_time();
m_addr = 0;
if(min_temp != temp.minutes)//neu phut hien tai khac voi phut truoc do
{
min_temp=temp.minutes;
while(m_addr < _end_eeprom)//kiem tra dia chi co trong khong
{
if (read_eeprom(m_addr) == 0xff)//dia chi trong
m_addr = m_addr + 3;
else //khong trong
{
rd_time(m_addr, m_time); //doc gio tu eeprom
minute =(m_time.h_minute<<4)|m_time.l_minute;
hour=(m_time.h_hour<<4)|m_time.l_hour;
//lay thu luu trong eeprom
m_day = read_eeprom(m_addr + 2);
m_repeat = m_day>>4;//kiem tra xem co lap lai khong
m_day = m_day&0x0f;
m_hop = 0;//khoi tao bien kiem tra co bang ngay khong
if((temp.hours == hour) && (temp.minutes==minute))
{
if((_monday<=temp.day)&&(temp.day<=_saturday) && ((temp.day + 1) == m_day))
{
m_hop = 1;
}
else if((temp.day == _sunday)&&(m_day == 1))
{
m_hop = 1;
}
else if(m_day == 8)
{
if ((_monday <= temp.day) && (temp.day <= _friday))
{
m_hop = 1;
m_repeat = 1;
}
}
else if(m_day == 9)
{
if ((_monday <= temp.day) && (temp.day <= _saturday))
{
m_hop = 1;
m_repeat = 1;
}
}
if(m_hop == 1)
{
output_high(PIN_C0);
send_message();
delay_ms(100);
output_low(PIN_C0);
if(m_repeat == 0)//khong co lap lai
{//xoa gio hen khong lap lai do
write_eeprom(m_addr,0xff);
}
break;
}
}
else
{
m_addr = m_addr + 3;
}
}
}//end while
}//end if
display_all(temp);
}
#org 0x1000
void xuat_thu_da_luu_1(byte m_day)
{
char s[9][7]={" Sun "," Mon "," Tue "," Wed "," Thu "," Fri "," Sat ","Mo~Fri","Mo~Sat"};
int8 i = 0;
lcd_gotoxy(6,0);
while(i < 6)
{
lcd_putc(s[m_day-1][i]);
i++;
}
}
#org 0x1000
void xuat_thu_da_luu(byte m_day)
{
byte m_weekly;
m_weekly = m_day>>4;
m_day = m_day&0x0F;
xuat_thu_da_luu_1(m_day);
lcd_gotoxy(6,0);
if (m_weekly == 1)
{
lcd_putc('+');
}
}
#org 0x1800
byte xuat_gio_da_luu(byte m_addr, step)
{
struct_time_eeprom m_time;
char m_day;
char string_time[6];
byte temp;
byte i;
while((0x00<= m_addr) && (m_addr < _end_eeprom)){//kiem tra dia chi co trong khong
temp = read_eeprom(m_addr);
if (temp == 0xff)
m_addr = m_addr + step;
else
break;
}
if(m_addr == 0xFD && step == -3){
m_addr = 0xFC;
while((0x00 <= m_addr) && (m_addr < _end_eeprom))//kiem tra dia chi co trong khong
{
temp = read_eeprom(m_addr);
if (temp == 0xff)
m_addr = m_addr + step;
else
break;
}
}
if(m_addr == 0xFF && step == 3){
m_addr = 0x00;
while(m_addr < _end_eeprom)//kiem tra dia chi co trong khong
{
temp = read_eeprom(m_addr);
if (temp == 0xff)
m_addr = m_addr + step;
else
break;
}
}
//////////////////////////////////
if(m_addr == 0xFD||m_addr==0xFF){
lcd_gotoxy(1,1);
lcd_putc("\f Not alarm!");
delay_ms(1000);
return 0xFF;
}
rd_time(m_addr, m_time);
string_time[0]=m_time.h_hour + 0x30;
string_time[1]=m_time.l_hour + 0x30;
string_time[2]=':';
string_time[3]=m_time.h_minute + 0x30;
string_time[4]=m_time.l_minute + 0x30;
string_time[5]='\0';
//hien gio trong m_time ra
i = 0;
lcd_putc("\f");
lcd_gotoxy(1,1);
lcd_putc("<-4 6->");
/////////////////////////////
lcd_gotoxy(6,1);
while(string_time[i] != 0)
{
lcd_putc(string_time[i]);
i++;
}
//hien thu da nhap
m_day = read_eeprom(m_addr + 2);
//hien footer
lcd_gotoxy(1,0);
lcd_putc("*Esc #Del");
xuat_thu_da_luu(m_day);
return m_addr;
}
#org 0x0800
byte test_eeprom()
{
byte addr_begin;
byte temp;
addr_begin = 0x00;//dia chi dau cua eeprom
while(addr_begin < _end_eeprom)//dia chi cuoi cua eeprom la 0xff, do step == 3
{
temp = read_eeprom(addr_begin);
if (temp == 0xff)//vung dia chi trong
return addr_begin;
else
addr_begin = addr_begin + 3;
}
return _end_eeprom;
}
#org 0x0800
int1 luu_gio_hen(struct_time_eeprom m_time, int1 m_weekly, byte c_input)
{
// char c;
byte m_addr;
m_addr = test_eeprom();
if(m_addr == _end_eeprom){
lcd_putc('\f');//clear LCD
lcd_gotoxy(4,1);
lcd_putc(" Memory full");
// delay_ms(1000);
return 0;//khong thuc hien chuc nang them gio
}
//goi ham save lai
write_time_eeprom(m_addr,m_time,m_weekly, c_input);
////////////
lcd_putc("\f");
lcd_gotoxy(5,1);
lcd_putc("Saved!");
delay_ms(1000);
return 1;
}
#org 0x800
int1 nhap_ngay_hen(struct_time_eeprom m_time)
{
int1 m_weekly;
int1 kt;
int1 m_cho_phep;
char c;
byte c_input;
m_weekly = 0;
c_input = 2;//mac dinh la Monday
m_cho_phep = 1;//cho phep ghi bien @
lcd_gotoxy(5,1);
lcd_putc("Monday ");
lcd_gotoxy(1,0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -