1. Trang chủ
  2. » Giáo án - Bài giảng

Mình dùng cái này đế lập trình led trái tim đấy

13 877 17

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 13
Dung lượng 20,14 KB

Nội dung

Mình dùng cái này đế lập trình led trái tim đấy .Mình thấy lập trình cho mấy cái chữ với đường viền thì quá đơn giản .Dùng vòng for kết hợp với mảng là xong .Đọc đoạn code này mình viết xem có hiểu k? Nếu hiểu là làm dc.

Trang 1

Mình dùng cái này đế lập trình led trái tim đấy Mình thấy lập trình cho mấy cái chữ với đường viền thì quá đơn giản Dùng vòng for kết hợp với mảng là

xong Đọc đoạn code này mình viết xem có hiểu k? Nếu hiểu là làm dc

//############################################

#include<reg52.h>

#include<stdio.h>

#include<intrins.h>

unsigned int i,j,k;

//###### ham delay tao thoi gian tre 0.5s ######

void delay(unsigned int ms)

{

unsigned int a;

unsigned char b;

for(a=0;a<ms;a++)

{

for(b=0;b<125;b++) {}

}

}

//##### hieu ung chop tat toan bo led ########

void hieu_ung_1(void)

{

for(k=0;k<8;k++)

{

P0=P1=P2=P3=0xff;

delay(300);

P0=P1=P2=P3=0x00;

delay(300);

}

}

//##### hieu ung chop 2 nua trai tim #########

void hieu_ung_2(void)

{

for(i=0;i<6;i++)

{

P0=P3=0x00;

delay(300);

P0=P3=0xff;

P1=P2=0x00;

delay(300);

P1=P2=0xff;

Trang 2

}

//##### hieu ung led nhay so le 1 ############## void hieu_ung_3(void)

{

for(i=0;i<8;i++)

{

P0=P1=P2=P3=0x55;

delay(300);

P0=P1=P2=P3=0xaa;

delay(300);

}

}

//##### hieu ung led nhay so le 2 ############## void hieu_ung_4(void)

{

for(i=0;i<8;i++)

{

P0=P1=P2=P3=0xaa;

delay(300);

P0=P1=P2=P3=0x55;

delay(300);

}

}

//##### p0,p1,p2,p3,p4 cung sang thuan ###### void hieu_ung_5(void)

{

unsigned char x,y;

x=y=255;

i=1;

j=128;

for(k=0;k<8;k++)

{

x=x-i;

y=y-j;

P0=x;

P1=P2=P3=y;

i=i*2;

j=j/2;

delay(300);

Trang 3

}

//##### p0,p1,p2,p3,p4 cung sang nghich ###### void hieu_ung_6(void)

{

unsigned char x,y;

x=y=255;

i=1;

j=128;

for(k=0;k<8;k++)

{

x=x-i;

y=y-j;

P0=y;

P1=P2=P3=x;

i=i*2;

j=j/2;

delay(300);

}

}

//##### sang dan het cac led theo chieu thuan ## void hieu_ung_7(void)

{

unsigned char M[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0, 0x80,0x00};

unsigned char N[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03, 0x01,0x00};

P0=P1=P2=P3=0xff;

for(i=0;i<8;i++)

{

P0=M[i];

delay(300);

}

for(i=0;i<8;i++)

{

P2=N[i];

delay(300);

}for(i=0;i<8;i++)

{

P3=N[i];

Trang 4

}for(i=0;i<8;i++)

{

P1=N[i];

delay(300);

}

}

//##### tat dan het cac led theo chieu thuan ############

void hieu_ung_8(void)

{

unsigned char M[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; unsigned char N[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; P0=P1=P2=P3=0x00;

for(i=0;i<8;i++)

{

P0=M[i];

delay(300);

}

for(i=0;i<8;i++)

{

P2=N[i];

delay(300);

}for(i=0;i<8;i++)

{

P3=N[i];

delay(300);

}for(i=0;i<8;i++)

{

P1=N[i];

delay(300);

}

}

//##### sang dan het cac led theo chieu nghich #####

void hieu_ung_9(void)

{

unsigned char M[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; unsigned char N[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; P0=P1=P2=P3=0xff;

for(i=0;i<8;i++)

{

Trang 5

delay(300);

}

for(i=0;i<8;i++)

{

P3=M[i];

delay(300);

}for(i=0;i<8;i++)

{

P2=M[i];

delay(300);

}for(i=0;i<8;i++)

{

P0=N[i];

delay(300);

}

}

//##### tat dan het cac led theo chieu nghich #####

void hieu_ung_10(void)

{

unsigned char M[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; unsigned char N[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; P0=P1=P2=P3=0x00;

for(i=0;i<8;i++)

{

P1=M[i];

delay(300);

}

for(i=0;i<8;i++)

{

P3=M[i];

delay(300);

}for(i=0;i<8;i++)

{

P2=M[i];

delay(300);

}for(i=0;i<8;i++)

{

P0=N[i];

delay(300);

Trang 6

}

//##### hieu ung pro 1 #################

void hieu_ung_11(void)

{

unsigned char M[]={0xf0,0xe1,0xc3,0x87,0x0f};

unsigned char N[]={0x0f,0x4f,0x63,0x71,0x78};

unsigned char L[]={0x1f,0x4f,0x6f,0x73,0x79,0x7c}; unsigned char K[]={0x3f,0x5f,0x6f,0x77,0x7b,0x7d,0x7e}; P0=P1=P2=P3=0xff;

for(i=0;i<5;i++)

{

P0=M[i];

delay(300);

}

P0=0xff;

for(i=0;i<5;i++)

{

P2=N[i];

delay(300);

}

P2=0x7f;

for(i=0;i<6;i++)

{

P3=L[i];

delay(300);

}

P2=P3=0x7f;

for(i=0;i<7;i++)

{

P1=K[i];

delay(300);

}

P1=P2=P3=0x7f;

}

Trang 7

//#include<stdio.h>

//#include<intrins.h>

unsigned int i,j,k;

//###### ham delay tao thoi gian tre 0.5s ###### void delay(unsigned int ms)

{

unsigned int a;

unsigned char b;

for(a=0;a<ms;a++)

{

for(b=0;b<125;b++) {}

}

}

//##### hieu ung chop tat toan bo led ######## void hieu_ung_1(void)

{

for(k=0;k<8;k++)

{

P0=P1=P2=P3=0xff;

delay(1000);

P0=P1=P2=P3=0x00;

delay(1000);

}

}

//##### hieu ung chop 2 nua trai tim ######### * void hieu_ung_2(void)

{

for(i=0;i<6;i++)

{

P0=P3=0x00;

delay(1000);

P0=P3=0xff;

P1=P2=0x00;

delay(1000);

P1=P2=0xff;

}

}

//##### hieu ung led nhay so le 1 ############## void hieu_ung_3(void)

Trang 8

for(i=0;i<8;i++)

{

P0=P1=P2=P3=0x55;

delay(1000);

P0=P1=P2=P3=0xaa;

delay(1000);

}

}

//##### hieu ung led nhay so le 2 ############## void hieu_ung_4(void)

{

for(i=0;i<8;i++)

{

P0=P1=P2=P3=0xaa;

delay(1000);

P0=P1=P2=P3=0x55;

delay(1000);

}

}

//##### p0,p1,p2,p3,p4 cung sang thuan ###### void hieu_ung_5(void)

{

unsigned char x,y;

x=y=255;

i=1;

j=128;

for(k=0;k<8;k++)

{

x=x-i;

y=y-j;

P0=x;

P1=P2=P3=y;

i=i*2;

j=j/2;

delay(1000);

}

}

//##### p0,p1,p2,p3,p4 cung sang nghich ###### void hieu_ung_6(void)

Trang 9

unsigned char x,y;

x=y=255;

i=1;

j=128;

for(k=0;k<8;k++)

{

x=x-i;

y=y-j;

P0=y;

P1=P2=P3=x;

i=i*2;

j=j/2;

delay(1000);

}

}

//##### sang dan het cac led theo chieu thuan ## void hieu_ung_7(void)

{

unsigned char M[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0, 0x80,0x00};

unsigned char N[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03, 0x01,0x00};

P0=P1=P2=P3=0xff;

for(i=0;i<8;i++)

{

P0=M[i];

delay(1000);

}

for(i=0;i<8;i++)

{

P2=N[i];

delay(1000);

}for(i=0;i<8;i++)

{

P3=N[i];

delay(1000);

}for(i=0

;i<8;i++)

{

Trang 10

delay(1000);

}

}

//##### tat dan het cac led theo chieu thuan ############

void hieu_ung_8(void)

{

unsigned char M[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; unsigned char N[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; P0=P1=P2=P3=0x00;

for(i=0;i<8;i++)

{

P0=M[i];

delay(1000);

}

for(i=0;i<8;i++)

{

P2=N[i];

delay(1000);

}for(i=0;i<8;i++)

{

P3=N[i];

delay(1000);

}for(i=0;i<8;i++)

{

P1=N[i];

delay(1000);

}

}

//##### sang dan het cac led theo chieu nghich #####

void hieu_ung_9(void)

{

unsigned char M[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; unsigned char N[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; P0=P1=P2=P3=0xff;

for(i=0;i<8;i++)

{

P1=M[i];

delay(1000);

}

Trang 11

{

P3=M[i];

delay(1000);

}for(i=0;i<8;i++)

{

P2=M[i];

delay(1000);

}for(i=0;i<8;i++)

{

P0=N[i];

delay(1000);

}

}

//##### tat dan het cac led theo chieu nghich #####

void hieu_ung_10(void)

{

unsigned char M[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; unsigned char N[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; P0=P1=P2=P3=0x00;

for(i=0;i<8;i++)

{

P1=M[i];

delay(1000);

}

for(i=0;i<8;i++)

{

P3=M[i];

delay(1000);

}for(i=0;i<8;i++)

{

P2=M[i];

delay(1000);

}for(i=0;i<8;i++)

{

P0=N[i];

delay(1000);

}

}

//##### hieu ung pro 1 #################

Trang 12

void hieu_ung_11(void)

{

unsigned char M[]={0xf0,0xe1,0xc3,0x87,0x0f};

unsigned char N[]={0x0f,0x4f,0x63,0x71,0x78};

unsigned char L[]={0x1f,0x4f,0x6f,0x73,0x79,0x7c}; unsigned char K[]={0x3f,0x5f,0x6f,0x77,0x7b,0x7d,0x7e}; P0=P1=P2=P3=0xff;

for(i=0;i<5;i++)

{

P0=M[i];

delay(1000);

}

P0=0xff;

for(i=0;i<5;i++)

{

P2=N[i];

delay(1000);

}

P2=0x7f;

for(i=0;i<6;i++)

{

P3=L[i];

delay(1000);

}

P2=P3=0x7f;

for(i=0;i<7;i++)

{

P1=K[i];

delay(1000);

}

P1=P2=P3=0x7f;

}

void main(void)

{

while(1)

{

hieu_ung_1() ;

hieu_ung_2() ;

hieu_ung_3() ;

hieu_ung_4() ;

Trang 13

hieu_ung_5() ; hieu_ung_6() ; hieu_ung_7() ; hieu_ung_8() ; hieu_ung_9 (); hieu_ung_10(); hieu_ung_11(); }

}

Ngày đăng: 19/06/2014, 20:04

TỪ KHÓA LIÊN QUAN

w