60 Sec Counter
60 Sec Counter
60 Sec Counter
Introduction:
The 60 seconds counter is one which repeatedly counts from 00 to 59 with a gap of 1 second
between each count. Pressing a switch serves as a hardware interrupt and resets the count to 00
immediately. An LED is dedicated to count the number of resets by blinking that many number of
times i.e the number of times the switch was pressed.
Block Diagram:
On-Board push button is available on pin 2.1. This is used as a hardware interrupt to reset
the counter.
On-Board LED available at pin 1.0 is used to display the number of times reset occurs.
The two common cathode seven segment displays are connected to port 3 and port 6 and
display the seconds count i.e from 00 to 59.
Timer A is an on-chip peripheral used here to generate delay between each count.
Circuit Diagram:
Flow chart:
Program with comments:
#include <msp430.h> //include the header files for the msp430 family
#define delay 1000 // define a variable delay = 1000
char code[]={0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xE6};
char code1[]={0x7E,0x30,0x6D,0x79,0x33,0x5B}; //HEX equivalent of BCD numbers
/**
* main.c
*/
void main()
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
P8DIR |= 0xFF;
P8OUT |= 0x00;
P4DIR |= 0xFF;
P4OUT |= 0x00;
P5DIR |= 0xFF;
P5OUT |= 0x00;
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void) //Interrupt service Routine for TIMER A Interrupt
{
z++;
if(z>delay) //after 1 second i.e z>1000
{
P3OUT=code[x];
P6OUT=code1[y];
x++;
if(x==10) //First seven segment counts from 0 to 9
{
x=0;
y++;
}
for(i=0;i<v;i++)
{ //Blink the LED the number of times reset occurs
P1OUT |= BIT0; // P1.0 = toggle
__delay_cycles(1048576);
P1OUT &=~BIT0; // P1.0 = toggle
__delay_cycles(1048576);
}
}
3. Use of Hex decoder IC can be done, to multiplex the pins and reduce the usage of ports.