Simple Digital Stopwatch CloudX

  • img
Project Details

In this project, we are going to make a version of a digital clock that can keep a record of hours, minutes and seconds, just like a stopwatch on your mobile phone! We are going to use an LCD to display the time.


Components

  • CloudX M633
  • CloudX SoftCard
  • LCD Display
  • Potentiometer
  • Push Button
  • Bread Board
  • Jumper Wire
  • V3 USB cable
  • 10k


CloudX M633 


LCD


Variable Resistor

 

Push Button

Jumper Wires

 

Circuit Diagram

Program

#include <CloudX/M633.h>
#include <CloudX/LCD.h>
#include <Cloudx/stdlib.h>

#define START_PAUSE 7
#define RESET 8
#define START 1
#define PAUSE 0

char timer[] = "00:00:00:0";
unsigned char HH, MM, SS, mSS,mscount, RFlag=0;
bit OmSF=0 , S_PFlag=0   ;

interrupt TimerOmSD(){
    if (INTCONbits.T0IF) {
      INTCONbits.T0IF = 0;
      TMR0 += 60;
      if (mscount++ == 10) {
      mscount = 0;
      OmSF = 1;
    }
   }
    
}

setup(){
         //setup here              
            pinMode(START_PAUSE , INPUT);
            pinMode(RESET , INPUT);  
            lcdSetting (1,2,3,4,5,6);
            lcdCmd(clear);
            lcdCmd(cursorOff);
            lcdWriteText(1,1, "CLOUDX STOPWATCH");

loop(){
       //Program here
      if( !readPin(START_PAUSE) ) {
         if(S_PFlag == START){
            delayMs(200);
            INTCON =     0b00000000;
            OPTION_REG = 0b00000000;
            mSS--;
            }
      if(S_PFlag == PAUSE && RFlag == 1 ){
            delayMs(200);
            INTCON =     0b11100000;
            OPTION_REG = 0b00000111;
            }
          
      if(S_PFlag == PAUSE && RFlag == 0 ){
            delayMs(200);
            INTCON =     0b11100000;
            OPTION_REG = 0b00000111;
            TMR0 += 60;
            mscount=0;
            OmSF = 0;
            }
     
            S_PFlag = ~S_PFlag;
            RFlag = 1;
         }           
      if( !readPin(RESET) ){
            delayMs(200);
            HH = 0;
            MM = 0;
            SS = 0;
            mSS = 0;
            INTCON =     0b00000000;
            OPTION_REG = 0b00000000;
            mscount=0;
            OmSF = 0;
            RFlag = 0;
            S_PFlag = PAUSE;
        }           
      if (OmSF){
                OmSF = ~ OmSF;
                mSS++;
                if(mSS==10) SS ++;
                if(SS==60 )MM++;
                if(MM==60 )HH++;
                }          
            if(HH==100) HH=0;
            if(MM==60) MM=0;
            if(SS==60) SS=0;
            if(mSS==10) mSS=0;
            timer[1] = (HH%10) +48; timer[0] = (HH/10) +48;
            timer[4] = (MM%10) +48; timer[3] = (MM/10) +48;
            timer[7] = (SS%10) +48; timer[6] = (SS/10) +48;
            timer[9] = mSS +48;
            lcdWriteText(2,2, timer);
       }
}

Share this with friends