sao bác ko tich hợp them chức năng hẹn giờ vô lun ^^,
Thông báo
Collapse
No announcement yet.
Đo nhiệt độ+ Đồng hồ số hiển thị LED 7 đoạn !
Collapse
X
-
Nguyên văn bởi vietthanh123 Xem bài viếtMình có cái đồng hồ này nữa.
Mo phong(2).zip
Comment
-
Nguyên văn bởi chumanh Xem bài viếtXem chừng là diễn box 8051 đang sôi động với đồng hồ số và đo nhiệt độ các loại, hôm nay rảnh ngồi send cho ae nào quan tâm tới vấn đề này. Một cái project mình làm đầy đủ cả, bạn nào thích thì load về lắp chơi nhé.
Screen Layout:
Screen Protues:
Demo Video:
////////////////////////////
19052011017 - YouTube
/////////////////////////
Screen Capture: Attach
File Download: Attach
Code fix một số chỗ cho những ai cảm thấy code cũ có vấn đề
PHP Code:/***********************************************************
FileName: Hai-Clock-7segment.c
MCU: 8051
Xtal: 12Mhz
App: Digital Clock
Author: manhcuong.k08@gmail.com
Creat Date: 4/5/2011
Finish Date:
************************************************************/
#include <at89x52.h>
/**********************define var,port*********************/
#define data_port P2
#define sel_port P0
sbit _RW = P3^6; //
sbit _RD = P3^7; //
sbit _INT = P1^7;
sbit MODE = P3^3; //external interrupt 1
sbit DEC = P3^4; //DEC value
sbit INC = P3^5; //increment value
sbit SDA = P3^0; //I2c data line
sbit SCL = P3^1; //I2c clock line
//===================time variable============================//
struct FREE_USER{
unsigned char SEC;
unsigned char MIN;
unsigned char HOUR;
unsigned char DAY;
unsigned char DATE;
unsigned char MONTH;
unsigned char YEAR;
} _TIME ;
//============================================================//
// Byte control Real Time Cloclk DS1307 //
// //
//============================================================//
#define CONTROL_WRITE 0xd0
#define CONTROL_READ 0xd1
/*********************sub program**************************/
//==========================================================//
// //
// RTC class //
//==========================================================//
unsigned char RTC_READ(unsigned char ADRESS);
void RTC_WRITE(unsigned char ADRESS,unsigned char DAT);
void I2C_START();
void I2C_STOP();
void I2C_WRITE(unsigned char byte);
unsigned char I2C_READ();
void RTC_INI();
//==========================================================//
// //
// other //
//==========================================================//
void DISPLAY_1__(unsigned char ARRAY[],unsigned char STATUS,bit istempsensor);
void DISPLAY_2__(unsigned char ARRAY[]);
void delay(int time);
void GET_TIME();
void TIMER0_ini();
void TIMER1_ini();
void CHECK_DAY(bit get);
void CONVERT();
void GET_T();
void DISPLAY_3__(unsigned char ARRAY[]);
unsigned char code seg_code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char code HELLO[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x76,0x79,0x38,0x38,0x3f,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
unsigned char code MORNING[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x39,0x74,0x77,0x5C,0x00,0x7C,0x1C,0x5C,0x10,
0x00,0x6D,0x77,0x54,0x6F,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
unsigned char code AFTERNOON[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x39,0x74,0x77,0x5C,0x00,0x7C,0x1C,0x5C,0x10,
0x00,0x58,0x74,0x10,0x79,0x1c,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
//day on week==============================================
unsigned char code SUN[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x39,0x74,0x1c,0x00,0x54,0x74,0x77,0x31,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char code MON[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x07,0x76,0x3e,0x00,0x5b,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char code TUE[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x07,0x76,0x3e,0x00,0x4f,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char code WED[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x07,0x76,0x3e,0x00,0x66,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char code THU[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x07,0x76,0x3e,0x00,0x6d,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char code FRI[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x07,0x76,0x3e,0x00,0x7d,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char code SAT[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x07,0x76,0x3e,0x00,0x07,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char TIME_DISPLAY[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char DATE_DISPLAY[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char DAY_DISPLAY[] = {
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char code T_SENSOR[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x63,0x39,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
};
unsigned char T_value[2];
#define SHIFT 0x00
#define STOP 0x01
#define CLEAR 0x02
#define TIME_STATUS 1080
int GLOBAL_DISPLAY=0;
unsigned char IN_VISIBLE;
unsigned char CONTROL_INVISIBLE=0;
unsigned char SHIFT_CURCOR;
unsigned char counter_status;
/********************************************************/
/* Main Program */
/********************************************************/
void main()
{
/********Time Default**************
_TIME.SEC = 0x00 ;
_TIME.MIN = 0x00 ;
_TIME.HOUR = 0x12 ;
_TIME.DAY = 0x04 ;
_TIME.DATE = 0x10;
_TIME.MONTH = 0x04;
_TIME.YEAR = 0x11;
RTC_INI();
////////////////////////////////////*/
_RD = 1;
_RW = 1;
TIMER0_ini();
TIMER1_ini();
//enable global interrupt
EX1 = 1; //enable external interrupt 1
IT1 = 1; //
EX0 = 1; //enable external interrupt 1
IT0 = 1; //
EA = 1;
TR0 = 1; //timer0 run
PT1 =1;
PX0 = 1;
while(1)
{
// GET_TIME();DISPLAY_1__(TIME_DISPLAY,STOP);
switch(GLOBAL_DISPLAY)
{
case 0: DISPLAY_1__(HELLO,SHIFT,0);while(GLOBAL_DISPLAY<100)DISPLAY_1__(HELLO,STOP,0);DISPLAY_1__(HELLO,CLEAR,0);break;
case 140: DISPLAY_1__(TIME_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<600)DISPLAY_1__(TIME_DISPLAY,STOP,0);DISPLAY_1__(TIME_DISPLAY,CLEAR,0);break;
case 620: if((_TIME.HOUR>=0)&&(_TIME.HOUR<12))DISPLAY_3__(MORNING);else if(_TIME.HOUR>=12)DISPLAY_3__(AFTERNOON);break;
case 700: CHECK_DAY(1);DISPLAY_1__(DAY_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<800){CHECK_DAY(1);DISPLAY_1__(DAY_DISPLAY,STOP,0);}DISPLAY_1__(DAY_DISPLAY,CLEAR,0);break;
case 820: DISPLAY_1__(DATE_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<920)DISPLAY_1__(DATE_DISPLAY,STOP,0);DISPLAY_1__(DATE_DISPLAY,CLEAR,0);break;
case 950: GET_T();DISPLAY_1__(T_SENSOR,SHIFT,1);while(GLOBAL_DISPLAY<1050)DISPLAY_1__(T_SENSOR,STOP,1);DISPLAY_1__(T_SENSOR,CLEAR,1);break;
default: {;}break;
}
}
}
//==========================================================//
// //
// DISPLAY_3__ //
//==========================================================//
void DISPLAY_3__(unsigned char ARRAY[])
{
unsigned char counter_char=0,index,time_shift,counter;
unsigned char __SELECT__ ;
while(ARRAY[counter_char]!=0xff)
counter_char++;
for(index=0;index<counter_char-8;index++)
{
for(time_shift=0;time_shift<20;time_shift++)
{
__SELECT__ = 0x7f;
for(counter=0;counter<8;counter++)
{
data_port = ARRAY[counter+index];
sel_port = __SELECT__;
delay(7);
sel_port = 0xff; //disable all led
data_port = 0x00; //disable all led
__SELECT__ >>= 1;
__SELECT__ |= 0x80;
}
}
}
}
//==========================================================//
// //
// DISPLAY_2__ //
//==========================================================//
void DISPLAY_2__(unsigned char ARRAY[])
{
unsigned char counter;
unsigned char __SELECT__=0x7f ;
for(counter=0;counter<8;counter++)
{
sel_port = __SELECT__;
sel_port |= IN_VISIBLE;
data_port = ARRAY[counter+8];
delay(7);
sel_port = 0xff; //disable all led
data_port = 0x00; //disable all led
__SELECT__ >>= 1;
__SELECT__ |= 0x80;
}
}
//==========================================================//
// //
// DISPLAY_1__ //
//==========================================================//
void DISPLAY_1__(unsigned char ARRAY[],unsigned char _STATUS_,bit istempsensor)
{
unsigned char counter_char=0,index,time_shift,counter;
unsigned char __SELECT__ ;
while(ARRAY[counter_char]!=0xff)
counter_char++;
switch(_STATUS_)
{
case SHIFT: {
for(index=0;index<counter_char-16;index++)
{
for(time_shift=0;time_shift<20;time_shift++)
{
__SELECT__ = 0x7f;
for(counter=0;counter<8;counter++)
{
if(istempsensor)
{
if(counter+index==0x0a)
data_port = T_value[0];
else if(counter+index==0x0b)
data_port = T_value[1];
else
data_port = ARRAY[counter+index];
}
else
data_port = ARRAY[counter+index];
sel_port = __SELECT__;
delay(7);
sel_port = 0xff; //disable all led
data_port = 0x00; //disable all led
__SELECT__ >>= 1;
__SELECT__ |= 0x80;
}
}
}
break;
}
case STOP: {
__SELECT__ = 0x7f;
for(counter=0;counter<8;counter++)
{
if(istempsensor)
{
if(counter+8==0x0a)
data_port = T_value[0];
else if(counter+8==0x0b)
data_port = T_value[1];
else
data_port = ARRAY[counter+8];
}
else
data_port = ARRAY[counter+8];
sel_port = __SELECT__;
delay(7);
sel_port = 0xff; //disable all led
data_port = 0x00; //disable all led
__SELECT__ >>= 1;
__SELECT__ |= 0x80;
}
break;
}
case CLEAR: {
for(index=8;index<counter_char-8;index++)
{
for(time_shift=0;time_shift<20;time_shift++)
{
__SELECT__ = 0x7f;
for(counter=0;counter<8;counter++)
{
if(istempsensor)
{
if(counter+index==0x0a)
data_port = T_value[0];
else if(counter+index==0x0b)
data_port = T_value[1];
else
data_port = ARRAY[counter+index];
}
else
data_port = ARRAY[counter+index];
sel_port = __SELECT__;
delay(7);
sel_port = 0xff; //disable all led
data_port = 0x00; //disable all led
__SELECT__ >>= 1;
__SELECT__ |= 0x80;
}
}
}
break;
}
}
}
//==========================================================//
// //
// delay //
//==========================================================//
void delay(int time)
{
int i,j;
for(i=0;i<time;i++)
for(j=0;j<time;j++)
{;}
}
//==========================================================//
// //
// I2c_START //
//==========================================================//
void I2C_START()
{
SDA = 1;
SCL = 1;
SDA = 0;
SCL = 0;
SDA = 1;
}
//==========================================================//
// //
// I2c_STOP //
//==========================================================//
void I2C_STOP()
{
SDA = 0;
SCL = 1;
SDA = 1;
}
//==========================================================//
// //
// I2c_WRITE //
//==========================================================//
void I2C_WRITE(unsigned char byte)
{
unsigned char counter;
for(counter = 0;counter<8;counter++)
{
if(byte&0x80)
SDA=1;
else
SDA=0;
SCL = 1;
SCL = 0;
byte<<=1;
}
SDA = 1;
SCL = 1;
SCL = 0;
}
//==========================================================//
// //
// I2c_READ //
//==========================================================//
unsigned char I2C_READ()
{
unsigned char return_value=0x00,counter=8;
while(counter>0)
{
SCL=1;
return_value<<=1;
return_value|=SDA;
SCL=0;
counter--;
}
SDA = 1;
SCL = 1;
SCL = 0;
SDA = 1;
return return_value;
}
//==========================================================//
// //
// RTC_WRITE //
//==========================================================//
void RTC_WRITE(unsigned char ADDRESS,unsigned char DAT)
{
I2C_START(); //i2c start
I2C_WRITE(CONTROL_WRITE); //send control byte
I2C_WRITE(ADDRESS); //send address byte
I2C_WRITE(DAT); //send data byte
I2C_STOP(); //i2c stop
}
//==========================================================//
// //
// RTC_READ //
//==========================================================//
unsigned char RTC_READ(unsigned char ADDRESS)
{
unsigned char return_value=0x00;
I2C_START();
I2C_WRITE(CONTROL_WRITE); //send byte control write
I2C_WRITE(ADDRESS); // send byte address
I2C_START(); // restart
I2C_WRITE(CONTROL_READ); // send byte control read
return_value = I2C_READ(); //read from RTC
I2C_STOP();
return return_value;
}
//==========================================================//
// //
// RTC_INI //
//==========================================================//
void RTC_INI()
{ //ADDRESS,DATA//
RTC_WRITE(0x00,_TIME.SEC);
RTC_WRITE(0x01,_TIME.MIN);
RTC_WRITE(0x02,_TIME.HOUR);
RTC_WRITE(0x03,_TIME.DAY);
RTC_WRITE(0x04,_TIME.DATE);
RTC_WRITE(0x05,_TIME.MONTH);
RTC_WRITE(0x06,_TIME.YEAR);
RTC_WRITE(0x07,0x10);//OUT = 1,SOUT = 1;
}
//==========================================================//
// //
// GET_TIME //
//==========================================================//
void GET_TIME()
{
_TIME.SEC = RTC_READ(0x00); //GET SECOND
_TIME.MIN = RTC_READ(0x01); //GET MIN
_TIME.HOUR = RTC_READ(0x02)&0x3f; //GET HOUR
_TIME.DAY = RTC_READ(0x03); //GET DAY
_TIME.DATE = RTC_READ(0x04); //GET DATE
_TIME.MONTH = RTC_READ(0x05); //GET MONTH
_TIME.YEAR = RTC_READ(0x06); //GET YEAR
CONVERT();
}
//==========================================================//
// //
// Timer0_ini //
//==========================================================//
void TIMER0_ini()
{
TMOD = 0x01 ;//timer 0 16bit reload
TH0 = 0x00;
TL0 = 0x00;
TF0 = 0;
TR0 = 0;
ET0 = 1; //enable timer0 interrupt
}
//==========================================================//
// //
// CONVERT //
//==========================================================//
void CONVERT()
{
unsigned char temp,index=15;
//GET SECCOND
temp = _TIME.SEC;
temp&=0x0f; //get the unit
TIME_DISPLAY[index]=seg_code[temp];
index--;
temp = _TIME.SEC;
temp&=0xf0; //get the tens
temp>>=4;
TIME_DISPLAY[index]=seg_code[temp];
index--;
//SPACER
TIME_DISPLAY[index]=0x40; //
index--;
//GET MIN
temp = _TIME.MIN;
temp&=0x0f; //get the unit
TIME_DISPLAY[index]=seg_code[temp];
index--;
temp = _TIME.MIN;
temp&=0xf0; //get the tens
temp>>=4;
TIME_DISPLAY[index]=seg_code[temp];
index--;
//SPACER
TIME_DISPLAY[index]=0x40; //
index--;
//GET HOUR
temp = _TIME.HOUR;
temp&=0x0f; //get the unit
TIME_DISPLAY[index]=seg_code[temp];
index--;
temp = _TIME.HOUR;
temp&=0xf0; //get the tens
temp>>=4;
TIME_DISPLAY[index]=seg_code[temp];
index=15;
//GET YEAR
temp = _TIME.YEAR;
temp&=0x0f; //get the unit
DATE_DISPLAY[index]=seg_code[temp];
index--;
temp = _TIME.YEAR;
temp&=0xf0; //get the tens
temp>>=4;
DATE_DISPLAY[index]=seg_code[temp];
index--;
//SPACER
DATE_DISPLAY[index]=0x40; //
index--;
//GET MONTH
temp = _TIME.MONTH;
temp&=0x0f; //get the unit
DATE_DISPLAY[index]=seg_code[temp];
index--;
temp = _TIME.MONTH;
temp&=0xf0; //get the tens
temp>>=4;
DATE_DISPLAY[index]=seg_code[temp];
index--;
//SPACER
DATE_DISPLAY[index]=0x40; //
index--;
//GET DATE
temp = _TIME.DATE;
temp&=0x0f; //get the unit
DATE_DISPLAY[index]=seg_code[temp];
index--;
temp = _TIME.DATE;
temp&=0xf0; //get the tens
temp>>=4;
DATE_DISPLAY[index]=seg_code[temp];
}
//==========================================================//
// //
// Timer1_ini //
//==========================================================//
void TIMER1_ini()
{
TMOD |= 0x10; //timer 1 16bit reload
TH1 = 0x00;
TL1 = 0x00;
TF1 = 0;
TR1 = 0;
ET1 = 1;
}
//==========================================================//
// //
// Timer0_interrupt //
//==========================================================//
void TIMER0_interrupt() interrupt 1
{
TR0 = 0;
TF0 = 0;
TH0 = 0;
TL0 = 0;
GLOBAL_DISPLAY++;
if(GLOBAL_DISPLAY==TIME_STATUS)
GLOBAL_DISPLAY=0;
TR0 = 1;
}
//==========================================================//
// //
// Timer1_interrupt //
//==========================================================//
void TIMER1_interrupt() interrupt 3
{
TR1 = 0; //stop timer1
TF1 = 0; //clear TF1
TH1 = 0;
TL1 = 1;
CONTROL_INVISIBLE++;
if(CONTROL_INVISIBLE==5)
{
IN_VISIBLE = 0x00;
}
else if(CONTROL_INVISIBLE==10)
{
IN_VISIBLE = SHIFT_CURCOR;
CONTROL_INVISIBLE=0;
}
else {;}
TR1 = 1;
}
//==========================================================//
// //
// External Interrupt 1 //
//==========================================================//
void EX1_interrupt()interrupt 2
{
unsigned char unit,tens;
EX1 = 0; // disable ex interrupt 1
EX0 = 0; // disable ex interrupt 0
counter_status=0x00;
TR1 = 1; //enable TIMER1
IN_VISIBLE = 0xc0;
SHIFT_CURCOR = IN_VISIBLE;
CONTROL_INVISIBLE=0;
// GET_TIME();
while(MODE==0)DISPLAY_2__(TIME_DISPLAY);
while(counter_status!=0x07)
{
switch(counter_status)
{
case 0x00: {
while(MODE)
{
if(INC==0)
{
while(INC==0)DISPLAY_2__(TIME_DISPLAY);
unit = _TIME.HOUR;
unit &=0x0f;
tens = _TIME.HOUR;
tens >>= 4;
if(tens!=2)
{
unit++;
if(unit==10)
{
tens++;
unit=0;
}
}
else
{
unit++;
if(unit==4)
{
tens=0;
unit = 0;
}
}
_TIME.HOUR = tens;
_TIME.HOUR <<=4;
_TIME.HOUR |= unit;
CONVERT();
}
if(DEC==0)
{
while(DEC==0)DISPLAY_2__(TIME_DISPLAY);
unit = _TIME.HOUR;
unit &=0x0f;
tens = _TIME.HOUR;
tens >>= 4;
if(tens!=0)
{
unit--;
if(unit==0xff)
{
tens--;
unit = 0x09;
}
}
else
{
unit--;
if(unit==0xff)
{
tens = 0x02;
unit = 0x03;
}
}
_TIME.HOUR = tens;
_TIME.HOUR <<=4;
_TIME.HOUR |= unit;
CONVERT();
}
DISPLAY_2__(TIME_DISPLAY);
}
while(MODE==0){DISPLAY_2__(TIME_DISPLAY);}
while(IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
IN_VISIBLE>>=3;
SHIFT_CURCOR = IN_VISIBLE;
counter_status++;
break;
}
case 0x01: {
while(MODE)
{
if(INC==0)
{
while(INC==0)DISPLAY_2__(TIME_DISPLAY);
unit = _TIME.MIN;
unit &=0x0f;
tens = _TIME.MIN;
tens >>= 4;
unit++;
if(unit==10)
{
tens++;
unit=0;
}
if(tens==6)
tens=0;
_TIME.MIN = tens;
_TIME.MIN <<=4;
_TIME.MIN |= unit;
CONVERT();
}
if(DEC==0)
{
while(DEC==0)DISPLAY_2__(TIME_DISPLAY);
unit = _TIME.MIN;
unit &=0x0f;
tens = _TIME.MIN;
tens >>= 4;
unit--;
if(unit==0xff)
{
tens--;
unit=9;
}
if(tens==0xff)
tens=5;
_TIME.MIN = tens;
_TIME.MIN <<=4;
_TIME.MIN |= unit;
CONVERT();
}
DISPLAY_2__(TIME_DISPLAY);
}
while(MODE==0){DISPLAY_2__(TIME_DISPLAY);}
while(IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
IN_VISIBLE>>=3;
SHIFT_CURCOR = IN_VISIBLE;
counter_status++;
break;
}
case 0x02: {
while(MODE)
{
if(INC==0)
{
while(INC==0)DISPLAY_2__(TIME_DISPLAY);
unit = _TIME.SEC;
unit &=0x0f;
tens = _TIME.SEC;
tens >>= 4;
unit++;
if(unit==10)
{
tens++;
unit=0;
}
if(tens==6)
tens=0;
_TIME.SEC = tens;
_TIME.SEC <<=4;
_TIME.SEC|= unit;
CONVERT();
}
if(DEC==0)
{
while(DEC==0)DISPLAY_2__(TIME_DISPLAY);
unit = _TIME.SEC;
unit &=0x0f;
tens = _TIME.SEC;
tens >>= 4;
unit--;
if(unit==0xff)
{
tens--;
unit=9;
}
if(tens==0xff)
tens=5;
_TIME.SEC = tens;
_TIME.SEC <<=4;
_TIME.SEC|= unit;
CONVERT();
}
DISPLAY_2__(TIME_DISPLAY);
}
while(MODE==0){DISPLAY_2__(TIME_DISPLAY);}
while(IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
IN_VISIBLE=0xc0;
SHIFT_CURCOR = IN_VISIBLE;
counter_status++;
break;
}
case 0x03: {
while(MODE)
{
if(INC==0)
{
while(INC==0)DISPLAY_2__(DATE_DISPLAY);
unit = _TIME.DATE;
unit &=0x0f;
tens = _TIME.DATE;
tens >>= 4;
if(_TIME.MONTH%2==1)
{
if(tens<3)
{
unit++;
if(unit==10)
{
tens++;
unit=0;
}
}
else
{
unit++;
if(unit==2)
{
tens=0;
unit=0;
}
}
}
else if(_TIME.MONTH%2==0)
{
if(tens<3)
{
unit++;
if(unit==10)
{
tens++;
unit=0;
}
}
else
{
unit++;
if(unit==1)
{
tens=0;
unit=0;
}
}
}
_TIME.DATE = tens;
_TIME.DATE <<=4;
_TIME.DATE |= unit;
CONVERT();
}
if(DEC==0)
{
while(DEC==0)DISPLAY_2__(DATE_DISPLAY);
unit = _TIME.DATE;
unit &=0x0f;
tens = _TIME.DATE;
tens >>= 4;
if(_TIME.MONTH%2==1)
{
unit--;
if(unit==0xff)
{
tens--;
unit=9;
}
if(tens==0xff)
{
tens=3;
unit=1;
}
}
else if(_TIME.MONTH%2==0)
{
unit--;
if(unit==0xff)
{
tens--;
unit=9;
}
if(tens==0xff)
{
tens=3;
unit=0;
}
}
_TIME.DATE = tens;
_TIME.DATE <<=4;
_TIME.DATE |= unit;
CONVERT();
}
DISPLAY_2__(DATE_DISPLAY);
}
while(MODE==0){DISPLAY_2__(DATE_DISPLAY); }
while(IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
IN_VISIBLE>>=3;
SHIFT_CURCOR = IN_VISIBLE;
counter_status++;
break;
}
case 0x04: {
while(MODE)
{
if(INC==0)
{
while(INC==0)DISPLAY_2__(DATE_DISPLAY);
unit = _TIME.MONTH;
unit &=0x0f;
tens = _TIME.MONTH;
tens >>= 4;
if(tens!=1)
{
unit++;
if(unit==10)
{
tens++;
unit=0;
}
}
else
{
unit++;
if(unit==3)
{
tens=0;
unit=0;
}
}
_TIME.MONTH = tens;
_TIME.MONTH <<=4;
_TIME.MONTH |= unit;
CONVERT();
}
if(DEC==0)
{
while(DEC==0)DISPLAY_2__(DATE_DISPLAY);
unit = _TIME.MONTH;
unit &=0x0f;
tens = _TIME.MONTH;
tens >>= 4;
unit--;
if(unit==0xff)
{
tens--;
unit=9;
}
if(tens==0xff)
{
tens=1;
unit=2;
}
_TIME.MONTH = tens;
_TIME.MONTH <<=4;
_TIME.MONTH |= unit;
CONVERT();
}
DISPLAY_2__(DATE_DISPLAY);
}
while(MODE==0){DISPLAY_2__(DATE_DISPLAY);}
while(IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
IN_VISIBLE>>=3;
SHIFT_CURCOR = IN_VISIBLE;
counter_status++;
break;
}
case 0x05: {
while(MODE)
{
if(INC==0)
{
while(INC==0)DISPLAY_2__(DATE_DISPLAY);
unit = _TIME.YEAR;
unit &=0x0f;
tens = _TIME.YEAR;
tens >>= 4;
unit++;
if(unit==10)
{
tens++;
unit=0;
}
if(tens==9)
tens=0;
_TIME.YEAR = tens;
_TIME.YEAR <<=4;
_TIME.YEAR |= unit;
CONVERT();
}
if(DEC==0)
{
while(DEC==0)DISPLAY_2__(DATE_DISPLAY);
unit = _TIME.YEAR;
unit &=0x0f;
tens = _TIME.YEAR;
tens >>= 4;
unit--;
if(unit==0xff)
{
tens--;
unit=9;
}
if(tens==0xff)
tens=9;
_TIME.YEAR = tens;
_TIME.YEAR <<=4;
_TIME.YEAR |= unit;
CONVERT();
}
DISPLAY_2__(DATE_DISPLAY);
}
while(MODE==0){DISPLAY_2__(DATE_DISPLAY);}
while(IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
IN_VISIBLE = 0xff;
SHIFT_CURCOR = IN_VISIBLE;
counter_status++;
break;
}
case 0x06: {
while(MODE)
{
CHECK_DAY(0);
if(INC==0)
{
while(INC==0)DISPLAY_2__(DAY_DISPLAY);
_TIME.DAY++;
if(_TIME.DAY==8)
_TIME.DAY=1;
CHECK_DAY(0);
}
if(DEC==0)
{
while(DEC==0)DISPLAY_2__(DAY_DISPLAY);
_TIME.DAY--;
if(_TIME.DAY==0xff)
_TIME.DAY=7;
CHECK_DAY(0);
}
DISPLAY_2__(DAY_DISPLAY);
}
while(MODE==0){DISPLAY_2__(DAY_DISPLAY);}
while(IN_VISIBLE==0x00){DISPLAY_2__(DAY_DISPLAY);}
SHIFT_CURCOR = IN_VISIBLE;
counter_status++;
break;
}
}
RTC_INI();
}
IE1 = 0;//clear external interrupt 1 flag
TR1 = 0;
EX0 = 1;
EX1 = 1;
}
//==========================================================//
// //
// CHECK_DAY //
//==========================================================//
void CHECK_DAY(bit get)
{
unsigned char index,DAY;
if(get)
DAY = RTC_READ(0x03);
else
DAY = _TIME.DAY;
switch(DAY)
{
case 0x01: for(index=0;index<24;index++)DAY_DISPLAY[index]=SUN[index];break;
case 0x02: for(index=0;index<24;index++)DAY_DISPLAY[index]=MON[index];break;
case 0x03: for(index=0;index<24;index++)DAY_DISPLAY[index]=TUE[index];break;
case 0x04: for(index=0;index<24;index++)DAY_DISPLAY[index]=WED[index];break;
case 0x05: for(index=0;index<24;index++)DAY_DISPLAY[index]=THU[index];break;
case 0x06: for(index=0;index<24;index++)DAY_DISPLAY[index]=FRI[index];break;
case 0x07: for(index=0;index<24;index++)DAY_DISPLAY[index]=SAT[index];break;
}
}
//===========================================================///
void update_time() interrupt 0
{
EX0 = 0;
GET_TIME();
IE0 = 0;
EX0 = 1;
}
//===========================================================//
void GET_T()
{
unsigned char temp;
_RW = 0;
_RW = 1;
while(_INT);
RD = 0;
temp = P1;
temp&=0x7f;
RD = 1;
T_value[0]=seg_code[temp/10];
T_value[1]=seg_code[temp%10];
}
Comment
-
Nguyên văn bởi vietthanh123 Xem bài viếtMình có cái đồng hồ này nữa.
Mo phong(2).zip
Comment
Bài viết mới nhất
Collapse
-
Trả lời cho Khác nhau giữa mạch cân bằng chủ động toàn dãy và mạch cân bằng chủ động kiểu so áp 2 string liền kề.bởi louisnkCụ đã lên design chi tiết cho mạch để test chưa?
-
Channel: Điện tử dành cho người mới bắt đầu
19-09-2024, 08:12 -
-
bởi Manh.n.trMọi người cho em hỏi có bác nào làm project mạch đo độ mặn chưa ạ. Cho em hỏi có bác nào mô phỏng được trên Proteus không ạ? Em sinh viên đầu năm 3 tay mơ chưa biết nhiều mong mọi người giúp đỡ ạ
-
Channel: Các mạch điện ứng dụng
17-09-2024, 13:54 -
-
Trả lời cho Xin hỏi về mạch khuếch đạibởi yname11Ko đc bác ạ, mạch nó tự ngắt. Thôi đành dùng 1 kênh vậy, thanks bác nhé....
-
Channel: Điện thanh
15-09-2024, 10:44 -
-
bởi nguyendinhvanTôi thì không học về MCU, không giỏi về VXL , cũng mờ tịt về công nghiệp thực phẩm, nhưng cũng cố gắng tự làm được cái này.
Đồ ở chợ mua về cứ đặt ở sân, rồi xếp cái máy này lên trên, rồi đi chơi.
Một lúc sau quay...-
Channel: Tâm tình dân kỹ thuật
15-09-2024, 02:36 -
-
Trả lời cho Thép hàn cube led ???bởi nguyendinhvanRa chợ kim khí mua, có nhiều loại to nhỏ. Họ bán cho thợ xây dựng buộc khung đúc bê tông.
Về cắt thành đoạn.
Nhưng làm cho các đoạn dây thép đó thẳng tưng như cái gói mì Ý, thì cũng đòi hỏi công nghệ khéo tay.-
Channel: Điện tử dành cho người mới bắt đầu
15-09-2024, 02:03 -
-
Trả lời cho Thép hàn cube led ???bởi bqvietThép nào cũng hàn thiếc được : thép các-bon, thép không gỉ ... miễn là có chất trợ dung phù hợp. Dùng nhựa thông bình thường thì khó hàn, nhưng trên thị trường bán nhiều loại chất trợ dung đủ kiểu. Đơn giản nhất là dung dịch kẽm clorua ZnCl2.
-
Channel: Điện tử dành cho người mới bắt đầu
15-09-2024, 00:34 -
-
bởi tuyenda1985Các bác cho em hỏi.
Định làm cube led chơi chơi, nhưng vụ que thép để cho nó cứng
Mà chưa biết mua ntn, vì đang alwn tăn, loại này là loại nào (như hình em úp) mà có thể dùng thiếc hàn ??
Cảm ơn...-
Channel: Điện tử dành cho người mới bắt đầu
14-09-2024, 22:05 -
-
Trả lời cho Xin hỏi về mạch khuếch đạibởi thetungPhương án của bạn có thể được ,nhưng có thể rủi ro . Mặt khác bạn muốn tăng công suất thì phải giảm trở kháng của loa ( thí dụ dùng loa 2 ohm )...
-
Channel: Điện thanh
14-09-2024, 11:46 -
-
Trả lời cho Xin hỏi về mạch khuếch đạibởi yname11chập 2 đầu r+, l+ vào làm 1, 2 đầu r-, l- vào làm 1 . rồi đấu vào loa...
-
Channel: Điện thanh
14-09-2024, 07:40 -
Comment