1. Trang chủ
  2. » Luận Văn - Báo Cáo

Các chương trình lập trình keil c cơ bản phục vụ cho thực tập vi xử lý

38 420 0

Đ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 38
Dung lượng 30,2 KB

Nội dung

Các chương trình lập trình Keil C cơ bản phục vụ cho thực tập vi xử lý1.. Hiệu ứng 8 Led đơn... char i;int dem; unsigned char chuc; donVi; void delayint time... void Delayint time... Nút

Trang 1

Các chương trình lập trình Keil C cơ bản phục vụ cho thực tập vi xử lý

1 Hiệu ứng 8 Led đơn

Trang 2

//============================================================void phaiTrai(unsigned char soLan){

}

//==========================================================void ngoaiVao(unsigned char soLan){

}

//==========================================================void giuaRa(unsigned char soLan){

unsigned char i;

for(i=0;i<soLan;i++){

int j;

Trang 3

for(j=0;j<4;j++){

P2=mangGiuaRa[j];

delay(10000);

} }

}

//==========================================================void sangDonQuaPhai(unsigned char soLan){

P2=mangDonQuaPhai[j];

delay(10000);

} }

}

//==========================================================void sangDanRaVao(unsigned char soLan){

unsigned char i;

for(i=0;i<soLan;i++){

int j;

for(j=0;j<8;j++){

Trang 4

P2=mangSangDanRaVao[j];

delay(10000);

} }

}

//==========================================================void sangBonLed(unsigned char soLan){

}

//==========================================================void tatBonLed(unsigned char soLan){

}

//==========================================================

Trang 5

void nhayLed(unsigned char soLan){

}

//=========================================================void nhayDuoiNguoc(unsigned char soLan){

Trang 6

//==========================================================void nhayZicZac(unsigned char soLan){

//==========================================================void nhayZicZac2(unsigned char soLan){

//==========================================================void nhayDuoiXuoi2(unsigned char soLan){

Trang 7

delay(15000);

} } }

//==========================================================void nhayDuoiNguoc2(unsigned char soLan){

Trang 9

char i;

int dem;

unsigned char chuc; donVi;

void delay(int time)

Trang 10

4 Đếm n Led 7 thanh

#include <REGX51.H>

char so[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};char maQuet[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0x7e};

char i;

unsigned char chuSo[8];

unsigned long dem, temp;

Trang 11

void Delay(int time)

Trang 13

P2=0xff;

led2=1;

P2=M[gio%10];delay(100);led2=0;

P2=0xff;

led3=1;

P2=M[phut/10];delay(100);led3=0;

P2=0xff;

led4=1;

P2=M[phut%10];delay(100);led4=0;

P2=0xff;

led5=1;

P2=M[giay/10];delay(100);led5=0;

P2=0xff;

Trang 15

down1=down;

if((down0==1)&&(down1==0)){ // neu nut down duoc bam

hour ;

if(hour==-1) hour=23; }

break;

}case 2: // chinh phut {

down0=down1;

down1=down;

if((down0==1)&&(down1==0)){ // neu nut down duoc bam

minute ;

if(minute==-1) minute=59; }

break;

}case 3: // chinh phut {

up0=up1;

Trang 16

down0=down1;

down1=down;

if((down0==1)&&(down1==0)){ // neu nut down duoc bam

second ;

if(second==-1) second=59; }

break;

}}

Trang 17

if(hour==23){

hour=0; }

}}

for(i=0;i<100;i++)hien_thi(hour,minute,second);

Trang 19

unsigned char i;

for(i=0;i<soLan;i++){

P3_7=P0_0=0; delay(10000); P3_6=P0_1=0; delay(10000); P3_5=P0_2=0; delay(10000); P3_4=P0_3=0; delay(10000); P3_3=P0_4=0; delay(10000); P3_2=P0_5=0; delay(10000); P3_1=P0_6=0; delay(10000); P3_0=P0_7=0; delay(10000); P2_7=P1_0=0; delay(10000); P2_6=P1_1=0; delay(10000); P2_5=P1_2=0; delay(10000); P2_4=P1_3=0; delay(10000); P2_3=P1_4=0; delay(10000); P2_2=P1_5=0; delay(10000); P2_1=P1_6=0; delay(10000); P2_0=P1_7=0; delay(10000);

P3_7=P0_0=1; delay(10000); P3_6=P0_1=1; delay(10000); P3_5=P0_2=1; delay(10000); P3_4=P0_3=1; delay(10000); P3_3=P0_4=1; delay(10000); P3_2=P0_5=1; delay(10000); P3_1=P0_6=1; delay(10000); P3_0=P0_7=1; delay(10000); P2_7=P1_0=1; delay(10000);

Trang 20

P2_6=P1_1=1; delay(10000); P2_5=P1_2=1; delay(10000); P2_4=P1_3=1; delay(10000); P2_3=P1_4=1; delay(10000); P2_2=P1_5=1; delay(10000); P2_1=P1_6=1; delay(10000); P2_0=P1_7=1; delay(10000);

P2_0=P1_7=0; delay(10000); P2_1=P1_6=0; delay(10000); P2_2=P1_5=0; delay(10000); P2_3=P1_4=0; delay(10000); P2_4=P1_3=0; delay(10000); P2_5=P1_2=0; delay(10000); P2_6=P1_1=0; delay(10000); P2_7=P1_0=0; delay(10000); P3_0=P0_7=0; delay(10000); P3_1=P0_6=0; delay(10000); P3_2=P0_5=0; delay(10000); P3_3=P0_4=0; delay(10000); P3_4=P0_3=0; delay(10000); P3_5=P0_2=0; delay(10000); P3_6=P0_1=0; delay(10000); P3_7=P0_0=0; delay(10000);

P2_0=P1_7=1; delay(10000); P2_1=P1_6=1; delay(10000); P2_2=P1_5=1; delay(10000);

Trang 22

P1=mangDonQuaPhai[k]; delay(10000);

}for(l=0;l<9;l++){

P2=mangDonQuaPhai[l]; delay(10000);

}for(m=0;m<9;m++){ P3=mangDonQuaPhai[m]; delay(10000);

}

for(m=8;m>=0;m ){ P3=mangDonQuaPhai[m]; delay(10000);

}

for(l=8;l>=0;l ){

P2=mangDonQuaPhai[l]; delay(10000);

}for(k=8;k>=0;k ){

Trang 23

P1=mangDonQuaPhai[k];

delay(10000);

}for(j=8;j>=0;j ){

P0=mangDonQuaPhai[j];

delay(10000);

} }

}

//============================================================void phaiTrai(unsigned char soLan){

Trang 24

}

}

}

//============================================================void giuaRa(unsigned char soLan){

P2=P0=P1=P3=mangDonQuaPhai[j];

delay(10000);

} }

Trang 25

}

//=============================================================void sangDanRaVao(unsigned char soLan){

unsigned char i;

for(i=0;i<soLan;i++){

Trang 28

//============================================================void nhayDuoiXuoi2(unsigned char soLan){

Trang 29

for(j=0;j<5;j++){

P2=P0=0x00; delay(9000); P2=P0=0xff; delay(9000); }

delay(100);

for(k=0;k<5;k++){

P1=P3=0x00; delay(9000); P1=P3=0xff; delay(9000); }

for(l=0;l<5;l++){

P2=P3=0x00; delay(9000); P2=P3=0xff; delay(9000); }

delay(100);

for(m=0;m<5;m++){

P1=P0=0x00; delay(9000); P1=P0=0xff; delay(9000); }

for(n=0;n<5;n++){

P0=P3=0x00; delay(9000); P0=P3=0xff; delay(9000); }

delay(100);

for(p=0;p<5;p++){

P1=P2=0x00; delay(9000); P1=P2=0xff; delay(9000); }

Trang 30

nhayDuoiNguoc(5);nhayDuoiXuoi(5);nhayZicZac(10);nhayDuoiXuoi2(10);nhayDuoiNguoc2(10);nhayZicZac2(10); nhayHaiCongMot(1);

nhayLed(10);

hinhTraiTim(3); }

}

9 Nút bấm 8 led đơn

Trang 33

}

}

}

//============================================================void sangDonQuaPhai(unsigned char soLan){

P2=mangDonQuaPhai[j];

delay(10000);

} }

}

//=============================================================void sangDanRaVao(unsigned char soLan){

Trang 34

}

}

//=============================================================void sangBonLed(unsigned char soLan){

unsigned char i;

for(i=0;i<soLan;i++){

Trang 37

//============================================================void nhayDuoiNguoc2(unsigned char soLan){

Trang 38

if(dem==7) sangBonLed(1);if(dem==8) tatBonLed(1);

if(dem==9) nhayDuoiNguoc(1);if(dem==10) nhayDuoiXuoi(1);if(dem==11) nhayZicZac(1);if(dem==12) nhayZicZac2(1);if(dem==13) nhayDuoiXuoi2(1);if(dem==14) nhayDuoiNguoc2(1); }

}

Ngày đăng: 06/11/2014, 15:26

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w