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
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ý

Đ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

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 #include <REGX51.H> char mangTraiPhai[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; char mangGiuaRa[]={0xe7,0xdb,0xbd,0x7e}; char mangSangDanRaVao[]={0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7}; char mangSangTatBonLed[]={0xee,0xcc,0x88,0x00,0x11,0x33,0x77,0xff}; char mangNhayDuoiXuoi[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc1,0x83,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; char mangDuoiXuoi2[]={0x11,0x22,0x44,0x88}; char mangZicZac[]={0x55,0xaa,0xcc,0x33}; char mangDonQuaPhai[]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; //============================ void delay(int time){ while(time ); } //============================================== void traiPhai(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=0;j<8;j++){ P2=mangTraiPhai[j]; delay(10000); } } } //============================================================ void phaiTrai(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=7;j>=0;j ){ P2=mangTraiPhai[j]; delay(10000); } } } //========================================================== void ngoaiVao(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=3;j>=0;j ){ P2=mangGiuaRa[j]; delay(10000); } } } //========================================================== void giuaRa(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=0;j<4;j++){ P2=mangGiuaRa[j]; delay(10000); } } } //========================================================== void sangDonQuaPhai(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=0;j<9;j++){ P2=mangDonQuaPhai[j]; delay(10000); } for(j=8;j>=0;j ){ 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++){ P2=mangSangDanRaVao[j]; delay(10000); } } } //========================================================== void sangBonLed(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=0;j<8;j++){ P2=mangSangTatBonLed[j]; delay(10000); } } } //========================================================== void tatBonLed(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=7;j>=0;j ){ P2=mangSangTatBonLed[j]; delay(10000); } } } //========================================================== void nhayLed(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ P2=0x00; delay(10000); P2=0xff; delay(10000); } } //========================================================== void nhayDuoiXuoi(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=0;j<13;j++){ P2=mangNhayDuoiXuoi[j]; delay(10000); } } } //========================================================= void nhayDuoiNguoc(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=12;j>=0;j ){ P2=mangNhayDuoiXuoi[j]; delay(10000); } } } //========================================================== void nhayZicZac(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ P2=0x55; delay(20000); P2=0xaa; delay(20000); } } //========================================================== void nhayZicZac2(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ P2=0x33; delay(20000); P2=0xcc; delay(20000); } } //========================================================== void nhayDuoiXuoi2(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=0;j<4;j++){ P2=mangDuoiXuoi2[j]; delay(15000); } } } //========================================================== void nhayDuoiNguoc2(unsigned char soLan){ unsigned char i; for(i=0;i<soLan;i++){ int j; for(j=3;j>=0;j ){ P2=mangDuoiXuoi2[j]; delay(15000); } } } //========================================================= void main(){ while(1){ nhayLed(10);delay(10000); traiPhai(3);delay(10000); phaiTrai(3);delay(10000); giuaRa(3);delay(10000); ngoaiVao(3);delay(10000); sangDanRaVao(3);delay(10000); sangDonQuaPhai(3);delay(10000); sangBonLed(3);delay(10000); tatBonLed(3);delay(10000); nhayDuoiNguoc(3);delay(10000); nhayDuoiXuoi(3);delay(10000); nhayZicZac(8);delay(10000); nhayZicZac2(6);delay(10000); nhayDuoiXuoi2(10);delay(10000); nhayDuoiNguoc2(10);delay(10000); } } 2. Nháy 1 led đơn #include <REGX51.H> void delay(int time) { while(time ); } void main(){ while(1){ P2_0=0; //bat led delay(1000); P2_0=1; //tat led delay(1000); } } 3. Đếm 00 đến 99 #include <REGX51.H> #define led1 P1_0 #define led2 P1_1 #define sang 0 #define tat 1 char so[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; char i; int dem; unsigned char chuc; donVi; void delay(int time) { while(time ); } void main(){ led1 = led2 = tat; while(1){ for (dem = 0; dem <100; dem++){ // tach chu so chuc = dem/10; donVi = dem%10; for(i=0;i<=40;i++){ // lam cham bang cach thay doi i<=10,20, cang tang cang cham lai led1 = sang; P0 = so[chuc]; delay(1000); // co the lam cham lai khi tang tre len led1 = tat; led2 = sang; P0 = so[donVi]; delay(1000); // co the lam cham lai khi tang tre len led2 = tat; } } } } 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; //=============================== void delay(int time) { while(time ); } //=============================== void tachChuSo(unsigned long temp, int soLed){ for(i=0;i<soLed;i++){ chuSo[i]=temp%10; temp=temp/10; } } //=============================== void quetLed(int soLed){ int i,j; for(i=0;i<25;i++){ // toc do nhay so for(j=0;j<soLed;j++){ P2=maQuet[j]; P0=so[chuSo[j]]; delay(1200); // toc do nhay so P2=0xff; [...]... 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 #include int dem; char mangTraiPhai[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; char mangGiuaRa[]={0xe7,0xdb,0xbd,0x7e}; char mangSangDanRaVao[]={0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7}; char mangSangTatBonLed[]={0xee,0xcc,0x88,0x00,0x11,0x33,0x77,0xff};... Led trái tim #include char hieuUngSangNguoc[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F}; char mangTraiPhai[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; char mangGiuaRa[]={0xe7,0xdb,0xbd,0x7e}; char mangSangDanRaVao[]={0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7}; char mangSangTatBonLed[]={0xee,0xcc,0x88,0x00,0x11,0x33,0x77,0xff}; char mangNhayDuoiXuoi[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc1,0x83,0x07,0x0f,0x1f,0x3f,0x7f,0xff... mangSangDanRaVao[]={0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7}; char mangSangTatBonLed[]={0xee,0xcc,0x88,0x00,0x11,0x33,0x77,0xff}; char mangNhayDuoiXuoi[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc1,0x83,0x07,0x0f,0x1f,0x3f,0x7f,0xff }; char mangDuoiXuoi2[]={0x11,0x22,0x44,0x88}; char mangZicZac[]={0x55,0xaa,0xcc,0x33}; char mangDonQuaPhai[]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; //============================================================... duoc bam minute++; if(minute>59) minute=0; } 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; up1=up; if((up0==1)&&(up1==0)){ // neu nut up duoc bam second++; if(second>59) second=0; } down0=down1; down1=down; if((down0==1)&&(down1==0)){ // neu nut down duoc bam second ; if(second==-1) second=59;... mangNhayDuoiXuoi[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc1,0x83,0x07,0x0f,0x1f,0x3f,0x7f,0xff }; char mangDuoiXuoi2[]={0x11,0x22,0x44,0x88}; char mangZicZac[]={0x55,0xaa,0xcc,0x33}; char mangDonQuaPhai[]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; //============================ void delay(int time){ while(time ); } void hinhTraiTim(unsigned char soLan){ unsigned char i; for(i=0;i . 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 #include <REGX51.H> char mangTraiPhai[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; char. dem++){ // tach chu so chuc = dem/10; donVi = dem%10; for(i=0;i<=40;i++){ // lam cham bang cach thay doi i<=10,20, cang tang cang cham lai led1 = sang; P0 = so[chuc]; delay(1000); // co the. mangNhayDuoiXuoi[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc1,0x83,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; char mangDuoiXuoi2[]={0x11,0x22,0x44,0x88}; char mangZicZac[]={0x55,0xaa,0xcc,0x33}; char mangDonQuaPhai[]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; //============================ void

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