1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

tổng hợp các dạng bài tập lập trình c

11 420 5

Đ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 11
Dung lượng 142,62 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Trang 1

Lập Trình C

Led Đơn

Bài 1:

 Lập trình:

#include <bai1.h>

#include <def_877a.h>

void main()

{

trisb = 0x00; trisd = 0xff; portb=0xff;

int sang[9]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; int tat[9]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; int a,b;

while(TRUE)

{

if(rd1==0)

{

loop1:

Trang 2

a=0;

while(a<5)

{

for(b=0;b<9;b++)

{

portb=sang[b]; delay_ms(10); if(rd0==0) goto loop2;

}

a++;

}

}

if(rd0==0)

{

loop2:

a=0;

while(a<10)

{

for(b=0;b<9;b++)

{

portb=tat[b]; delay_ms(10); if(rd1==0) goto loop1;

}

a++;

}

}

}

}

Bài 9:

 Lập Trình:

#include <bai9.h>

#include <def_877a.h>

void main()

{

trisb = 0x00; trisd = 0xff; portb=0xff;

int trongra[9]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; int ngoaivao[9]={0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; int a,b;

while(TRUE)

{

if(rd0==0)

{

loop1:

a=0;

while(a<10)

Trang 3

{

for(b=0;b<9;b++)

{

portb=trongra[b]; delay_ms(10); if(rd1==0) goto loop2; }

a++;

}

}

if(rd1==0)

{

loop2:

a=0;

while(a<5)

{

for(b=0;b<9;b++)

{

portb=ngoaivao[b]; delay_ms(10); if(rd0==0) goto loop1; }

a++;

}

}

}

}

Trang 4

Led 7 thanh

Bài 3:

 Lập trình:

#include <bai3.h>

#include <def_877a.h>

void main()

{

trisb = 0x00; trisd = 0xff; trisc=0x00; portb=0x00;

int8 bm[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; int a=0;

while(TRUE)

{

if(rd0==0) if(a<9){ a++; delay_ms(5);}

if(rd1==0) if(a>0){ a ; delay_ms(5);}

portc=0x00; portb=bm[a]; portc=0x08; delay_ms(5);

}

}

Trang 5

Bài 5:

 Lập trình:

#include <bai5.h>

#include <def_877a.h>

void main()

{

trisb = 0x00; trisd = 0xff; trisc=0x00; portb=0x00;

int8 bm[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; int a=0,b=0,i;

while(TRUE)

{

loop:

portc=0x00;

if(rd0==0)

{

for(b=0;b<10;b++)

{

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

{

i=0;

while(i<100)

{

Trang 6

if(rd0==1) goto loop;

portc=0x00; portb=bm[a]; portc=0x08; delay_ms(5);

portc=0x00; portb=bm[b]; portc=0x04; delay_ms(5);

i++;

}

}

}

}

}

}

Bài 7:

 Lập trình:

#include <bai7.h>

#include <def_877a.h>

void main()

{

trisb = 0x00; trisd = 0xff; trisc=0x00; portb=0x00;

int8 bm[11] =

{0x3f,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; int a=0,b=0,i;

while(TRUE)

{

loop:

portc=0x00;

if(rd0==0)

{

for(b=10;b>0;b )

{

for(a=10;a>0;a )

{

i=0;

while(i<100)

{

if(rd0==1) goto loop;

portc=0x00; portb=bm[a]; portc=0x08; delay_ms(5);

portc=0x00; portb=bm[b]; portc=0x04; delay_ms(5);

i++;

}

}

}

}

}

Trang 7

Bài 10:

 Lập trình:

#include <bai10.h>

#include <def_877a.h>

void main()

{

trisb = 0x00; trisd = 0xff; trisc=0x00; portb=0x00; while(TRUE)

{

if(rd0==0)

{

while(true)

{

portc=0x00; portb=0x7f; portc=0x08; delay_ms(5); portc=0x00; portb=0x06; portc=0x04; delay_ms(5); portc=0x00; portb=0x3f; portc=0x02; delay_ms(5); portc=0x00; portb=0x5b; portc=0x01; delay_ms(5); }

}

}

}

Trang 8

Ma Trận Phím 3x3

Bài 2:

 Lập trình:

#include <bai2.h>

#include <def_877a.h>

void main()

{

trisb = 0x07; trisc=0x00; portc=0x00;

int8 bm[9] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f}; while(TRUE)

{

portb=0xf7;

if(rb0==0) portc=bm[0];

if(rb1==0) portc=bm[1];

if(rb2==0) portc=bm[2];

portb=0xef;

if(rb0==0) portc=bm[3];

if(rb1==0) portc=bm[4];

if(rb2==0) portc=bm[5];

portb=0xdf;

if(rb0==0) portc=bm[6];

if(rb1==0) portc=bm[7];

Trang 9

if(rb2==0) portc=bm[8];

}

}

Bài 4:

 Lập trình

#include <bai4.h>

#include <def_877a.h>

void main()

{

trisb = 0x07; trisc=0x00; portc=0x00;

int8 bm[9] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f}; while(TRUE)

{

portb=0xf7;

if(rb0==0) portc=bm[0];

if(rb1==0) portc=bm[3];

if(rb2==0) portc=bm[6];

portb=0xef;

if(rb0==0) portc=bm[1];

if(rb1==0) portc=bm[4];

if(rb2==0) portc=bm[7];

portb=0xdf;

if(rb0==0) portc=bm[2];

if(rb1==0) portc=bm[5];

if(rb2==0) portc=bm[8];

}

}

Động Cơ Bước

Trang 10

Bài 6:

 Lập trình:

#include <bai6.h>

#include <def_877a.h>

void main()

{

trisb=0xff; trisd=0x00;

int mastep[8]={0x09,0x08,0x0c,0x09,0x06,0x02,0x03,0x01}; int a,b,c;

while(TRUE)

{

loop:

if(rb0==0)

{

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

{

for(b=0;a<50;b++)

{

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

{

portd=mastep[c]; delay_ms(30);

if(rb1==0) goto loop;

}

}

Trang 11

}

}

}

}

Bài 8:

 Lập trình:

#include <bai8.h>

#include <def_877a.h>

void main()

{

trisb=0xff; trisd=0x00;

int mastep[9]={0x09,0x09,0x08,0x0c,0x09,0x06,0x02,0x03,0x01}; int a;

while(TRUE)

{

if(rb0==0)

{

loop1:

for(a=8;a>0;a )

{

portd=mastep[a]; delay_ms(30);

if(rb1==0) goto loop2;

}

}

if(rb1==0)

{

loop2:

for(a=1;a<9;a++)

{

portd=mastep[a]; delay_ms(30);

if(rb0==0) goto loop1;

}

}

}

}

Ngày đăng: 10/09/2019, 22:57

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w