SlideShare a Scribd company logo
// LED 7 ĐOẠN TĂNG DẦN KHI BẤM 
NÚT 
#include <REGX51.H> 
unsigned char x=0; 
void hien_thi(char x); 
void main() 
{ 
while (1) 
{ 
hien_thi(x); 
if (P2_7==0) 
x=x+1; 
if (x>9) 
x=0; 
while (P2_7==0) 
hien_thi(x); 
} 
} 
void hien_thi(char x) 
{ 
switch (x) 
{ 
case 0: P0 = 0x40;break; 
case 1: P0 = 0x79;break; 
case 2: P0 = 0x24;break; 
case 3: P0 = 0x30 ;break; 
case 4: P0 = 0x19;break; 
case 5: P0 = 0x12;break; 
case 6: P0 = 0x02;break; 
case 7: P0 = 0x78 ;break; 
case 8: P0 = 0x00;break; 
case 9: P0 = 0x10 ;break; 
} 
} 
// LED 7 ĐOẠN 
TĂNG / GIẢM 
DẦN KHI BẤM 
NÚT 
#include 
<REGX51.H> 
unsigned char 
x=0; 
void 
hien_thi(char x); 
void main() 
{ 
while (1) 
{ 
hien_thi(x); 
if 
(P2_7==0) 
x=x+1; 
if 
(x==10) 
x=0; 
while 
(P2_7==0) 
hien_thi(x); 
if 
(P2_6==0) 
x = x - 
1; 
if (x = = - 
1) 
x = 9; 
while 
(P2_6 = = 0) 
hien_thi(x); 
} 
} 
void hien_thi(char 
x) 
{ 
switch (x) 
{ 
case 0: P0 
= 0x40;break; 
case 1: P0 
= 0x79;break; 
case 2: P0 
= 0x24;break; 
case 3: P0 
= 0x30 ;break; 
case 4: P0 
= 0x19;break; 
case 5: P0 
= 0x12;break; 
case 6: P0 
= 0x02;break; 
case 7: P0 
= 0x78 ;break; 
case 8: P0 
= 0x00;break; 
case 9: P0 
= 0x10 ;break; 
} 
} 
1
// ĐẾM TIẾN LÙI TỪ 
00 ĐẾN 99 
#include <reg52x2.h> 
#define DVI P3_1 
#define CHUC P3_0 
#define tang P1_1 
#define giam P1_0 
delay(int time); 
hien_thi(int number); 
void main(void) 
{ 
int phim_tang, 
phim_giam,sodem, 
d_vi,hang_chuc,i; 
sodem = 0; 
while(1) 
{ 
phim_tang = 
tang; 
if(phim_tan 
g = = 0) 
{ 
sode 
m++; 
if 
(sodem = =100) 
sodem=0; 
while 
(phim_tang = = 
0) phim_tang = 
tang; 
} 
phim_giam = 
giam; 
if(phim_giam = 
= 0) 
{ 
sode 
m--; 
if 
(sodem<0) 
sodem=0; 
while 
(phim_giam = = 
0) phim_giam = 
giam; 
} 
hang_chuc = 
sodem/10; 
d_vi = sodem 
- (hang_chuc*10); 
for 
(i=1;i<30;i++) 
{ 
DVI = 1; 
CHUC = 0; 
hien_thi(d_vi); 
} 
for 
(i=1;i<30;i++) 
{ 
CHUC = 1; 
DVI = 0; 
hien_thi(hang_chuc); 
}}} 
hien_thi (int number) 
{ 
switch (number) 
{ 
case 0: P2 = 
0x40;break; 
case 1: P2 = 
0x79;break; 
case 2: P2 = 
0x24;break; 
case 3: P2 = 
0x30 ;break; 
case 4: P2 = 
0x19;break; 
case 5: P2 = 
0x12;break; 
case 6: P2 = 
0x02;break; 
case 7: P2 = 
0x78 ;break; 
case 8: P2 = 
0x00;break; 
case 9: P2 = 
0x10 ;break; 
} 
P2 = 
0xff; 
} 
delay(int time) 
{ 
int k,l; 
for(k=1;k<time; 
k++) 
for(l=1;l<time;l+ 
+); 
}} 
#include 
<reg52x2.h> 
unsigned char i; 
void sangdan(); 
void tatdan(); 
void delay(long 
time); 
void 
2
sang_theo_tung_cap 
(); 
void main() 
{ 
while(1) 
{ 
P2=0x00; 
delay(2000); 
sangdan(); 
delay(2000); 
tatdan(); 
delay(2000); 
sang_theo_tung_c 
ap(); delay(2000); 
} 
} 
void delay(long 
time) 
{ 
long t; 
for 
(t=0;t<=time;t++) 
{ } 
} 
void sangdan( ) 
{ 
unsigned char 
sangdan[ ] = 
{0x01,0x03,0x07,0x0 
f,0x1f,0x3f,0x7f,0xff} 
; 
for (i=0;i<=7;i++) 
{ 
P2=sangdan[i 
]; delay(2000); 
} 
} 
void tatdan() 
{ 
unsigned char 
sangdan[ ] = 
{0x01,0x03,0x07,0 
x0f,0x1f,0x3f,0x7f, 
0xff}; 
for 
(i=0;i<=7;i++) 
{ 
P2 = ~ 
sangdan[i]; 
delay(2000); 
} 
} 
void 
sang_theo_tung_ca 
p( ) 
{ 
unsigned char 
sang_theo_tung_ca 
p[ ] = 
{0x81,0xc3,0xe7,0x 
ff}; 
for (i=0;i<=3;i+ 
+) 
{ 
P2=sang_theo_tun 
g_cap[i]; 
delay(2000); 
} 
} 
// BÁO ĐỘNG 
#include 
<reg52x2.h> 
#define hoatdong 
P1_0 
#define n1 P0_0 
#define n2 P0_1 
#define n3 P0_2 
#define n4 P0_3 
#define button P3_7 
#define baodong 
P3_0 
void main(void) 
{ 
int phim_hd, 
nut_n1,nut_n2,nut_n3, 
nut_n4, nut_button; 
int dem1,temp; 
baodong = 0; 
while (1) 
{ 
temp = 0; 
phim_hd = 
hoatdong; 
if ( phim_hd 
= = 0 ) 
{ 
temp = 1; 
baodong = 0; 
while ( phim_hd = = 0 ) 
phim_hd = hoatdong; 
} 
while (temp= =1) 
{ 
nut_button = button; 
if (nut_button = = 1) 
baodong = 1; 
nut_n1 = n1; 
nut_n2 = n2; 
nut_n3 = n3; 
nut_n4 = n4; 
if (nut_n1 == 0) 
{ 
if (dem1= =0) dem1 
= 1; else dem1=0; 
while (nut_n1 = = 0) 
nut_n1 = n1; 
} 
if (nut_n2 = = 0) 
{ 
3
if (dem1= =1) dem1 
= 2; else dem1=0; 
while (nut_n2 == 
0) nut_n2 = n2; 
} 
if (nut_n3 = = 0) 
{ 
if (dem1= =2) dem1 = 
3; else dem1=0; 
while (nut_n3 == 0) 
nut_n3 = n3; 
} 
if (nut_n4 = = 0) 
{ 
if (dem1= =3) dem1 
= 4; else dem1=0; 
while (nut_n4 = = 
0) nut_n4 = n4; 
} 
if (dem1 = =4) 
{baodong = 0; 
temp=0; dem1=0;} 
}}} 
// CHẠY XUỐNG / 
LÊN 
#include <reg52x2.h> 
int luythua (a,b); 
void delay (int time); 
void main ( ) 
{ 
//HIỂN THỊ CHỮ 
“T” 
#include <reg52x2.h> 
#define hang P2 
#define cot P3 
void main(void) 
{ int i,k; 
int i,x,t; 
t = 1000; 
while(1) 
{ 
P2 = 0; 
for (i=0; i<8; i++) 
{P2 = luythua (2, i); 
delay (t);} 
for (i=7; i>0; i - -) 
{P2 = luythua (2, i); 
delay (t);}}} 
void delay(int time) 
{ 
int i; 
for(i=0;i<time;i++); 
} 
int luythua(a,b) 
{ 
int x,k; 
x = 1; 
for(k=0;k<b;k++) x=x*a; 
return(x); 
} 
int gt_hang[8], 
gt_cot[8]; 
for(i = 1;i<9;i++) 
gt_cot[i] = 2^(i-1); 
gt_cot[1] = 1; 
gt_cot[2] = 2; 
gt_cot[3] = 4; 
gt_cot[4] = 8; 
gt_cot[5] = 16; 
gt_cot[6] = 32; 
gt_cot[7] = 64; 
gt_cot[8] = 128; 
gt_hang[1]= 0xfc; 
gt_hang[2]= 0xfc; 
gt_hang[3]= 0xfc; 
gt_hang[4]= 0x00; 
gt_hang[5]= 0x00; 
gt_hang[6]= 0xfc; 
gt_hang[7]= 0xfc; 
gt_hang[8]= 0xfc; 
while(1) 
{ 
for (i=1;i<9;i++) 
{ 
for(k=0;k<10;k++) 
{ 
cot = gt_cot[i]; hang = 
gt_hang[i]; 
} 
} 
} 
} 
// ĐẾM TỪ 00 ĐẾN 99 RỒI LẶP LẠI, 
12MHz 
#include"regx51.h" 
#define Led_dv P3_0 
#define Led_chuc P3_1 
unsigned char 
Ma[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x8 
2,0xf8,0x80,0x90}; 
int a, b, c, d, k; 
void delay(unsigned long int t) 
{ 
unsigned long int l; 
4
for(l=0;l<t;l++); 
} 
void main() 
{ 
int i; 
while(1) 
{ 
for(k=0;k<=99;k++) 
{ 
a=k/10; 
b=k%10; 
for(i=0;i<20;i++) 
{ 
Led_dv=1; 
P2=Ma[a]; 
delay(400); 
Led_dv=0; 
P2=0xff;//xoa data 
Led_chuc=1; 
P2=Ma[b]; 
delay(400); 
Led_chuc=0; 
P2=0xff; 
} 
} 
} 
} 
// ĐẾM TỪ 0000 ĐẾN 9999 RỒI 
LẶP LẠI, 12MHz 
#include<reg51.h> 
unsigned char 
Ma[10]={0xc0,0xf9,0xa4,0xb0, 
0x99,0x92,0x82,0xf8,0x80,0x9 
0}; 
unsigned char 
num=0,donvi,chuc,tram,nghin; 
void 
delay(unsig 
ned long int 
t) 
{ 
unsigne 
d long int l; 
for(l=0;l 
<t;l++); 
} 
void DCB(void) 
{ 
nghin=num/1000; 
tram=(num%1000)/100; 
chuc=(num%100)/10; 
donvi=num%10; 
} 
void HIEN_THI(void) 
{ 
P0=Ma[nghin]; 
P2=0x1; 
delay(130); 
P2=0; 
P0=0xFF; 
P0=Ma[tram]; 
P2=0x2; 
delay(130); 
P2=0; 
P0=0xFF; 
P0=Ma[chuc]; 
P2=0x4; 
delay(130); 
P2=0; 
P0=0xFF; 
P0=Ma[donvi]; 
P2=0x8; 
delay(130); 
P2=0; 
P0=0xFF; 
} 
void main(void) 
{ 
while(1) 
{ 
unsigned a; 
for(a=0;a<30;a++) 
{ 
DCB(); 
HIEN_THI( 
); 
} 
num=num+ 
1; 
if (num= 
=10000)nu 
m=0; 
} 
} 
Đề năm 2013/06/15 
5
#include <REGX51.H> 
unsigned char x=0,y; 
void hien_thi_chu(char y); 
void hien_thi_so(char x); 
void main() 
{ 
while (1) 
{ 
hien_thi_so (x); 
if (P3_0==0) 
x=x+1; 
if (x==10) 
x=9; 
while (P3_0==0) 
{ 
while (P3_1==0) 
{ 
hien_thi_chu(1); 
} 
hien_thi_so (x); 
} 
if (P3_1==0) 
x=x-1; 
if (x == - 1) 
x=0; 
while (P3_1 == 0) 
{ 
while (P3_0==0) 
{ 
hien_thi_chu(2); 
} 
hien_thi_so (x); 
} 
} 
} 
void hien_thi_so (char x) 
{ 
switch (x) 
{ 
case 0: P2 = 0x40;break; 
case 1: P2 = 0x79;break; 
case 2: P2 = 0x24;break; 
case 3: P2 = 0x30 ;break; 
case 4: P2 = 0x19;break; 
case 5: P2 = 0x12;break; 
case 6: P2 = 0x02;break; 
case 7: P2 = 0x78 ;break; 
case 8: P2 = 0x00;break; 
case 9: P2 = 0x10 ;break; 
} 
} 
void hien_thi_chu (char y) 
{ 
switch (y) 
{ 
case 1: P2 = 0x08;break; 
case 2: P2 = 0x03;break; 
} 
} 
6
#include <REGX51.H> 
unsigned char x=0,y; 
void hien_thi_chu(char y); 
void hien_thi_so(char x); 
void main() 
{ 
while (1) 
{ 
hien_thi_so (x); 
if (P3_0==0) 
x=x+1; 
if (x==10) 
x=9; 
while (P3_0==0) 
{ 
while (P3_1==0) 
{ 
hien_thi_chu(1); 
} 
hien_thi_so (x); 
} 
if (P3_1==0) 
x=x-1; 
if (x == - 1) 
x=0; 
while (P3_1 == 0) 
{ 
while (P3_0==0) 
{ 
hien_thi_chu(2); 
} 
hien_thi_so (x); 
} 
} 
} 
void hien_thi_so (char x) 
{ 
switch (x) 
{ 
case 0: P2 = 0x40;break; 
case 1: P2 = 0x79;break; 
case 2: P2 = 0x24;break; 
case 3: P2 = 0x30 ;break; 
case 4: P2 = 0x19;break; 
case 5: P2 = 0x12;break; 
case 6: P2 = 0x02;break; 
case 7: P2 = 0x78 ;break; 
case 8: P2 = 0x00;break; 
case 9: P2 = 0x10 ;break; 
} 
} 
void hien_thi_chu (char y) 
{ 
switch (y) 
{ 
case 1: P2 = 0x08;break; 
case 2: P2 = 0x03;break; 
} 
} 
6

More Related Content

What's hot

Operating system and embedded systems
Operating system and embedded systemsOperating system and embedded systems
Operating system and embedded systems
gayatrigayu1
 
3
33
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
corehard_by
 
Алексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereАлексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhere
Sergey Platonov
 
Nested micro
Nested microNested micro
Nested micro
Satyamevjayte Haxor
 
Main Form Number To Word
Main Form Number To WordMain Form Number To Word
Main Form Number To Word
Nanthachai Poolketgij
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
Timur Safin
 
C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)
Yuki Tamura
 
Computer Programming- Lecture 4
Computer Programming- Lecture 4Computer Programming- Lecture 4
Computer Programming- Lecture 4
Dr. Md. Shohel Sayeed
 
Voce Tem Orgulho Do Seu Codigo
Voce Tem Orgulho Do Seu CodigoVoce Tem Orgulho Do Seu Codigo
Voce Tem Orgulho Do Seu Codigo
Victor Hugo Germano
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources
輝 子安
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errors
PVS-Studio
 
Percobaan 1
Percobaan 1Percobaan 1
Percobaan 1
Antoso Djoko
 
project3
project3project3
project3
Russell Rawls
 
Bai Giang 11
Bai Giang 11Bai Giang 11
Bai Giang 11
nbb3i
 
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
Iosif Itkin
 
Gaurav Jatav , BCA Third Year
Gaurav Jatav , BCA Third YearGaurav Jatav , BCA Third Year
Gaurav Jatav , BCA Third Year
dezyneecole
 
Breaking the wall
Breaking the wallBreaking the wall
Breaking the wall
Taras Kalapun
 
Server
ServerServer
Server
marveenstein
 

What's hot (19)

Operating system and embedded systems
Operating system and embedded systemsOperating system and embedded systems
Operating system and embedded systems
 
3
33
3
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
 
Алексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereАлексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhere
 
Nested micro
Nested microNested micro
Nested micro
 
Main Form Number To Word
Main Form Number To WordMain Form Number To Word
Main Form Number To Word
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)
 
Computer Programming- Lecture 4
Computer Programming- Lecture 4Computer Programming- Lecture 4
Computer Programming- Lecture 4
 
Voce Tem Orgulho Do Seu Codigo
Voce Tem Orgulho Do Seu CodigoVoce Tem Orgulho Do Seu Codigo
Voce Tem Orgulho Do Seu Codigo
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errors
 
Percobaan 1
Percobaan 1Percobaan 1
Percobaan 1
 
project3
project3project3
project3
 
Bai Giang 11
Bai Giang 11Bai Giang 11
Bai Giang 11
 
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
 
Gaurav Jatav , BCA Third Year
Gaurav Jatav , BCA Third YearGaurav Jatav , BCA Third Year
Gaurav Jatav , BCA Third Year
 
Breaking the wall
Breaking the wallBreaking the wall
Breaking the wall
 
Server
ServerServer
Server
 

Viewers also liked

Tere
Tere Tere
CEIP Alcalde Rafael Cedrés - Día de La Infancia
CEIP Alcalde Rafael Cedrés - Día de La InfanciaCEIP Alcalde Rafael Cedrés - Día de La Infancia
CEIP Alcalde Rafael Cedrés - Día de La Infancia
Manuel Negrín Perdomo
 
Lietuva ir es
Lietuva ir  esLietuva ir  es
Lietuva ir es
agni197
 
SGQ in Anatomia Patologica
SGQ in Anatomia PatologicaSGQ in Anatomia Patologica
SGQ in Anatomia Patologica
BFrollano2704
 
Felicitación Navideña 2015 - CEIP La Cerruda
Felicitación Navideña 2015 - CEIP La CerrudaFelicitación Navideña 2015 - CEIP La Cerruda
Felicitación Navideña 2015 - CEIP La Cerruda
Manuel Negrín Perdomo
 
What are kpi targets
What are kpi targetsWhat are kpi targets
What are kpi targets
singfletjones
 
CERTIFICATE
CERTIFICATECERTIFICATE
CERTIFICATE
Huseyin Ozer
 
FAQ PAU - IES Lomo Apolinario
FAQ PAU - IES Lomo ApolinarioFAQ PAU - IES Lomo Apolinario
FAQ PAU - IES Lomo Apolinario
Manuel Negrín Perdomo
 
Gioco Vase - Vase Erasmus +
Gioco Vase - Vase Erasmus +Gioco Vase - Vase Erasmus +
Gioco Vase - Vase Erasmus +
Manuel Negrín Perdomo
 
Presentación red ecos IES Lomo Apolinario
Presentación red ecos  IES Lomo ApolinarioPresentación red ecos  IES Lomo Apolinario
Presentación red ecos IES Lomo Apolinario
Manuel Negrín Perdomo
 
Sales kpi dashboard
Sales kpi dashboardSales kpi dashboard
Sales kpi dashboard
singfletjones
 
A.Yasser ( Mechatronics Engineer ) CV
A.Yasser ( Mechatronics Engineer ) CVA.Yasser ( Mechatronics Engineer ) CV
A.Yasser ( Mechatronics Engineer ) CV
Ahmed Qaitbay
 

Viewers also liked (13)

Tere
Tere Tere
Tere
 
CEIP Alcalde Rafael Cedrés - Día de La Infancia
CEIP Alcalde Rafael Cedrés - Día de La InfanciaCEIP Alcalde Rafael Cedrés - Día de La Infancia
CEIP Alcalde Rafael Cedrés - Día de La Infancia
 
Lietuva ir es
Lietuva ir  esLietuva ir  es
Lietuva ir es
 
SGQ in Anatomia Patologica
SGQ in Anatomia PatologicaSGQ in Anatomia Patologica
SGQ in Anatomia Patologica
 
Felicitación Navideña 2015 - CEIP La Cerruda
Felicitación Navideña 2015 - CEIP La CerrudaFelicitación Navideña 2015 - CEIP La Cerruda
Felicitación Navideña 2015 - CEIP La Cerruda
 
What are kpi targets
What are kpi targetsWhat are kpi targets
What are kpi targets
 
CERTIFICATE
CERTIFICATECERTIFICATE
CERTIFICATE
 
FAQ PAU - IES Lomo Apolinario
FAQ PAU - IES Lomo ApolinarioFAQ PAU - IES Lomo Apolinario
FAQ PAU - IES Lomo Apolinario
 
Gioco Vase - Vase Erasmus +
Gioco Vase - Vase Erasmus +Gioco Vase - Vase Erasmus +
Gioco Vase - Vase Erasmus +
 
DMS Certificate
DMS CertificateDMS Certificate
DMS Certificate
 
Presentación red ecos IES Lomo Apolinario
Presentación red ecos  IES Lomo ApolinarioPresentación red ecos  IES Lomo Apolinario
Presentación red ecos IES Lomo Apolinario
 
Sales kpi dashboard
Sales kpi dashboardSales kpi dashboard
Sales kpi dashboard
 
A.Yasser ( Mechatronics Engineer ) CV
A.Yasser ( Mechatronics Engineer ) CVA.Yasser ( Mechatronics Engineer ) CV
A.Yasser ( Mechatronics Engineer ) CV
 

Similar to Tai lieu ky thuat lap trinh

8051 -5
8051 -58051 -5
Snake.c
Snake.cSnake.c
Snake.c
Vijay Singh
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
anishgoel
 
REPORT
REPORTREPORT
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
kkkseld
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
Syed Ghufran Hassan
 
Aodv routing protocol code in ns2
Aodv routing protocol code in ns2Aodv routing protocol code in ns2
Aodv routing protocol code in ns2
Prof Ansari
 
Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018
Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018
Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018
UVCE
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
SANTIAGO PABLO ALBERTO
 
Program interfacing lab
Program interfacing labProgram interfacing lab
Program interfacing lab
noorahamed tahasildar
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
Kandarp Tiwari
 
Jamming attack in wireless network
Jamming attack in wireless networkJamming attack in wireless network
Jamming attack in wireless network
Thesis Scientist Private Limited
 
ANS#include iostream int Rn_get(int low, int high); int cva.pdf
ANS#include iostream int Rn_get(int low, int high); int cva.pdfANS#include iostream int Rn_get(int low, int high); int cva.pdf
ANS#include iostream int Rn_get(int low, int high); int cva.pdf
anikkothari1
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
Chaitanya Kn
 
Senior design project code for PPG
Senior design project code for PPGSenior design project code for PPG
Senior design project code for PPG
FrankDin1
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
PVS-Studio LLC
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
Programming Homework Help
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better code
Dror Helper
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
apexelectronices01
 
7segment scetch
7segment scetch7segment scetch
7segment scetch
Bang Igo
 

Similar to Tai lieu ky thuat lap trinh (20)

8051 -5
8051 -58051 -5
8051 -5
 
Snake.c
Snake.cSnake.c
Snake.c
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
 
REPORT
REPORTREPORT
REPORT
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
Aodv routing protocol code in ns2
Aodv routing protocol code in ns2Aodv routing protocol code in ns2
Aodv routing protocol code in ns2
 
Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018
Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018
Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
Program interfacing lab
Program interfacing labProgram interfacing lab
Program interfacing lab
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Jamming attack in wireless network
Jamming attack in wireless networkJamming attack in wireless network
Jamming attack in wireless network
 
ANS#include iostream int Rn_get(int low, int high); int cva.pdf
ANS#include iostream int Rn_get(int low, int high); int cva.pdfANS#include iostream int Rn_get(int low, int high); int cva.pdf
ANS#include iostream int Rn_get(int low, int high); int cva.pdf
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
Senior design project code for PPG
Senior design project code for PPGSenior design project code for PPG
Senior design project code for PPG
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better code
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
 
7segment scetch
7segment scetch7segment scetch
7segment scetch
 

Recently uploaded

Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 

Recently uploaded (20)

Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 

Tai lieu ky thuat lap trinh

  • 1. // LED 7 ĐOẠN TĂNG DẦN KHI BẤM NÚT #include <REGX51.H> unsigned char x=0; void hien_thi(char x); void main() { while (1) { hien_thi(x); if (P2_7==0) x=x+1; if (x>9) x=0; while (P2_7==0) hien_thi(x); } } void hien_thi(char x) { switch (x) { case 0: P0 = 0x40;break; case 1: P0 = 0x79;break; case 2: P0 = 0x24;break; case 3: P0 = 0x30 ;break; case 4: P0 = 0x19;break; case 5: P0 = 0x12;break; case 6: P0 = 0x02;break; case 7: P0 = 0x78 ;break; case 8: P0 = 0x00;break; case 9: P0 = 0x10 ;break; } } // LED 7 ĐOẠN TĂNG / GIẢM DẦN KHI BẤM NÚT #include <REGX51.H> unsigned char x=0; void hien_thi(char x); void main() { while (1) { hien_thi(x); if (P2_7==0) x=x+1; if (x==10) x=0; while (P2_7==0) hien_thi(x); if (P2_6==0) x = x - 1; if (x = = - 1) x = 9; while (P2_6 = = 0) hien_thi(x); } } void hien_thi(char x) { switch (x) { case 0: P0 = 0x40;break; case 1: P0 = 0x79;break; case 2: P0 = 0x24;break; case 3: P0 = 0x30 ;break; case 4: P0 = 0x19;break; case 5: P0 = 0x12;break; case 6: P0 = 0x02;break; case 7: P0 = 0x78 ;break; case 8: P0 = 0x00;break; case 9: P0 = 0x10 ;break; } } 1
  • 2. // ĐẾM TIẾN LÙI TỪ 00 ĐẾN 99 #include <reg52x2.h> #define DVI P3_1 #define CHUC P3_0 #define tang P1_1 #define giam P1_0 delay(int time); hien_thi(int number); void main(void) { int phim_tang, phim_giam,sodem, d_vi,hang_chuc,i; sodem = 0; while(1) { phim_tang = tang; if(phim_tan g = = 0) { sode m++; if (sodem = =100) sodem=0; while (phim_tang = = 0) phim_tang = tang; } phim_giam = giam; if(phim_giam = = 0) { sode m--; if (sodem<0) sodem=0; while (phim_giam = = 0) phim_giam = giam; } hang_chuc = sodem/10; d_vi = sodem - (hang_chuc*10); for (i=1;i<30;i++) { DVI = 1; CHUC = 0; hien_thi(d_vi); } for (i=1;i<30;i++) { CHUC = 1; DVI = 0; hien_thi(hang_chuc); }}} hien_thi (int number) { switch (number) { case 0: P2 = 0x40;break; case 1: P2 = 0x79;break; case 2: P2 = 0x24;break; case 3: P2 = 0x30 ;break; case 4: P2 = 0x19;break; case 5: P2 = 0x12;break; case 6: P2 = 0x02;break; case 7: P2 = 0x78 ;break; case 8: P2 = 0x00;break; case 9: P2 = 0x10 ;break; } P2 = 0xff; } delay(int time) { int k,l; for(k=1;k<time; k++) for(l=1;l<time;l+ +); }} #include <reg52x2.h> unsigned char i; void sangdan(); void tatdan(); void delay(long time); void 2
  • 3. sang_theo_tung_cap (); void main() { while(1) { P2=0x00; delay(2000); sangdan(); delay(2000); tatdan(); delay(2000); sang_theo_tung_c ap(); delay(2000); } } void delay(long time) { long t; for (t=0;t<=time;t++) { } } void sangdan( ) { unsigned char sangdan[ ] = {0x01,0x03,0x07,0x0 f,0x1f,0x3f,0x7f,0xff} ; for (i=0;i<=7;i++) { P2=sangdan[i ]; delay(2000); } } void tatdan() { unsigned char sangdan[ ] = {0x01,0x03,0x07,0 x0f,0x1f,0x3f,0x7f, 0xff}; for (i=0;i<=7;i++) { P2 = ~ sangdan[i]; delay(2000); } } void sang_theo_tung_ca p( ) { unsigned char sang_theo_tung_ca p[ ] = {0x81,0xc3,0xe7,0x ff}; for (i=0;i<=3;i+ +) { P2=sang_theo_tun g_cap[i]; delay(2000); } } // BÁO ĐỘNG #include <reg52x2.h> #define hoatdong P1_0 #define n1 P0_0 #define n2 P0_1 #define n3 P0_2 #define n4 P0_3 #define button P3_7 #define baodong P3_0 void main(void) { int phim_hd, nut_n1,nut_n2,nut_n3, nut_n4, nut_button; int dem1,temp; baodong = 0; while (1) { temp = 0; phim_hd = hoatdong; if ( phim_hd = = 0 ) { temp = 1; baodong = 0; while ( phim_hd = = 0 ) phim_hd = hoatdong; } while (temp= =1) { nut_button = button; if (nut_button = = 1) baodong = 1; nut_n1 = n1; nut_n2 = n2; nut_n3 = n3; nut_n4 = n4; if (nut_n1 == 0) { if (dem1= =0) dem1 = 1; else dem1=0; while (nut_n1 = = 0) nut_n1 = n1; } if (nut_n2 = = 0) { 3
  • 4. if (dem1= =1) dem1 = 2; else dem1=0; while (nut_n2 == 0) nut_n2 = n2; } if (nut_n3 = = 0) { if (dem1= =2) dem1 = 3; else dem1=0; while (nut_n3 == 0) nut_n3 = n3; } if (nut_n4 = = 0) { if (dem1= =3) dem1 = 4; else dem1=0; while (nut_n4 = = 0) nut_n4 = n4; } if (dem1 = =4) {baodong = 0; temp=0; dem1=0;} }}} // CHẠY XUỐNG / LÊN #include <reg52x2.h> int luythua (a,b); void delay (int time); void main ( ) { //HIỂN THỊ CHỮ “T” #include <reg52x2.h> #define hang P2 #define cot P3 void main(void) { int i,k; int i,x,t; t = 1000; while(1) { P2 = 0; for (i=0; i<8; i++) {P2 = luythua (2, i); delay (t);} for (i=7; i>0; i - -) {P2 = luythua (2, i); delay (t);}}} void delay(int time) { int i; for(i=0;i<time;i++); } int luythua(a,b) { int x,k; x = 1; for(k=0;k<b;k++) x=x*a; return(x); } int gt_hang[8], gt_cot[8]; for(i = 1;i<9;i++) gt_cot[i] = 2^(i-1); gt_cot[1] = 1; gt_cot[2] = 2; gt_cot[3] = 4; gt_cot[4] = 8; gt_cot[5] = 16; gt_cot[6] = 32; gt_cot[7] = 64; gt_cot[8] = 128; gt_hang[1]= 0xfc; gt_hang[2]= 0xfc; gt_hang[3]= 0xfc; gt_hang[4]= 0x00; gt_hang[5]= 0x00; gt_hang[6]= 0xfc; gt_hang[7]= 0xfc; gt_hang[8]= 0xfc; while(1) { for (i=1;i<9;i++) { for(k=0;k<10;k++) { cot = gt_cot[i]; hang = gt_hang[i]; } } } } // ĐẾM TỪ 00 ĐẾN 99 RỒI LẶP LẠI, 12MHz #include"regx51.h" #define Led_dv P3_0 #define Led_chuc P3_1 unsigned char Ma[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x8 2,0xf8,0x80,0x90}; int a, b, c, d, k; void delay(unsigned long int t) { unsigned long int l; 4
  • 5. for(l=0;l<t;l++); } void main() { int i; while(1) { for(k=0;k<=99;k++) { a=k/10; b=k%10; for(i=0;i<20;i++) { Led_dv=1; P2=Ma[a]; delay(400); Led_dv=0; P2=0xff;//xoa data Led_chuc=1; P2=Ma[b]; delay(400); Led_chuc=0; P2=0xff; } } } } // ĐẾM TỪ 0000 ĐẾN 9999 RỒI LẶP LẠI, 12MHz #include<reg51.h> unsigned char Ma[10]={0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8,0x80,0x9 0}; unsigned char num=0,donvi,chuc,tram,nghin; void delay(unsig ned long int t) { unsigne d long int l; for(l=0;l <t;l++); } void DCB(void) { nghin=num/1000; tram=(num%1000)/100; chuc=(num%100)/10; donvi=num%10; } void HIEN_THI(void) { P0=Ma[nghin]; P2=0x1; delay(130); P2=0; P0=0xFF; P0=Ma[tram]; P2=0x2; delay(130); P2=0; P0=0xFF; P0=Ma[chuc]; P2=0x4; delay(130); P2=0; P0=0xFF; P0=Ma[donvi]; P2=0x8; delay(130); P2=0; P0=0xFF; } void main(void) { while(1) { unsigned a; for(a=0;a<30;a++) { DCB(); HIEN_THI( ); } num=num+ 1; if (num= =10000)nu m=0; } } Đề năm 2013/06/15 5
  • 6. #include <REGX51.H> unsigned char x=0,y; void hien_thi_chu(char y); void hien_thi_so(char x); void main() { while (1) { hien_thi_so (x); if (P3_0==0) x=x+1; if (x==10) x=9; while (P3_0==0) { while (P3_1==0) { hien_thi_chu(1); } hien_thi_so (x); } if (P3_1==0) x=x-1; if (x == - 1) x=0; while (P3_1 == 0) { while (P3_0==0) { hien_thi_chu(2); } hien_thi_so (x); } } } void hien_thi_so (char x) { switch (x) { case 0: P2 = 0x40;break; case 1: P2 = 0x79;break; case 2: P2 = 0x24;break; case 3: P2 = 0x30 ;break; case 4: P2 = 0x19;break; case 5: P2 = 0x12;break; case 6: P2 = 0x02;break; case 7: P2 = 0x78 ;break; case 8: P2 = 0x00;break; case 9: P2 = 0x10 ;break; } } void hien_thi_chu (char y) { switch (y) { case 1: P2 = 0x08;break; case 2: P2 = 0x03;break; } } 6
  • 7. #include <REGX51.H> unsigned char x=0,y; void hien_thi_chu(char y); void hien_thi_so(char x); void main() { while (1) { hien_thi_so (x); if (P3_0==0) x=x+1; if (x==10) x=9; while (P3_0==0) { while (P3_1==0) { hien_thi_chu(1); } hien_thi_so (x); } if (P3_1==0) x=x-1; if (x == - 1) x=0; while (P3_1 == 0) { while (P3_0==0) { hien_thi_chu(2); } hien_thi_so (x); } } } void hien_thi_so (char x) { switch (x) { case 0: P2 = 0x40;break; case 1: P2 = 0x79;break; case 2: P2 = 0x24;break; case 3: P2 = 0x30 ;break; case 4: P2 = 0x19;break; case 5: P2 = 0x12;break; case 6: P2 = 0x02;break; case 7: P2 = 0x78 ;break; case 8: P2 = 0x00;break; case 9: P2 = 0x10 ;break; } } void hien_thi_chu (char y) { switch (y) { case 1: P2 = 0x08;break; case 2: P2 = 0x03;break; } } 6