các cao thủ xem giúp em chương trình này sai ở đâu với. em cám ơn!
#include <AT89x52.h>
//#include <Delay.h>
#include "intrins.h"
// Chuong trinh chuan tinh den ngay 11/05/2012
#define dataso P1_2//P1_0
#define clockso P1_0//P1_1
#define latchso P1_1//P1_2
#define phim1 P2_3//tang gia tri cham tien do
#define phim2 P2_5// giam gia tri LED
#define phim3 P2_7//tang chi so
#define phim4 P2_6//tang gia tri LED
#define phim5 P2_4// giam gia tri cham tien do
#define phim6 P2_2// loi line reset gia tri ve 0
#define SDA P0_4//P0_0
#define SCL P0_3//P0_1
#define On 1
#define Off 0
// DS1307
#define psec 0x00
#define pmin 0x01
#define phour 0x02
#define pday 0x03
#define pdate 0x04
#define pmonth 0x05
#define pyear 0x06
#define pcontrol 0x07
#define stbangso 10
#define soled 10
unsigned char idata buffht[soled];
unsigned char code SegCode[] = //4094
{0x18,0xBD,0x68,0xA8,0x8D,0x8A,0x0A,0xBC,0x08,0x88 ,0xff,0xef};//, // 0,...,9,tat
// {0x44, 0xcf, 0x52, 0x4a, 0xc9, 0x68, 0x60, 0xce, 0x40, 0x48, 0xff, 0xfb};//, // 0,...,9,tat
//0x04, 0x8f, 0x12, 0x0a, 0x89, 0x28, 0x20, 0x8e, 0x00, 0x08, 0xff}; // 0.,...,9.,tat // dau gach duoi: 0xbf
unsigned char code SegCode_cham[] =
{0x10,0xB5,0x60,0xA0,0x85,0x82,0x02,0xB4,0x00,0x80 };
unsigned char code SegCode_test[] = //4094
{0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};
unsigned char tam1=0,tam2=0,tam3=0,tam4=0,tam5=0,tam6=0;
unsigned char i,adr_so,chiso,dem;
unsigned char gio,phut,giay,ngay,thang,nam,ngay1,ngay2,bienngay1 ,bienngay2,bienngay3;
unsigned int num,bienngay;
unsigned int linerank;
bit nhapnhay = 0;
//============= RTC DS1307 ==================
void start(void)
{
SCL=0;
SDA=1;
_nop_();_nop_();_nop_();
SCL=1;
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
SCL=1;
SDA=0;
_nop_();_nop_();_nop_();
SCL=0;
}
void stop(void)
{
SCL=0;
SDA=0;
_nop_();_nop_();_nop_();
SCL=1;
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
SCL=1;
SDA=1;
_nop_();_nop_();_nop_();
SCL=0;
}
bit write_data(unsigned char chr)
{
unsigned char temp,ack;
for(temp=0;temp<8;temp++)
{
SDA = (chr & 0x80);
SCL=1;
SCL=0;
chr=chr<<1;
}
SDA=1;
SCL=1;
ack=SDA;
SCL=0;
return(ack);
}
unsigned char convertBCD(unsigned char _data)
{
unsigned char temp;
temp=(_data/10<<4)|(_data%10&0x0F);
return temp;
}
unsigned char read_data(void)
{
unsigned char temp1,temp2=0;
for(temp1=0;temp1<8;temp1++)
{
SCL=1;
temp2=temp2<<1;
temp2=temp2|((unsigned char)(SDA));
SCL=0;
}
return(temp2);
}
void write_RTC(unsigned char address, unsigned char _data)
{
bit status;
start();
write_data(0xD0);
write_data(address);
write_data(_data);
stop();
start();
status=write_data(0xD0);
while(status) //status = 1 (NACK)
{
start();
status=write_data(0xd0);
}
}
unsigned char read_RTC(unsigned char address)
{
unsigned char k;
start();
write_data(0xD0);
write_data(address);
start();
write_data(0xD1);
k=read_data();
stop();
return ((k>>4)*10+(k&0x0F));
}
unsigned char read_RTC_chuan(unsigned char address)
{
unsigned char k;
start();
write_data(0xD0);
write_data(address);
start();
write_data(0xD1);
k=read_data();
stop();
return k;
}
void init_RTC(void)
{
// cai dat ngay theo chuan thuc te
write_RTC(0x07,0x10);
write_RTC(0x00,0x00); //0s
write_RTC(0x01,0x39); // phut :23
write_RTC(0x02,0x20); // h : 20
write_RTC(0x04,0x19); // ngay : 12
write_RTC(0x05,0x01); // thang :01
write_RTC(0x06,0x11); // nam : 2011/
//write_RTC(stbangso,10);
//write_RTC(stbangso+1,0);
//write_RTC(stbangso+2,0);
}
//////End DS1307//////////
////////////////////////////////////////////
void quetled (void)
{
unsigned char led1, led2, t;
// doc lich!
/*giay =read_RTC(0x00);
phut =read_RTC(0x01);
gio =read_RTC(0x02);
ngay =read_RTC(0x04);
thang=read_RTC(0x05);
nam =read_RTC(0x06);
/*
buffht[0] = ngay/10;
buffht[1] = ngay%10;
buffht[2] = thang/10;
buffht[3] = thang%10;
buffht[4] = nam/10;
buffht[5] = nam%10;
buffht[6] = phut/10;
buffht[7] = phut%10;
buffht[8] = giay/10;
buffht[9] = giay%10;*/
for(t=0; t<soled; t++)
{
if(chiso==t)
{
if(nhapnhay) led1 = SegCode[buffht[chiso]];
else led1 = 0xff; //tat
}
else led1 = SegCode[buffht[t]]; // giu nguyen gia tri
led2 = 0x80;
loop_time: // dich tung bit dua ra led
dataso = led1 & led2;
_nop_();_nop_();_nop_();
clockso =1;
led2 = led2 >> 1;
_nop_();_nop_();_nop_();
clockso =0;
if(led2) goto loop_time;
}
latchso =1;
_nop_();_nop_();_nop_();_nop_();
latchso =0;
}
void quetled_moi (void)
{
unsigned char led1, led2, t,t_moi;
// doc lich!
giay =read_RTC(0x00);
phut =read_RTC(0x01);
gio =read_RTC(0x02);
ngay =read_RTC(0x04);
thang=read_RTC(0x05);
nam =read_RTC(0x06);
buffht[0] = ngay/10;
buffht[1] = ngay%10;
buffht[2] = thang/10;
buffht[3] = thang%10;
buffht[4] = nam/10;
buffht[5] = nam%10;
buffht[6] = phut/10;
buffht[7] = phut%10;
buffht[8] = giay/10;
buffht[9] = giay%10;
for(t_moi=0; t_moi<soled; t_moi++)
{
if (t_moi==0){t=8;}
if (t_moi==1){t=4;}
if (t_moi==2){t=0;}
if (t_moi==3){t=5;}
if (t_moi==4){t=3;}
if (t_moi==5){t=7;}
if (t_moi==6){t=9;}
if (t_moi==7){t=2;}
if (t_moi==8){t=1;}
if (t_moi==9){t=6;}
if(chiso==t)
{
if(nhapnhay) led1 = SegCode[buffht[chiso]];
else led1 = 0xff; //tat
}
else led1 = SegCode[buffht[t]]; // giu nguyen gia tri
led2 = 0x80;
if (t==1){led1=SegCode_cham[buffht[t]];}
loop_time: // dich tung bit dua ra led
dataso = led1 & led2;
_nop_();_nop_();_nop_();
clockso =1;
led2 = led2 >> 1;
_nop_();_nop_();_nop_();
clockso =0;
if(led2) goto loop_time;
}
latchso =1;
_nop_();_nop_();_nop_();_nop_();
latchso =0;
}
void delay_ms(int i)
{
int j;
for(j=1;j<=i;j++){}
}
void main (void)
{
P0=0xff; // P0 la dau vao
P1=0x00; // P1,P2,P3 la dau ra
P2=0xff; //P2 la dau vao bam so
P3=0x00;
init_RTC();while(1){} // cai dat ngay chuan theo ngay thuc te
// cai 1 lan cho moi con DS1307
// Chay test
/*linerank=read_RTC(0x00);
while (1)
{
linerank=read_RTC(0x00);
buffht[2]=linerank%10;
buffht[1]=linerank/10;
quetled_moi();
} */
//nap DS
/*write_RTC(stbangso,10);
write_RTC(stbangso+1,0);
write_RTC(stbangso+2,0);
write_RTC(stbangso+3,0);
write_RTC(stbangso+4,0);
write_RTC(stbangso+5,0);
write_RTC(stbangso+6,0);
write_RTC(stbangso+7,0);
write_RTC(stbangso+8,0);
write_RTC(stbangso+9,0);
init_RTC();while(1){}*/
// load du lieu tu ROM ra
adr_so=stbangso;
for(i=0;i<soled;i++)
{
buffht[i]=read_RTC_chuan(adr_so);
adr_so++;
}
chiso = soled;
dem = 0; //dem thoi gian nhap nhay
while(1)
{
dem++;
if(dem==100) nhapnhay = ~nhapnhay;
if(dem>200) {nhapnhay = ~nhapnhay; dem=0;}
phut =read_RTC(0x04);////////doc trang thai chuyen doi tang
/////0x04 ngay; 0x00 giay;0x01 phut;0x02 gio
ngay1=read_RTC_chuan(stbangso+12);
ngay2=read_RTC_chuan(stbangso+13);
if (phut != ((ngay1*10)+ngay2))
{
write_RTC(stbangso+12,phut/10);
write_RTC(stbangso+13,phut%10);
bienngay1=read_RTC_chuan(stbangso+5);
bienngay2=read_RTC_chuan(stbangso+6);
bienngay3=read_RTC_chuan(stbangso+7);
bienngay = bienngay1*100 + bienngay2*10 + bienngay3;
bienngay++;
write_RTC(stbangso+5,(bienngay/100));
write_RTC(stbangso+6,(bienngay%100)/10);
write_RTC(stbangso+7,(bienngay%10));
buffht[5] = bienngay/100;
buffht[6] = (bienngay%100)/10;
buffht[7] = bienngay%10;
}
//quetled();
quetled_moi();
// co phim an
if ((phim1==0) | (phim2==0) | (phim3==0) | (phim4==0) | (phim5==0) | (phim6==0))
{
delay_ms(100);
if (phim3 == 0) //tang chiso
{
if (chiso == soled) chiso = 3;
else chiso++;
}
else if (phim4 == 0)//tang gia tri cuar LED
{
if (chiso != soled)
{
if (buffht[chiso] >= 9) buffht[chiso] = 0;
else buffht[chiso] = buffht[chiso] + 1;
}
adr_so = stbangso + chiso;
write_RTC(adr_so,buffht[chiso]);
}
else if (phim2 == 0)//giam gia tri cua LED
{
if (chiso != soled)
{
if (buffht[chiso] == 0) buffht[chiso] = 9;
else buffht[chiso] = buffht[chiso] - 1;
}
adr_so = stbangso + chiso;
write_RTC(adr_so,buffht[chiso]);
}
else if (phim6 == 0)//co loi line reset so ngay ve 0
{
buffht[5] = 0;
write_RTC(stbangso+5,0);
buffht[6] = 0;
write_RTC(stbangso+6,0);
buffht[7] = 0;
write_RTC(stbangso+7,0);
num = buffht[8]*10 + buffht[9];
if (num == 99) num = 0;
else num++;
buffht[8] = (num%100)/10;
write_RTC(stbangso+8,buffht[8]);
buffht[9] = num%10;
write_RTC(stbangso+9,buffht[9]);
}
else if (phim1 == 0)//tang gia tri cham tien do
{
if (buffht[0] == 10)
{
num = buffht[1]*10 + buffht[2];
if (num == 99) num = 0;
else num++;
}
else if (buffht[0] == 11)
{
num = buffht[1]*10 + buffht[2];
if (num == 1)
{
num = 0;
buffht[0] = 10;
}
else num--;
}
write_RTC(stbangso,buffht[0]);
buffht[1] = num/10;
write_RTC(stbangso+1,buffht[1]);
buffht[2] = num%10;
write_RTC(stbangso+2,buffht[2]);
}
else if (phim5 == 0)// giam gia tri cham tien do
{
if (buffht[0] == 10)
{
num = buffht[1]*10 + buffht[2];
if (num == 0)
{
num = 1;
buffht[0] = 11;
}
else num--;
}
else if (buffht[0] == 11)
{
num = buffht[1]*10 + buffht[2];
if (num == 99)
{
num = 0;
buffht[0] = 10;
}
else num++;
}
write_RTC(stbangso,buffht[0]);
buffht[1] = num/10;
write_RTC(stbangso+1,buffht[1]);
buffht[2] = num%10;
write_RTC(stbangso+2,buffht[2]);
}
//quetled_moi();
while((phim1==0) | (phim2==0) | (phim3==0) | (phim4==0) | (phim5==0) | (phim6==0)); // doi thoat phim
delay_ms(500);
while((phim1==0) | (phim2==0) | (phim3==0) | (phim4==0) | (phim5==0) | (phim6==0)); // doi thoat phim
delay_ms(500);
}
}// while (1)
} // of main
#include <AT89x52.h>
//#include <Delay.h>
#include "intrins.h"
// Chuong trinh chuan tinh den ngay 11/05/2012
#define dataso P1_2//P1_0
#define clockso P1_0//P1_1
#define latchso P1_1//P1_2
#define phim1 P2_3//tang gia tri cham tien do
#define phim2 P2_5// giam gia tri LED
#define phim3 P2_7//tang chi so
#define phim4 P2_6//tang gia tri LED
#define phim5 P2_4// giam gia tri cham tien do
#define phim6 P2_2// loi line reset gia tri ve 0
#define SDA P0_4//P0_0
#define SCL P0_3//P0_1
#define On 1
#define Off 0
// DS1307
#define psec 0x00
#define pmin 0x01
#define phour 0x02
#define pday 0x03
#define pdate 0x04
#define pmonth 0x05
#define pyear 0x06
#define pcontrol 0x07
#define stbangso 10
#define soled 10
unsigned char idata buffht[soled];
unsigned char code SegCode[] = //4094
{0x18,0xBD,0x68,0xA8,0x8D,0x8A,0x0A,0xBC,0x08,0x88 ,0xff,0xef};//, // 0,...,9,tat
// {0x44, 0xcf, 0x52, 0x4a, 0xc9, 0x68, 0x60, 0xce, 0x40, 0x48, 0xff, 0xfb};//, // 0,...,9,tat
//0x04, 0x8f, 0x12, 0x0a, 0x89, 0x28, 0x20, 0x8e, 0x00, 0x08, 0xff}; // 0.,...,9.,tat // dau gach duoi: 0xbf
unsigned char code SegCode_cham[] =
{0x10,0xB5,0x60,0xA0,0x85,0x82,0x02,0xB4,0x00,0x80 };
unsigned char code SegCode_test[] = //4094
{0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};
unsigned char tam1=0,tam2=0,tam3=0,tam4=0,tam5=0,tam6=0;
unsigned char i,adr_so,chiso,dem;
unsigned char gio,phut,giay,ngay,thang,nam,ngay1,ngay2,bienngay1 ,bienngay2,bienngay3;
unsigned int num,bienngay;
unsigned int linerank;
bit nhapnhay = 0;
//============= RTC DS1307 ==================
void start(void)
{
SCL=0;
SDA=1;
_nop_();_nop_();_nop_();
SCL=1;
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
SCL=1;
SDA=0;
_nop_();_nop_();_nop_();
SCL=0;
}
void stop(void)
{
SCL=0;
SDA=0;
_nop_();_nop_();_nop_();
SCL=1;
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
SCL=1;
SDA=1;
_nop_();_nop_();_nop_();
SCL=0;
}
bit write_data(unsigned char chr)
{
unsigned char temp,ack;
for(temp=0;temp<8;temp++)
{
SDA = (chr & 0x80);
SCL=1;
SCL=0;
chr=chr<<1;
}
SDA=1;
SCL=1;
ack=SDA;
SCL=0;
return(ack);
}
unsigned char convertBCD(unsigned char _data)
{
unsigned char temp;
temp=(_data/10<<4)|(_data%10&0x0F);
return temp;
}
unsigned char read_data(void)
{
unsigned char temp1,temp2=0;
for(temp1=0;temp1<8;temp1++)
{
SCL=1;
temp2=temp2<<1;
temp2=temp2|((unsigned char)(SDA));
SCL=0;
}
return(temp2);
}
void write_RTC(unsigned char address, unsigned char _data)
{
bit status;
start();
write_data(0xD0);
write_data(address);
write_data(_data);
stop();
start();
status=write_data(0xD0);
while(status) //status = 1 (NACK)
{
start();
status=write_data(0xd0);
}
}
unsigned char read_RTC(unsigned char address)
{
unsigned char k;
start();
write_data(0xD0);
write_data(address);
start();
write_data(0xD1);
k=read_data();
stop();
return ((k>>4)*10+(k&0x0F));
}
unsigned char read_RTC_chuan(unsigned char address)
{
unsigned char k;
start();
write_data(0xD0);
write_data(address);
start();
write_data(0xD1);
k=read_data();
stop();
return k;
}
void init_RTC(void)
{
// cai dat ngay theo chuan thuc te
write_RTC(0x07,0x10);
write_RTC(0x00,0x00); //0s
write_RTC(0x01,0x39); // phut :23
write_RTC(0x02,0x20); // h : 20
write_RTC(0x04,0x19); // ngay : 12
write_RTC(0x05,0x01); // thang :01
write_RTC(0x06,0x11); // nam : 2011/
//write_RTC(stbangso,10);
//write_RTC(stbangso+1,0);
//write_RTC(stbangso+2,0);
}
//////End DS1307//////////
////////////////////////////////////////////
void quetled (void)
{
unsigned char led1, led2, t;
// doc lich!
/*giay =read_RTC(0x00);
phut =read_RTC(0x01);
gio =read_RTC(0x02);
ngay =read_RTC(0x04);
thang=read_RTC(0x05);
nam =read_RTC(0x06);
/*
buffht[0] = ngay/10;
buffht[1] = ngay%10;
buffht[2] = thang/10;
buffht[3] = thang%10;
buffht[4] = nam/10;
buffht[5] = nam%10;
buffht[6] = phut/10;
buffht[7] = phut%10;
buffht[8] = giay/10;
buffht[9] = giay%10;*/
for(t=0; t<soled; t++)
{
if(chiso==t)
{
if(nhapnhay) led1 = SegCode[buffht[chiso]];
else led1 = 0xff; //tat
}
else led1 = SegCode[buffht[t]]; // giu nguyen gia tri
led2 = 0x80;
loop_time: // dich tung bit dua ra led
dataso = led1 & led2;
_nop_();_nop_();_nop_();
clockso =1;
led2 = led2 >> 1;
_nop_();_nop_();_nop_();
clockso =0;
if(led2) goto loop_time;
}
latchso =1;
_nop_();_nop_();_nop_();_nop_();
latchso =0;
}
void quetled_moi (void)
{
unsigned char led1, led2, t,t_moi;
// doc lich!
giay =read_RTC(0x00);
phut =read_RTC(0x01);
gio =read_RTC(0x02);
ngay =read_RTC(0x04);
thang=read_RTC(0x05);
nam =read_RTC(0x06);
buffht[0] = ngay/10;
buffht[1] = ngay%10;
buffht[2] = thang/10;
buffht[3] = thang%10;
buffht[4] = nam/10;
buffht[5] = nam%10;
buffht[6] = phut/10;
buffht[7] = phut%10;
buffht[8] = giay/10;
buffht[9] = giay%10;
for(t_moi=0; t_moi<soled; t_moi++)
{
if (t_moi==0){t=8;}
if (t_moi==1){t=4;}
if (t_moi==2){t=0;}
if (t_moi==3){t=5;}
if (t_moi==4){t=3;}
if (t_moi==5){t=7;}
if (t_moi==6){t=9;}
if (t_moi==7){t=2;}
if (t_moi==8){t=1;}
if (t_moi==9){t=6;}
if(chiso==t)
{
if(nhapnhay) led1 = SegCode[buffht[chiso]];
else led1 = 0xff; //tat
}
else led1 = SegCode[buffht[t]]; // giu nguyen gia tri
led2 = 0x80;
if (t==1){led1=SegCode_cham[buffht[t]];}
loop_time: // dich tung bit dua ra led
dataso = led1 & led2;
_nop_();_nop_();_nop_();
clockso =1;
led2 = led2 >> 1;
_nop_();_nop_();_nop_();
clockso =0;
if(led2) goto loop_time;
}
latchso =1;
_nop_();_nop_();_nop_();_nop_();
latchso =0;
}
void delay_ms(int i)
{
int j;
for(j=1;j<=i;j++){}
}
void main (void)
{
P0=0xff; // P0 la dau vao
P1=0x00; // P1,P2,P3 la dau ra
P2=0xff; //P2 la dau vao bam so
P3=0x00;
init_RTC();while(1){} // cai dat ngay chuan theo ngay thuc te
// cai 1 lan cho moi con DS1307
// Chay test
/*linerank=read_RTC(0x00);
while (1)
{
linerank=read_RTC(0x00);
buffht[2]=linerank%10;
buffht[1]=linerank/10;
quetled_moi();
} */
//nap DS
/*write_RTC(stbangso,10);
write_RTC(stbangso+1,0);
write_RTC(stbangso+2,0);
write_RTC(stbangso+3,0);
write_RTC(stbangso+4,0);
write_RTC(stbangso+5,0);
write_RTC(stbangso+6,0);
write_RTC(stbangso+7,0);
write_RTC(stbangso+8,0);
write_RTC(stbangso+9,0);
init_RTC();while(1){}*/
// load du lieu tu ROM ra
adr_so=stbangso;
for(i=0;i<soled;i++)
{
buffht[i]=read_RTC_chuan(adr_so);
adr_so++;
}
chiso = soled;
dem = 0; //dem thoi gian nhap nhay
while(1)
{
dem++;
if(dem==100) nhapnhay = ~nhapnhay;
if(dem>200) {nhapnhay = ~nhapnhay; dem=0;}
phut =read_RTC(0x04);////////doc trang thai chuyen doi tang
/////0x04 ngay; 0x00 giay;0x01 phut;0x02 gio
ngay1=read_RTC_chuan(stbangso+12);
ngay2=read_RTC_chuan(stbangso+13);
if (phut != ((ngay1*10)+ngay2))
{
write_RTC(stbangso+12,phut/10);
write_RTC(stbangso+13,phut%10);
bienngay1=read_RTC_chuan(stbangso+5);
bienngay2=read_RTC_chuan(stbangso+6);
bienngay3=read_RTC_chuan(stbangso+7);
bienngay = bienngay1*100 + bienngay2*10 + bienngay3;
bienngay++;
write_RTC(stbangso+5,(bienngay/100));
write_RTC(stbangso+6,(bienngay%100)/10);
write_RTC(stbangso+7,(bienngay%10));
buffht[5] = bienngay/100;
buffht[6] = (bienngay%100)/10;
buffht[7] = bienngay%10;
}
//quetled();
quetled_moi();
// co phim an
if ((phim1==0) | (phim2==0) | (phim3==0) | (phim4==0) | (phim5==0) | (phim6==0))
{
delay_ms(100);
if (phim3 == 0) //tang chiso
{
if (chiso == soled) chiso = 3;
else chiso++;
}
else if (phim4 == 0)//tang gia tri cuar LED
{
if (chiso != soled)
{
if (buffht[chiso] >= 9) buffht[chiso] = 0;
else buffht[chiso] = buffht[chiso] + 1;
}
adr_so = stbangso + chiso;
write_RTC(adr_so,buffht[chiso]);
}
else if (phim2 == 0)//giam gia tri cua LED
{
if (chiso != soled)
{
if (buffht[chiso] == 0) buffht[chiso] = 9;
else buffht[chiso] = buffht[chiso] - 1;
}
adr_so = stbangso + chiso;
write_RTC(adr_so,buffht[chiso]);
}
else if (phim6 == 0)//co loi line reset so ngay ve 0
{
buffht[5] = 0;
write_RTC(stbangso+5,0);
buffht[6] = 0;
write_RTC(stbangso+6,0);
buffht[7] = 0;
write_RTC(stbangso+7,0);
num = buffht[8]*10 + buffht[9];
if (num == 99) num = 0;
else num++;
buffht[8] = (num%100)/10;
write_RTC(stbangso+8,buffht[8]);
buffht[9] = num%10;
write_RTC(stbangso+9,buffht[9]);
}
else if (phim1 == 0)//tang gia tri cham tien do
{
if (buffht[0] == 10)
{
num = buffht[1]*10 + buffht[2];
if (num == 99) num = 0;
else num++;
}
else if (buffht[0] == 11)
{
num = buffht[1]*10 + buffht[2];
if (num == 1)
{
num = 0;
buffht[0] = 10;
}
else num--;
}
write_RTC(stbangso,buffht[0]);
buffht[1] = num/10;
write_RTC(stbangso+1,buffht[1]);
buffht[2] = num%10;
write_RTC(stbangso+2,buffht[2]);
}
else if (phim5 == 0)// giam gia tri cham tien do
{
if (buffht[0] == 10)
{
num = buffht[1]*10 + buffht[2];
if (num == 0)
{
num = 1;
buffht[0] = 11;
}
else num--;
}
else if (buffht[0] == 11)
{
num = buffht[1]*10 + buffht[2];
if (num == 99)
{
num = 0;
buffht[0] = 10;
}
else num++;
}
write_RTC(stbangso,buffht[0]);
buffht[1] = num/10;
write_RTC(stbangso+1,buffht[1]);
buffht[2] = num%10;
write_RTC(stbangso+2,buffht[2]);
}
//quetled_moi();
while((phim1==0) | (phim2==0) | (phim3==0) | (phim4==0) | (phim5==0) | (phim6==0)); // doi thoat phim
delay_ms(500);
while((phim1==0) | (phim2==0) | (phim3==0) | (phim4==0) | (phim5==0) | (phim6==0)); // doi thoat phim
delay_ms(500);
}
}// while (1)
} // of main
Comment