/* CAU TRUC PHAN CUNG
*vienngoai =>P0.3 ( TRANG ) va P0.4 ( DO )
*vientrong => P1.0 (VANG ) va P1.1
*vienduoi => P0.0 ( do ) + P0.1(xanh duong ) + P0.2 ( xanh la cay )
*chu ILU => I > P0.5
LOVE > P0.6
U > P0.7
*/
#include <REG51F.H>
#include <stdio.h>
sbit P1_0 = P1^0;
sbit P1_1 = P1^1;
sbit P0_0 = P0^0;
sbit P0_1 = P0^1;
sbit P0_2 = P0^2;
sbit P0_3 = P0^3;
sbit P0_4 = P0^4;
sbit P0_5 = P0^5;
sbit P0_6 = P0^6;
sbit P0_7 = P0^7;
/* KHAI BAO CAC CHUONG TRINH CON */
void delay(unsigned char time)
{
unsigned char j,i;
for(i=0;i<=120;i++)
for(j=0;j<=time;j++);
}
// Chuong trinh con vien ngoai //
void vienngoai_1(void) // Led duoi nhau nguoc-xuoi //
{
unsigned char a,a1,a2;
for(a=0;a<=50;a++)
{
P0_3=0;P0_4=1;delay(100);
P0_3=1;P0_4=0;delay(100);
}
for(a1=0;a1<=60;a1++)
{
P0_3=0; P0_4=1;delay(200);
P0_3=1;P0_4=0;delay(200);
}
for(a2=0;a2<=50;a2++)
{
P0_0=3;P0_4=1;delay(400);
P0_0=3;P0_4=0;delay(400);
}
}
void vienngoai_2(void) // Led do sang, led trang tat va nguoc lai //
{
unsigned char b,b1;
for(b=0;b<=50;b++)
{
P0_4=0;P0_3=1;delay(200);
}
for(b1=0;b1<=60;b1++)
{
P0_4=1;P0_3=0;delay(200);
}
}
void vienngoai_3(void) // Sang tat ca led vien ngoai //
{
P0_3=1;P0_4=1;
delay(300);
P0_3=0;P0_4=0;
delay(300);
}
void vienngoai(void)
{
unsigned char dem1,dem2,dem3;
for(dem1=0;dem1<=50;dem1++) vienngoai_1();
for(dem2=0;dem2<=50;dem2++) vienngoai_2();
for(dem3=0;dem3<=50;dem3++) vienngoai_3();
}
// Chuong trinh con vien trong //
void vientrong_1(void) // Led duoi nhau nguoc-xuoi //
{
unsigned char g,g1,g2;
for(g=0;g<=50;g++)
{
P1_0=0;P1_1=1;delay(100);
P1_0=1;P1_1=0;delay(100);
}
for(g1=0;g1<=60;g1++)
{
P1_0=0;P1_1=1;delay(200);
P1_0=1;P1_1=0;delay(200);
}
for(g2=0;g2<=50;g2++)
{
P1_0=0;P1_1=1;delay(400);
P1_0=1;P1_1=0;delay(400);
}
}
void vientrong_2(void) // Led xanh sang, vang tat //
{
unsigned char d,d1;
for(d=0;d<=10;d++)
{
P1_0=0;P1_1=1;
delay(400);
}
for(d1=0;d1<=10;d1++)
{
P1_0=1;P1_1=0;
delay(400);
}
}
void vientrong(void)
{
unsigned char e,e1;
for(e=0;e<=30;e++) vientrong_1();
for(e1=0;e1<=20;e1++) vientrong_2();
}
// Chuong trinh con chu I LOVE YOU //
void ilu_0(void) // Sang I LOVE YOU //
{
P0=0xff;
delay(200);
P0=0x00;
}
void ilu_1(void)// Sang lan luot I > LOVE > YOU va nguoc lai //
{
P0_5=1;P0_6=0;P0_7=0;delay(200); // duoi trai - phai //
P0_5=0;P0_6=1;P0_7=0;delay(200);
P0_5=0;P0_6=0;P0_7=1;delay(200);
P0_5=0;P0_6=0;P0_7=1;delay(200);// duoi phai - trai //
P0_5=0;P0_6=1;P0_7=0;delay(200);
P0_5=1;P0_6=0;P0_7=0;delay(200);
P0_5=1;P0_6=0;P0_7=1;delay(200);// sang I U;tat LOVE //
P0_5=0;P0_6=1;P0_7=0;delay(200);// sang LOVE tat I U //
}
void ilu_2(void)// sang don I > love > you //
{
P0_5=1;P0_6=0;P0_7=0;delay(200);
P0_5=1;P0_6=1;P0_7=0;delay(200);
P0_5=1;P0_6=1;P0_7=1;delay(200);
P0_5=0;P0_6=0;P0_7=1;delay(200);
P0_5=0;P0_6=1;P0_7=1;delay(200);
P0_5=1;P0_6=1;P0_7=1;delay(200);
}
void iloveyou(void)
{
unsigned char c,c1,c2;
for(c=0;c<=20;c++) ilu_0();
for(c1=0;c1<=20;c1++) ilu_1();
for(c2=0;c2<=20;c2++) ilu_2();
}
// Chuong trinh con vien duoi //
void vienduoi_0(void) // sang tat ca led vien duoi //
{
P0_0=0;P0_1=0;P0_2=0;
delay(100);
P0_0=1;P0_1=1;P0_2=1;
delay(100);
}
void vienduoi_1(void) // led duoi nguoi xuoi//
{
P0_0=1;P0_1=0;P0_2=0; delay(200);
P0_0=0;P0_1=1;P0_2=0; delay(200);
P0_0=0;P0_1=0;P0_2=1; delay(200);
P0_0=0;P0_1=0;P0_2=1; delay(200);
P0_0=0;P0_1=1;P0_2=0; delay(200);
P0_0=1;P0_1=0;P0_2=0; delay(200);
}
void vienduoi_2(void)// sang led do //
{
P0_0=1;P0_1=0;P0_2=0;
}
void vienduoi_3(void)//sang led xang duong //
{
P0_1=1;P0_0=0;P0_2=0;
}
void vienduoi_4(void)// sang led xanh la cay //
{
P0_2=1;P0_0=0;P0_1=0;
}
void vienduoi(void)
{
unsigned char f,f1,f2,f3,f4;
for(f=0;f<=10;f++) vienduoi_4();
for(f1=0;f1<=10;f1++) vienduoi_3();
for(f2=0;f2<=10;f2++) vienduoi_2();
for(f3=0;f3<=10;f3++) vienduoi_1();
for(f4=0;f4<=10;f4++) vienduoi_0();
}
/* CHUONG TRINH CHINH */
void main()
{ unsigned char q1,q2,q3,q4;
P1=0xff;P0=0xff;
delay(1000);
while(1)
{
for(q1=0;q1<=2;q1++) vienngoai();
for(q2=0;q2<=2;q2++) vientrong();
for(q3=0;q3<=2;q3++) vienduoi();
for(q4=0;q4<=2;q4++) iloveyou();
}
}
Khi chạy thực tế thì chỉ có chương trinh con vienngoai() chạy thôi, các chương trinh khác ko chạy ! Bác nào cao thủ giúp em với nha
*vienngoai =>P0.3 ( TRANG ) va P0.4 ( DO )
*vientrong => P1.0 (VANG ) va P1.1
*vienduoi => P0.0 ( do ) + P0.1(xanh duong ) + P0.2 ( xanh la cay )
*chu ILU => I > P0.5
LOVE > P0.6
U > P0.7
*/
#include <REG51F.H>
#include <stdio.h>
sbit P1_0 = P1^0;
sbit P1_1 = P1^1;
sbit P0_0 = P0^0;
sbit P0_1 = P0^1;
sbit P0_2 = P0^2;
sbit P0_3 = P0^3;
sbit P0_4 = P0^4;
sbit P0_5 = P0^5;
sbit P0_6 = P0^6;
sbit P0_7 = P0^7;
/* KHAI BAO CAC CHUONG TRINH CON */
void delay(unsigned char time)
{
unsigned char j,i;
for(i=0;i<=120;i++)
for(j=0;j<=time;j++);
}
// Chuong trinh con vien ngoai //
void vienngoai_1(void) // Led duoi nhau nguoc-xuoi //
{
unsigned char a,a1,a2;
for(a=0;a<=50;a++)
{
P0_3=0;P0_4=1;delay(100);
P0_3=1;P0_4=0;delay(100);
}
for(a1=0;a1<=60;a1++)
{
P0_3=0; P0_4=1;delay(200);
P0_3=1;P0_4=0;delay(200);
}
for(a2=0;a2<=50;a2++)
{
P0_0=3;P0_4=1;delay(400);
P0_0=3;P0_4=0;delay(400);
}
}
void vienngoai_2(void) // Led do sang, led trang tat va nguoc lai //
{
unsigned char b,b1;
for(b=0;b<=50;b++)
{
P0_4=0;P0_3=1;delay(200);
}
for(b1=0;b1<=60;b1++)
{
P0_4=1;P0_3=0;delay(200);
}
}
void vienngoai_3(void) // Sang tat ca led vien ngoai //
{
P0_3=1;P0_4=1;
delay(300);
P0_3=0;P0_4=0;
delay(300);
}
void vienngoai(void)
{
unsigned char dem1,dem2,dem3;
for(dem1=0;dem1<=50;dem1++) vienngoai_1();
for(dem2=0;dem2<=50;dem2++) vienngoai_2();
for(dem3=0;dem3<=50;dem3++) vienngoai_3();
}
// Chuong trinh con vien trong //
void vientrong_1(void) // Led duoi nhau nguoc-xuoi //
{
unsigned char g,g1,g2;
for(g=0;g<=50;g++)
{
P1_0=0;P1_1=1;delay(100);
P1_0=1;P1_1=0;delay(100);
}
for(g1=0;g1<=60;g1++)
{
P1_0=0;P1_1=1;delay(200);
P1_0=1;P1_1=0;delay(200);
}
for(g2=0;g2<=50;g2++)
{
P1_0=0;P1_1=1;delay(400);
P1_0=1;P1_1=0;delay(400);
}
}
void vientrong_2(void) // Led xanh sang, vang tat //
{
unsigned char d,d1;
for(d=0;d<=10;d++)
{
P1_0=0;P1_1=1;
delay(400);
}
for(d1=0;d1<=10;d1++)
{
P1_0=1;P1_1=0;
delay(400);
}
}
void vientrong(void)
{
unsigned char e,e1;
for(e=0;e<=30;e++) vientrong_1();
for(e1=0;e1<=20;e1++) vientrong_2();
}
// Chuong trinh con chu I LOVE YOU //
void ilu_0(void) // Sang I LOVE YOU //
{
P0=0xff;
delay(200);
P0=0x00;
}
void ilu_1(void)// Sang lan luot I > LOVE > YOU va nguoc lai //
{
P0_5=1;P0_6=0;P0_7=0;delay(200); // duoi trai - phai //
P0_5=0;P0_6=1;P0_7=0;delay(200);
P0_5=0;P0_6=0;P0_7=1;delay(200);
P0_5=0;P0_6=0;P0_7=1;delay(200);// duoi phai - trai //
P0_5=0;P0_6=1;P0_7=0;delay(200);
P0_5=1;P0_6=0;P0_7=0;delay(200);
P0_5=1;P0_6=0;P0_7=1;delay(200);// sang I U;tat LOVE //
P0_5=0;P0_6=1;P0_7=0;delay(200);// sang LOVE tat I U //
}
void ilu_2(void)// sang don I > love > you //
{
P0_5=1;P0_6=0;P0_7=0;delay(200);
P0_5=1;P0_6=1;P0_7=0;delay(200);
P0_5=1;P0_6=1;P0_7=1;delay(200);
P0_5=0;P0_6=0;P0_7=1;delay(200);
P0_5=0;P0_6=1;P0_7=1;delay(200);
P0_5=1;P0_6=1;P0_7=1;delay(200);
}
void iloveyou(void)
{
unsigned char c,c1,c2;
for(c=0;c<=20;c++) ilu_0();
for(c1=0;c1<=20;c1++) ilu_1();
for(c2=0;c2<=20;c2++) ilu_2();
}
// Chuong trinh con vien duoi //
void vienduoi_0(void) // sang tat ca led vien duoi //
{
P0_0=0;P0_1=0;P0_2=0;
delay(100);
P0_0=1;P0_1=1;P0_2=1;
delay(100);
}
void vienduoi_1(void) // led duoi nguoi xuoi//
{
P0_0=1;P0_1=0;P0_2=0; delay(200);
P0_0=0;P0_1=1;P0_2=0; delay(200);
P0_0=0;P0_1=0;P0_2=1; delay(200);
P0_0=0;P0_1=0;P0_2=1; delay(200);
P0_0=0;P0_1=1;P0_2=0; delay(200);
P0_0=1;P0_1=0;P0_2=0; delay(200);
}
void vienduoi_2(void)// sang led do //
{
P0_0=1;P0_1=0;P0_2=0;
}
void vienduoi_3(void)//sang led xang duong //
{
P0_1=1;P0_0=0;P0_2=0;
}
void vienduoi_4(void)// sang led xanh la cay //
{
P0_2=1;P0_0=0;P0_1=0;
}
void vienduoi(void)
{
unsigned char f,f1,f2,f3,f4;
for(f=0;f<=10;f++) vienduoi_4();
for(f1=0;f1<=10;f1++) vienduoi_3();
for(f2=0;f2<=10;f2++) vienduoi_2();
for(f3=0;f3<=10;f3++) vienduoi_1();
for(f4=0;f4<=10;f4++) vienduoi_0();
}
/* CHUONG TRINH CHINH */
void main()
{ unsigned char q1,q2,q3,q4;
P1=0xff;P0=0xff;
delay(1000);
while(1)
{
for(q1=0;q1<=2;q1++) vienngoai();
for(q2=0;q2<=2;q2++) vientrong();
for(q3=0;q3<=2;q3++) vienduoi();
for(q4=0;q4<=2;q4++) iloveyou();
}
}
Khi chạy thực tế thì chỉ có chương trinh con vienngoai() chạy thôi, các chương trinh khác ko chạy ! Bác nào cao thủ giúp em với nha
Comment