السلام عليكم
لدي دائرة بين real time clock DS1307 وبين pic18f4520
وأريد تعديل او كتابة الوقت في RTC عن طريق استخدام زرين بحيث قمت بتوصيل زرين عن طريق b5 , b6
كود:
if(portb.f5==0) //if B5 interrupt occured
{
if(count>6)
{ Lcd_Cmd(_Lcd_CLEAR);
get_time_date();
count=0;
}
count++ ;
}
while (count<6)
{
get_time_date();
_i2c_write_RTC(0,0x80); //Reset second to 0 sec. and stop Oscillator
if(count==1)
{
Lcd_Out(1,1," set min ");
if(portb.f6==0) //if B6 interrupt occured ->
{
_i2c_write_RTC(1,(0x01+_i2c_read_RTC(1))); //increment min
if( _i2c_read_RTC(1)== 60)
_i2c_read_RTC(1)=0x01;
}
}
else if(count==2)
{
Lcd_Out(1,1," set hour ");
if(portb.f6==0) //if B6 interrupt occured ->
{ _i2c_write_RTC(2,(0x01+_i2c_read_RTC(2))); //increment hour
if(_i2c_read_RTC(2)==60)
_i2c_read_RTC(2)=0x00;
}
}
else if(count==3)
{
Lcd_Out(1,1," set date ");
if(portb.f6==0) //if B6 interrupt occured ->
{
_i2c_write_RTC(4,(0x01+ _i2c_read_RTC(4))); //increment date of week
if(_i2c_read_RTC(4)==31)
_day=0x01;
}
}
else if (count==4)
{
Lcd_Out(1,1," set month ");
if(portb.f6==0) //if B6 interrupt occured ->
{
_i2c_write_RTC(5,(0x01+ _i2c_read_RTC(5))); // increment month
if (_mon==31)
_day=0x01;
}
}
else if(count==5)
{
Lcd_Out(1,1," set year ");
if(portb.f6==0) //if B6 interrupt occured ->
{
_i2c_write_RTC(6,(0x01+ _i2c_read_RTC(6))); // increment year
if(_yr==13)
_yr=0x01;
}
}
}
_i2c_write_RTC(0,0x00);
بحيث اذا ضغط مرة واحدة على زر b5 يقوم بتعديل الدقيقة و زر b6 يقوم بزيادة الدقيقة
واذا ضغط مرتين على b5 يقوم بتعديل الساعة وزر b6 يقوم بزيادة الساعة
المشكلة انه عندما اضغط على الزر b5 مرة واحدة يقوم بتعدل السنة وفي بعض الاحيان يقوم بتعديل الشهور
والمشكلة الثانية عندما أقوم بتعديل الأوقات فانه بعد الرقم 9 يقوم باظهار الرموز ولا يتوقف ابد
ارجو مساعدتي في تصحيح الكود