Ticker

6/recent/ticker-posts

Interfacing Seven Segment Display



I put 7SEG-MPX4-CC at Port 2 and pushbutton at Port 1. If i press the pushbutton it will count down from 25 to 0 and when reach 0 it will display stop. It easy just store the hex number for 7 segment and then do program for one and tens for 7 segment.

Program c++ for Keil

#include
sbit PB1 = P1^0;
sbit D3= P3^0;
sbit D2=P3^1;
sbit D1=P3^2;
sbit D0=P3^3;
void delay_ms (int ms)
{
unsigned int i,j;
for (i=0;ifor (j=0;j<100 br="" j="">}
void countdown(void)
{
int count,delay;
unsigned char number [10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
for (count =25;count>-1;count--)
for (delay=0;delay<20 br="" delay=""> {
P3=0x17;
P2=number [count %10];
delay_ms(10);
P3=0x1B;
P2= number[count/10];
delay_ms(10);
}
}
void stop (void)
{
unsigned char stop[4] = {0x6D,0x78,0x3F,0x73};
{
D3=0;
P2 =0x6D;
delay_ms(5);
D3=1;
D2=0;
P2 =0x73;
delay_ms(5);
D2=1;
D1=0;
P2=0x3F;
delay_ms(5);
D1=1;
D0=0;
P2=0x73;
delay_ms(5);
D0=1;
}
}
void main (void)
{
if (PB1==0)
{
countdown();
stop();
}
}

Catat Ulasan

0 Ulasan