This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Programming a Digital Clock in C language on the MSP430F5529 microcontroller

Other Parts Discussed in Thread: MSP430F5529

Hello everyone, I am trying to figure out how to use the Touch Pads on the MSP430F5529 micro-controller to get the user to set time, The problem Statement is as Follows: 

When the program starts, it will start displaying time starting from 00:00:00.
Pressing touch sensitive PAD4 causes the program to enter time adjustment mode, and while in time adjustment mode:

  1. Seconds will be immediately set to zero
  2. Touching PAD1 increases the hours (from 0 to 23, and then back to zero again)
  3. Touching PAD2 increases the minutes (from 0 to 59, and then back to 0 again)
  4. Touching PAD4 again will cause the program to run normally, displaying the current time that was entered by the user.
    /*******************************************************************************
     *
     *  UserExperience.c - Main Application
     *
     *  Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *    Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     *    Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the
     *    distribution.
     *
     *    Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     ******************************************************************************/
    
    /*******************************************************************************
     * Modified by: Kevin Moore, NAIT
     * Date: Nov.26, 2013
     *
     * This program demonstrates the use of the capacitive
     * touch pad library.
     *
     * Students may use this project and its source code
     * to complete lab work in ELTRO1102 (Embedded 1).
     *
     * Note that the library Touchpad.c and its header file
     * have many dependencies. These additional files are
     * incorporated into this demonstration project.
     *
     *
     *
     *******************************************************************************/
    
    /********************************************************************************
     * 	Include Directives
     ********************************************************************************/
    #include <stdint.h>
    #include "msp430.h"
    #include <HAL_PMM.h>
    #include "HAL_UCS.h"
    #include "HAL_Board.h"
    #include "HAL_Dogs102x6.h"
    #include <HAL_Dogs102x6_B.h>
    #include "structure.h"
    #include "CTS_Layer.h"
    #include <TouchPad.h>
    #include <intrinsics.h>			//contains declaration for _delay_cycles()
    
    #define	CHAR_WIDTH 6
    
    
    /********************************************************************************
     * 	Function Declarations
     * 	See definitions below function main for more information
     * 	if you are interested.
     ********************************************************************************/
    
    void Start(void);
    void StartLCD(void);
    void StartTouchPads(void);
    void DisplayTime(int nSec, int nMin, int nHours);
    
    
    void main(void)
    {//start main function
    
     volatile unsigned int nTouchPad = 0;
     Start();	//initialize hardware
     int nMode1=1;
    
     while(1)
     {//start first while loop
    
     nTouchPad = GetTouchPads();	//detect which pad is touched
    								//set a break point on this line
    								//touch a pad, and observe what happens
    								//to the variable nTouchPad
    
      if (nMode1 ==1)
    
       {//if loop start
    
    	int nSS = 0, nMM = 0, nHH = 0;
    
    	Start();				//init hardware
    
    	while(1)
    	   {//while loop 1 start
    	    Dogs102x6_clearRow(0);
    
    	    DisplayTime(nSS, nMM, nHH);
    		nSS++;
    
    		 if (nSS > 59)
    	        {
    		nMM = nMM + 1;
    		nSS=0;
    	         }
    
    		 if (nMM > 59)
    			 {
    		nHH = nHH + 1;
    		nMM = 0;
    			 }
    
    		 if (nHH > 23)
    			 {
    		nHH = 0;
    		nMM = 0;
    		nSS = 0;
    			 }
    
    		_delay_cycles (1048576-500);
    /*This part of the program will enable user to set time using the touch pads*/
    
    
        if (nTouchPad==4)
    			{nMode1=2;
    
    		}//while loop 1 ends
    
    //This part of the program will define what happens when the nMode is equal to 2
    
    if(nMode1==2)
    
    {//if nMode 2 Starts
    	nTouchPad = GetTouchPads();
    	nSS = 0;
    
    if(nTouchPad ==1)
    {
    nHH++;
    __delay_cycles(27000000);
    }
    if(nTouchPad ==2)
    {
    nMM++;
    __delay_cycles(27000000);
    }if(nTouchPad ==4)
    {
    nMode1=1;
    __delay_cycles(27000000);
    }
    } //if nMode 2 ends
    
       }//while loop end
    
       }//end first while loop
    
    
    }//main function end
    }
    /* ***********************************************************************
     * Function: Start
     * Parameters: None
     * Returns nothing. Initializes all hardware for this demo program,
     * involving the LCD and touch pads.
     *
     * ***********************************************************************/
    
    void Start(void)
    {
    
    	WDTCTL = WDTPW + WDTHOLD;	//disable watchdog timer
    
    	Board_init();				//initialize MSP430 pins
    
    	//Buttons_init(BUTTON_ALL);
    
    	Dogs102x6_init();
    
    	Dogs102x6_backlightInit();
    
    	Dogs102x6_setBacklight(3);
    
    	Dogs102x6_setContrast(7);
    
    	Dogs102x6_clearScreen();
    
    }
    
    
    
    /* ***********************************************************************
     * Function: Start
     * Parameters: None
     * Returns nothing. Initializes all hardware for this demo program,
     * involving the LCD and touch pads.
     *
     * ***********************************************************************/
    void StartLCD(void)
    {
    	Dogs102x6_init();			//init LCD
    	Dogs102x6_backlightInit();	//turn on back light
    	Dogs102x6_setBacklight(11);	//set back light intensity
    	Dogs102x6_setContrast(11);	//set LCD pixel contrast
    	Dogs102x6_clearScreen();	//clear the LCD
    
    }
    
    void StartTouchPads(void)
    {
    	// Set Vcore to accomodate for max. allowed system speed
    	SetVCore(3);
    
    	// Use 32.768kHz XTAL as reference
    	LFXT_Start(XT1DRIVE_0);
    
    	// Set system clock to max (25MHz)
    	Init_FLL_Settle(25000, 762);
    
    	TI_CAPT_Init_Baseline(&slider); //measure baseline capacitance
    									//must be called while no pads are touched
    
    
    }
    
    void DisplayTime(int nSec, int nMin, int nHours)
    {
    	Dogs102x6_intDrawXY(0,0, nHours,DOGS102x6_DRAW_NORMAL);
    
    	Dogs102x6_stringDrawXY(CHAR_WIDTH*2+1, 0, ":", 0);
    
    	Dogs102x6_intDrawXY(0,CHAR_WIDTH*3+1, nMin, DOGS102x6_DRAW_NORMAL);
    
    	Dogs102x6_stringDrawXY(CHAR_WIDTH*5+1, 0, ":", 0);
    
    	Dogs102x6_intDrawXY(0,CHAR_WIDTH*6+1, nSec,DOGS102x6_DRAW_NORMAL);
    }
    

    Above is My code and I am not sure why I am not being able to get the Touch Pads to alter my time in any way! Any Help is greatly appreciated. 

  • Hi,

    This looks to me like you have your '{' brackets mixed up. at the bottom of the main function you have

       }//end first while loop
    }//main function end
    }

    There is an extra bracket at the end, that does not match the comments.

    I think the problem starts with:

    if (nTouchPad==4)
    {nMode1=2;

    }//while loop 1 ends

    This should be

    if (nTouchPad==4)
      {

        nMode1=2;
      }                                                // Extra bracket should be here not at the end
    }//while loop 1 ends

    Hope this helps

**Attention** This is a public forum