Thông báo

Collapse
No announcement yet.

Ai sua giup mih code mach giao thong dung 8051 nay voi.

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Ai sua giup mih code mach giao thong dung 8051 nay voi.

    code nay chay dung tin hieu den giao thong nhung led hien thi bi loi.may ban coi giup minh xem loi o dau nha

    Click image for larger version

Name:	hinh1.png
Views:	1
Size:	66.4 KB
ID:	1410430Click image for larger version

Name:	hinh1.png
Views:	1
Size:	66.4 KB
ID:	1410430Code:
    #include<AT89X51.h>
    unsigned char thoi_gian0,thoi_gian1,thoi_gian2,thoi_gian3;
    unsigned int over=0;
    unsigned char ma[10]={192,249,164,176,153,146,130,248,128,144};

    void delay(unsigned char time)
    {
    unsigned char x,y;
    for(x=0;x<time;x++)
    {
    for(y=0;y<13;y++);

    }
    }
    void time0() interrupt 1
    { //cu 200 us thi tran 1 lan
    over++;
    if(over==4950) //gia tri tinh toan la 5000, tinh chinh lai 4950
    {
    over=0;
    thoi_gian0--;
    thoi_gian1--;
    thoi_gian2--;
    thoi_gian3--;
    }
    }

    void h_thi0()
    {
    unsigned char k,chuc,donvi;
    for(k=0;k<2;k++)
    {
    donvi=thoi_gian0 ;
    chuc=thoi_gian0/10;
    }
    P2=ma[donvi];
    P0=0xfe;
    delay(1);
    P0=0xff;
    delay(1);
    P0=0xfb;
    delay(1);
    P0=0xff;
    delay(1);
    P2=ma[chuc];
    P0=0xfd;
    delay(1);
    P0=0xff;
    delay(1);
    P0=0xf7;
    delay(1);
    P0=0xff;
    delay(1);
    }


    void h_thi1()
    {
    unsigned char k,chuc,donvi;
    for(k=0;k<2;k++)
    {
    donvi=thoi_gian1 ;
    chuc=thoi_gian1/10;
    }
    P2=ma[donvi];
    P0_4=0;
    delay(1);
    P0_4=1;
    delay(1);
    P0_6=0;
    delay(1);
    P0_6=1;
    delay(1);
    P2=ma[chuc];
    P0_5=0;
    delay(1);
    P0_5=1;
    delay(1);
    P0_7=0;
    delay(1);
    P0_7=1;
    delay(1);
    }

    void h_thi2()
    {
    unsigned char k,chuc,donvi;
    for(k=0;k<2;k++)
    {
    donvi=thoi_gian2 ;
    chuc=thoi_gian2/10;
    }
    P2=ma[donvi];
    P0_4=0;
    delay(1);
    P0_4=1;
    delay(1);
    P0_6=0;
    delay(1);
    P0_6=1;
    delay(1);
    P2=ma[chuc];
    P0_5=0;
    delay(1);
    P0_5=1;
    delay(1);
    P0_7=0;
    delay(1);
    P0_7=1;
    delay(1);
    }


    void h_thi3()
    {
    unsigned char k,chuc,donvi;
    for(k=0;k<2;k++)
    {
    donvi=thoi_gian3 ;
    chuc=thoi_gian3/10;
    }
    P2=ma[donvi];
    P0_0=0;
    delay(1);
    P0_0=1;
    delay(1);
    P0_2=0;
    delay(1);
    P0_2=1;
    delay(1);
    P2=ma[chuc];
    P0_1=0;
    delay(1);
    P0_1=1;
    delay(1);
    P0_3=0;
    delay(1);
    P0_3=1;
    delay(1);
    }
    void main()
    {
    P0=255;
    P2=255;
    TMOD=2; //timer0 o che do 2 tu nap lai
    TH0=54; //gia tri nap lai
    TR0=1; //cho phep timer0 chay
    ET0=1; //cho phep ngat timer0
    EA=1;
    while(1)
    {
    thoi_gian0=20;
    thoi_gian1=24;

    do
    {
    P1=0x21;
    h_thi0();
    h_thi1();
    }
    while(thoi_gian0!=0);

    thoi_gian0=5;
    thoi_gian1=5;
    do
    {
    P1=0x22;
    h_thi0();
    h_thi1();
    }
    while(thoi_gian0!=0);

    thoi_gian2=20;
    thoi_gian3=24;

    do
    {

    P1=0x0c;

    h_thi2();
    h_thi3();
    }
    while(thoi_gian2!=0);


    thoi_gian2=5;
    thoi_gian3=5;
    do
    {
    P1=0x14;
    h_thi2();
    h_thi3();
    }
    while(thoi_gian2!=0);
    }
    }

Về tác giả

Collapse

chuotcon Tìm hiểu thêm về chuotcon

Bài viết mới nhất

Collapse

Đang tải...
X