Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Turned OFF and turned ON at pre-define time the display 7seg runing RTC

Status
Not open for further replies.

saramah

Member level 3
Joined
Apr 25, 2018
Messages
64
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
689
Hi,

In software side, it is multiplex, xc8 comp to disp HH:MM:SEC, mcu reading from rtc readng at 24hrs format and then in software it is converted to 12hrs farmat under main().

H/W, 7seg CC, RTC1307.

All are working correctly , now I want to add a feature that is, when the time reach at 2:30 (at night)the disp will be turned OFF and after 2:32 (at night) the disp will turn ON. The code attched here is working all the said time(ie, as every 2.30 start OFF and evert 2.32 start ON), whereas i need only at night, so if 1st time turned OFF and ON then for 2nd time(which is day time) no need ON-OFF and vice-versa, and 3rd. time what was in 1st time.

As per code attached here, Once turned OFF at said time at 2.30 & it ON at 2.32, when it ON then i set the time by BUTTON once to keep ON(as it is day time) the disp for this 2nd. time but it going OFF again.and all the 2.30 it is going off and on at 2.32.

So, is the code ok or what should i modify either at BUTTON routine or Main routine.

Code is under at Main()

// Here TIME FORMAT 24 to 12 HRS conversion
Code:
            if (hour <= 12)
            {
                hour = hour;
PowerSave = 1;
            }
            else
            {
                 PowerSave = 0;
                hour = (hour - 12);

                
            }
            
 // For particular time display to be TURNED OFF and Again ON          
 if (PowerSave == 1)
  {
             
    if ((hour == 2 && min >= 30) && (hour == 2 && min <= 31))
        {
            INTCONbits.T0IE = 0;
 

        }
    else 
   
   INTCONbits.T0IE = 1;
            
    }


Sub routine for BUTTON
Code:
uint8_t edit(uint8_t parameter)
{
  while(debounce());                                // call debounce function (wait for B1 to be released)
 
  while(1) 
        {
            while(!BUTTON2)                         // if button B2 is pressed
                 {
                    parameter++;
                    __delay_ms(300);                //this delay for prevent several count on one press
                    
                    if (i == 0 && parameter <= 12)
                        PowerSave &= 0x01;
          
                    if(i == 0 && parameter > 12)    // if hours > 23 ==> hours = 0
                    parameter = 1;
      
                    if(i == 1 && parameter > 59)    // if minutes > 59 ==> minutes = 0
                    parameter = 0;
      

                    if (i == 0)
                         {
                            hour_1 = (parameter % 10);
                            hour_10 = (parameter / 10); 
                            __delay_ms(10);
                         }
      
                    if (i == 1)
                         {
                            min_1 = (parameter % 10);
                            min_10 = (parameter / 10);   
                            __delay_ms(10);                
      
                         }
    
                 }
    
            if(!BUTTON1)                            // if button B1 is pressed
            if(debounce())                          // call debounce function (make sure if B1 is pressed)
             {
                i++;                                // increment 'i' for the next parameter
                return parameter;                   // return parameter value and exit
              }
 
        }
 
}

tnx
 

Hello!

now I want to add a feature that is, when the time reach at 2:30 (at night)the disp
will be turned OFF and after 2:32 (at night) the disp will turn ON

That's fine, but you should explain your code. What is INTCONbits.T0IE?
Is it something specific to xc8?

Now general comments about your code:

1. You shouldn't use clock consuming routines to debounce. The most economical way
to do that is:
- Set a one-shot timer when you receive a button press (for example 250 ms).
and disable the button interrupt;
- When you receive the timer interrupt after 250 ms, re-enable the button interrupt.

2. You write:
Code:
	hour = hour;
What do you expect from this instruction?
Suggestion: instead of:
Code:
	            if (hour <= 12)
            {
                hour = hour;
				PowerSave = 1;
            }
            else
            {
                PowerSave = 0;
				hour = (hour - 12);

                
            }
you may consider:
Code:
	PowerSave = 0;
	if(hour > 12) hour -= 12;

Dora
 

HI,
HTML:
What is INTCONbits.T0IE?
its Time0 interrupt enable bit.
Code is attached here in .txt format
The code is extracting time from rtc module I2C displaying at segments and the segments is refresing at every 1msec using timer0 and the multiplex is uded.
So, I think debounce routine is not clock consuming here.

The code is running ok with the h/w and there are no problems(drift in time) also if button is pressed and debounce called.

HTML:
now I want to add a feature that is, when the time reach at 2:30 (at night)the disp
will be turned OFF and after 2:32 (at night) the disp will turn ON

Pl looks the code in .TXT format here.

What is happening::

1) Button is used to set the time(2:29) nearer to predefined OFF stage, some times it is going OFF and ON (at 2:31), and once OFF/ON completed for the first time

2) Then it should be keep ON( that means the time is DAY 2:30AM, i set the time nearer to predefined by button)

3) Again after set at nearer to predefined time (that means the time is 2:30 PM) - the it should be OFF at this stage. and continue continuously those all three stage one after another.

I have modified under //edit(), and while() at main() function to get this result but irregularity is noticed that means once point 1 is comes then it is coming after some stage latter not interval of one stage.

pl suggest what i am doing wrong in the code to add that features.
tnx
 

Attachments

  • auto ON-OFF.txt
    13.9 KB · Views: 36

I haven't fully followed the code but the method I use when using multiple daily timers is to convert everything to a common format first. Instead of checking hours and minutes as different variables, let the clock maintain a common variable of "minutes into the day", starting at zero and counting up to 1440 (24h * 60m). Calculate it as hours * minutes every time the clock updates then to enable or disable a function just use a numerical compare to see if the time falls in the desired period.

For example: if((MinSinceMidnight == 150) || (MinSinceMidnight == 151)) powersave = 1; // 150 = 02:30, 151 = 02:31

In my applications, the number used in the comparison is itself a variable, for example sunrise and sunset times to turn lighting on overnight.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top