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.

DIGITAL CLOCK IN C ( NOT USING 'IF' Statements)

Status
Not open for further replies.

brucelee2

Member level 2
Joined
Aug 22, 2009
Messages
49
Helped
6
Reputation
12
Reaction score
3
Trophy points
1,288
Location
on a PCB
Activity points
1,638
HI all,


Im trying to make a digital clock in using an 80515. I want to do it without using 'IF' conditions to check counters ect. I will then Display it on a 4X7segemnt display HDSP-B08G.

Apart from the Clock i also want to implement a BCD to 7-segment decoder without 'IF' statements.

I will need to use bitwise operators i assume but the technique im not sure of, any examples notes?.

OUTLINE:

TIMER -increment counter(needs to be reset with bitwise operators??)
Interrupt1 - To diaplay on the seven segments alternatly and fast enough for the human eye.


I WANT TO USE DIGITAL TECHNIQUES BUT WITH C :idea:


THANKS :D
 

brucelee2

Member level 2
Joined
Aug 22, 2009
Messages
49
Helped
6
Reputation
12
Reaction score
3
Trophy points
1,288
Location
on a PCB
Activity points
1,638
I gather the use of bitwise operators for a task uses less 'processing power' from the Microcontroller. To become familier more familier with bitwise operators too.

Any ideas?
 

brucelee2

Member level 2
Joined
Aug 22, 2009
Messages
49
Helped
6
Reputation
12
Reaction score
3
Trophy points
1,288
Location
on a PCB
Activity points
1,638
NEED TO BE REPLACED or different system with no IF statements. Does any body have an idea?

Code:
void Init_Timer(void)//timer zero
{

 TMOD=0x01;
 TR0=1;
 ET0=1;
 TH0=0xFC;  //64535 - 65535   
 TL0=0x17;  //

}

void Init_int(void)
{
//turn off interupts the configure priority then turn on. 
IEN0=0x00; //turn off interrupts.
           //3 interrupts-Timer1,-Button,-Display freq(most->least).
                                                                    

//NOT FINISHED YET




}

void ISR_timer(void) interrupt 1
{
 TH0=0xFC;    //xtal@12MHZ  ISR 12 machine cycles, timer reg incremented    every 1/1e6-->counter every ms

  TL0=0x17;
 counter++; 
}
                                          


void main(void)
{
  Init_int();
  Init_Timer();
  port_init();
 
 while (1) {      

             if(counter>=1000)  NEED TO BE REPLACED or different system with no IF statements
              {
	 	    //printf("Time=%2:%2d:%2d\n", h1,m1,s1);
               s1++; 
               counter=0; 
              }

             if(s1>59)
             {
               s1=0;
               m1++;
             }

             if(m1>59)
              {
               m1=0;
               h1++;

               if (h1 >23)
	        {
	         h1=0;
	        }

               }
      

            }


   
}

THANKS!
 

kender

Advanced Member level 4
Joined
Jun 19, 2005
Messages
1,422
Helped
138
Reputation
276
Reaction score
38
Trophy points
1,328
Location
Stanford, SF Bay Peninsula, California, Earth, Sol
Activity points
9,970
Your code looks fine. I would probably write it in a similar fashion.

brucelee2 said:
I gather the use of bitwise operators for a task uses less 'processing power' from the Microcontroller.
For a clock, which increments every second or every millisecond even. not much processing power is needed.
 

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
451
Helped
25
Reputation
50
Reaction score
9
Trophy points
1,298
Activity points
3,605
use ds1302
64_1258013088.jpg
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top