Bai 3

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 16

Bài Tập Bài 2

• Bài 1 :
#include <REGX52.H>
void delay(long n)
{
long i;
for(i=0;i<n;i++)
{;}
}
unsigned int led[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x80};
void main()
{
int i;
while(1)
{
for(i=0;i<9;i++) {P1=led[i]; delay(10000); }
}
}
Bài Tập Bài 2

• Bài 2:
void main()
{
int a,b,j;
while(1)
{
P1=0xff;
a =0xfe;
b =0x01;
for(j=0;j<8;j++){ P1=P1&a; a=a<<1; delay(5000); }
for(j=0;j<8;j++){ P1=P1|b; b=b<<1; delay(5000); }
}
}
Bài Tập Bài 2
• Bài 3:
void main(void)
{
led1 = tat; // ban dau led tat;
while(1)
{
if (( start==0)&& ( stop==1))
{ led1=bat;}
if (( start==1)&& ( stop==0))
{ led1=tat;}
}
}
Bài 3: LED_7_SEG

• Dương chung
• Âm chung
Bài 3: LED_7_SEG

7 6 4 2 1 10 9 5 A B C D E F G DP
7 6 4 2 1 10 9 5

D 13A
Anot chung D 12A
C a to t c h u n g

8 3
8 3
Bài 3: LED_7_SEG
Bài 3: LED_7_SEG
•Nguyên ly :
Bài 3: LED_7_SEG
Bài 3: LED_7_SEG
C¸c sè P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0 Sè n¹p hex
hiÓ dp g f e d c b a
n
thÞ
0 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 0 0
2 1 1 0 0 1 1 0 0
3 1 1 1 0 1 0 0 0
4 1 0 1 1 1 0 0 1
5 1 0 1 0 1 0 1 0
6 1 0 0 0 1 0 1 0
7 1 1 1 1 1 0 0 0
8 1 0 0 0 1 0 0 0
9 1 0 0 1 1 0 0 0
Bài 3: LED_7_SEG
C¸c sè P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0 Sè n¹p hex
hiÓ dp g f e d c b a
n
thÞ
0 1 1 0 0 0 0 0 0 0xc0
1 1 1 1 1 1 1 0 0 0xf9
2 1 1 0 0 1 1 0 0 0xa4
3 1 1 1 0 1 0 0 0 0xb0
4 1 0 1 1 1 0 0 1 0x99
5 1 0 1 0 1 0 1 0 0x92
6 1 0 0 0 1 0 1 0 0x82
7 1 1 1 1 1 0 0 0 0xf8
8 1 0 0 0 1 0 0 0 0x80
9 1 0 0 1 1 0 0 0 0x90
Bài 3: LED_7_SEG
Start

Khai bao ban dau

Delay()

Convert()

Display()

main()
Bài 3: LED_7_SEG

#include <at89x52.h>
unsigned char code maled7[] =
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
#define led1 P0_0
#define led2 P0_1
#define led3 P0_2
#define led4 P0_3
int i,j,k,l,a=0;
Bài 3: LED_7_SEG

void delay(long n)
{
long i;
for(i=0;i<n;i++)
{;}
}
Bài 3: LED_7_SEG

void convert(int x)
{
i = x % 10;
x = x / 10;
j = x % 10;
x = x / 10;
k = x % 10;
l = x / 10;
}
Bài 3: LED_7_SEG

void display(int x)
{
convert(x);
P0=0x00;led1=1; P1 = maled7[i]; delay(100);
P0=0x00;led2=1; P1 = maled7[j]; delay(100);
P0=0x00;led3=1; P1 = maled7[k]; delay(100);
P0=0x00;led4=1; P1 = maled7[l]; delay(100);
}
Bài 3: LED_7_SEG

void main()
{
while(1)
{
display(1234);
}
}

You might also like