Professional Documents
Culture Documents
Jay Deep - Display - Interfacing - With - 8051 - Primer PDF
Jay Deep - Display - Interfacing - With - 8051 - Primer PDF
Digit 2 P3.5
Digit 3 P3.6
Digit - 4 P3.7
VCC
Seg - a P1.0
1
1K
Digit - 1 2
Seg b
3
P1.1
U1
8
Seg c seg-a 7
CA
CA
A
P1.2 Seg-b
Seg-c
6
4 B
seg-d 2 C
Segment Lines
seg-e 1 D
Seg d P1.3
seg-f
seg-g
9
10
E
F
a seg--dp 5 G
DP
Seg e P1.4
f g b 7 SEG DISP
Seg dp P1.7
+5V
SW30
OFF 1 8 ON
Make switch SW30 to 2 7
7SEG
LCD
3 6 SM/RL
7SEG label marking position 4 5 GLCD
PWR ON/OFF
Source Code
#include<stdio.h>
#include<reg51.h>
unsigned char SetDisplay(unsigned char);
void delay();
sbit eseg1000 = P3^7;
sbit eseg100 = P3^6;
sbit eseg10 = P3^5;
sbit eseg1 = P3^4;
//--------------
//Delay Function
//--------------
void delay()
{
int i;
for(i=0; i<500; i++)
i = i + 0;
}
//--------------
//Main Program
//--------------
void main(void)
{
unsigned char count = 0;
unsigned long timer = 0;
int turn = 1;
P2 = 0xff;
while(1)
{
if(turn==1) //7-Seg Display 0
eseg1000=0;
eseg100=0;
eseg10=0;
eseg1=1;
P1=SetDisplay(d0);
turn = 2;
delay();
}
else if(turn==2) //7-Seg Display 1
{
eseg1=0;
eseg1000=0;
eseg100=0;
eseg10=1;
P1=SetDisplay(d1);
turn = 3;
delay();
}
else if(turn==3) //7-Seg Display 2
{
eseg10=0;
eseg1=0;
P1=SetDisplay(d2);
turn = 0;
delay();
}
else //7-Seg Display 3
{
eseg100=0;
eseg10=0;
eseg1=0;
eseg1000=1;
P1=SetDisplay(d3);
turn = 1;
delay();
}
if(timer == 100){
d0++;
timer=0;
if(d0>=10){
d0=0;
d1++;
if(d2>=10){
d2=0;
d3++;
if(d3>=10){
d3=0;
}
}
}
}
}
timer++;
}
}