SlideShare a Scribd company logo
1 of 7
// 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 systemsgayatrigayu1
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019corehard_by
 
Алексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereАлексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereSergey Platonov
 
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 BoFTimur Safin
 
C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)Yuki Tamura
 
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 errorsPVS-Studio
 
Bai Giang 11
Bai Giang 11Bai Giang 11
Bai Giang 11nbb3i
 
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 Yeardezyneecole
 

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

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

ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureanishgoel
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1kkkseld
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controllerSyed Ghufran Hassan
 
Aodv routing protocol code in ns2
Aodv routing protocol code in ns2Aodv routing protocol code in ns2
Aodv routing protocol code in ns2Prof 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 |11GUEE6018UVCE
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxSANTIAGO PABLO ALBERTO
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
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.pdfanikkothari1
 
Senior design project code for PPG
Senior design project code for PPGSenior design project code for PPG
Senior design project code for PPGFrankDin1
 
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++ codePVS-Studio LLC
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better codeDror 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.pdfapexelectronices01
 
7segment scetch
7segment scetch7segment scetch
7segment scetchBang 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

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

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