السلام عليكم
تم تحديث مكتبه DS1307 لكي تتعامل مع النظامين 12 و 24 مع اعطاء اشاره AM , PM
http://arabsh.com/files/0c34434d65fa...-data-rar.html
ملاحظه المكتبه موجوده ضمن مشروع باسم clock_data
كود:
static void set_DS1307(unsigned char set_switch,unsigned char inc_dec_system_12_24)
{
if(set_switch==0)// start value
{
setting_DS1307[0]=hours;
setting_DS1307[1]=minutes;
setting_DS1307[2]=seconds;
setting_DS1307[3]=day;
setting_DS1307[4]=week;
setting_DS1307[5]=month;
setting_DS1307[6]=year;
}
if(set_switch==9)//write new data to DS1307
{
if(inc_dec_system_12_24==24)kw_12_24=24;
else if(inc_dec_system_12_24==12)kw_12_24=12;
Show_Time(setting_DS1307[0],setting_DS1307[1],setting_DS1307[2],setting_DS1307[3],
setting_DS1307[4],setting_DS1307[5],setting_DS1307[6],0);
}
طبعا اذا ارسلت بعد عمل setting رقم 12 يعني اريد الوقت يعمل بنظام 12 واذا ارسلت 24 يعني اريده يعمل بــ 24
طبعا لنرجع قليلا الى البرنامج
كود:
while(1)
{
if (Button(&PORTA, 0, 100, 0)) // set switch
{
kk=0;
if(set==0)set_DS1307(0,255);// to sore data in setting_DS1307 before change value
set++;
lcd_cmd(1);
if(set>=9)
{
kk=255;
LCD_Chr(1,8,'.');
LCD_Chr(1,11,'.');
LCD_Out(2,1,"Time ");
LCD_Chr(2,8,':');
LCD_Chr(2,11,':');
LCD_Out(1,12,"20");
set_DS1307(set,system_12_24);
set=0;
}
تلاحظون ايضا لاختيار نظام 24 نضغط على سويج -- وموجود على بورت a بن 2
اما لاختيار النظام 12 نضغط على سويج++ وموجود على بورت a بن 1
وتلاحظون ايضا انه عندما اريد اظهار system على شاشه امنع من ظهور الارقام
حيث كتبت
كود:
if(kk!=255 && set !=8)
{
Lcd_Chr(1, 14, (setting_DS1307[set-1]/ 10) + 48);
Lcd_Chr(1,15, (setting_DS1307[set-1] % 10) + 48);
}
اما كيف يتم ضبط النظام لاحظ كود من البرنامج
كود:
if (Button(&PORTA, 1, 150, 0)) // dec switch
{
set_DS1307(set,1);
if(set ==8){
lcd_out(1,8,"24");
system_12_24=24;
}
}
if (Button(&PORTA, 2, 150, 0)) // inc switch
{
set_DS1307(set,0);
if(set ==8)
{
lcd_out(1,8,"12");
system_12_24=12;
}
}
نعود الى مكتبه وهذا هو كود مضاف لاختيار النظام 12 او 24
كود:
static void Show_Time(unsigned char c_hours, unsigned char c_minutes, unsigned char c_seconds,
unsigned char c_day, unsigned char c_week, unsigned char c_month, unsigned char c_year,unsigned char states)
{
if(states==0){
c_hours=dec2bcd(c_hours);
c_minutes=dec2bcd(c_minutes);
c_seconds=dec2bcd(c_seconds);
c_day=dec2bcd(c_day);
c_month=dec2bcd(c_month);
c_year=dec2bcd(c_year);
Write_Time(c_hours,c_minutes,c_seconds,c_day,c_week,c_month,c_year);
}
Read_Time(&hours, &minutes, &seconds, &day, &week, &month, &year);
seconds = ((seconds & 0x70) >> 4)*10 + (seconds & 0x0F);
minutes = ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F);
hours =((hours & 0x10) >> 4)*10 + (hours& 0x0F);[COLOR="DimGray"]
if(kw_12_24==24)k_12_24=24;//for system 24
else if(kw_12_24==12)// for system 12
{
if(hours <= 12 )
{
k_12_24=0; // this mean AM,
if(hours==0)hours=1;
}
if(hours >= 13)
{
k_12_24=1;//this mean PM,
hours = hours -12;
}
}
week = (week & 0x07);
day = ((day & 0xF0) >> 4)*10 + (day & 0x0F);
month = ((month & 0x10) >> 4)*10 + (month & 0x0F);
year = ((year & 0xF0)>>4)*10+(year & 0x0F);