Code:
#include <AT89C51.H> #define solanquetphim 100 void phim_duoc_an(unsigned char phim) { switch(phim)// Tuy vao so lan { case 0: { so0(); break; }// Neu so lan =0 hien so 0 thoat khoi switch case 1: { so1(); break; }// Neu so lan =1 hien so 1 thoat khoi switch case 2: { so2(); break; }// .... case 3: { so3(); break; } case 4: { so4(); break; } case 5: { so5(); break; } case 6: { so6(); break; } case 7: { so7(); break; } case 8: { so8(); break; } case 9: { so9(); break; }// Neu so lan =9 hien so 9 thoat khoi switch unsigned char quetbanphim(void) { unsigned char giatribanphim;// Bien de luu gia tri phim an tu 0 den 15 ma hoa 16 phim unsigned char x,y; //Quet 4 hang phim for(x=0; x<4;x++) { P3=quetphim[x];// Dua lan luot cac hang xuong 0 for(y=0;y<solanquetphim;y++)// Kiem tra solanquetphim lan { if(P3_4==0) giatribanphim=0+4*x;// Gia tri phim tuong ung if(P3_5==0) giatribanphim=1+4*x;// Tuy thuoc vao hang x if(P3_6==0) giatribanphim=2+4*x;// La may ma gia tri cua if(P3_7==0) giatribanphim=3+4*x;// gia tri ban phim tuong ung. } } return(giatribanphim); } Hàm Main. void main(void) { unsigned char i; while(1) { i=quetbanphim(); phim_duoc_an(i); } }
tks cả nhà
Comment