AVR: Stopwatch With Interrupt Timer and Multiplexed 7 segment Display
Here we are connecting the 7 segment display with PORTA, i.e. Multiplexing of six-7segment display, with the control lines to PORTB. Following is the program to Interface the 7segments.
Crystal : 8MHz
Time: 0.125uSec
Prescaler: clk/1025
Timer Interrupt : 25mSec.
For 1sec , run this timmer for 40 times.
We can achieve max delay of appx. 35000uSec or 35mSec with 8MHz crystal frequency and prescaler (clk/1024).
Program:
/*
* two_7seg.c
*
* Created: 27-Oct-13 19:08:04
* Author: avrnarm
*/
/* PROGRAM to execute the counter with the multiplexed 7 segent display */
#define FUSE_CKSEL0 0
#define FUSE_CKSEL1 0
#define FUSE_CKSEL2 1
#define FUSE_CKSEL3 0
#include<avr/io.h>
#define F_CPU 8000000Ul
#include<util/delay.h>
#include<avr/interrupt.h>
unsigned int j,ss=0,mm=0,hh=0;
char ssd[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; // Hexadecimal values for the 7 Segment display generated by the look up table
char ssd_dec[]={0xbf,0x86,0xdb,0xcf,0xE6,0xEd,0xFd,0x87,0xff,0xEf}; // Hexadecimal values for the 7 Segment display generated by the look up table
{
DDRA=0xFF;
DDRB=0xFF;
//*********************TIMER***(8MHz crystal....clk/1024 prescaler......Obtained 25ms delay
TCNT0=61;
TCCR0=0x05;
TIMSK=(1<<TOIE0);
//*********************
sei();
while(1)
{
// for seconds
PORTB=0xFF;
PORTA=ssd[(ss)/10];