|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
|
Ðiều Chỉnh | Xếp Bài |
31-10-2012, 12:10 PM | #1 |
Nhập môn đệ tử
Tham gia ngày: Oct 2012
Bài gửi: 2
: |
mong mọi người giúp đỡ e với
#include <16F877A.H>
#define STOP PIN_B4 #define DKTH PIN_B5 #define DKNG PIN_B6 #define TANGTOC PIN_B7 #fuses NOWDT,XT #use delay(clock=20000000) #use fast_io(a) #use fast_io(b) #Use fast_io(d) int BCHUC,BDVI,VDVI,VCHUC; /// DUNG CHO TACH SO QUAY THUAN /// int BCHUC1,BDVI1,VDVI1,VCHUC1; /// DUNG CHO TACH SO QUAY NGHICH /// int BCHUC2,BDVI2,VDVI2,VCHUC2; /// DUNG CHO TACH SO STOP /// int SBUOC=0,A,SVONG=0; int SBUOC1=0,SVONG1=0; int SBUOC2=0,SVONG2=0; int R_KEY=0,i,j; char DIG[10]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X9 0}; char S[10]={0XC0,0XC0,0XC0,0XC0,0XC0,0XC0,0XC0,0XC0,0XC0,0XC 0}; char ROTATE[8]={14,12,13,9,11,3,7,6}; ///////////// CHUONG TRINH NGAT /////////////////////// #INT_RB void NGAT_RB() { clear_interrupt(int_rb); if(input(STOP)==0) A=0; if(input(DKTH)==0) A=1; if(input(DKNG)==0) A=2; if(input(TANGTOC)==0) A=3; } //////////// TACH SO DUNG CHO THUAN ////////////////// void HEX_BCD_THUAN() { VCHUC=SVONG/10; VDVI=SVONG; BCHUC=SBUOC/10; BDVI=SBUOC; } ////////////// TACH SO DUNG CHO STOP ///////////////// void HEX_BCD_STOP() { VCHUC2=SVONG2/10; VDVI2=SVONG2; BCHUC2=SBUOC2/10; BDVI2=SBUOC2; } ////////////// TACH SO DUNG CHO NGHICH ////////////// void HEX_BCD_NGHICH() { VCHUC1=SVONG1/10; VDVI1=SVONG1; BCHUC1=SBUOC1/10; BDVI1=SBUOC1; } //////// HIEN THI SO CHO NGHICH _DUNG CHO HIEN THI4 ////////// void HIENTHI3() { for(j=0;j<5;j ) { output_c(DIG[BDVI1]); //HIEN THI SO BUOC DON VI output_d(0b11111110); delay_ms(10); output_d(255); output_c(DIG[BCHUC1]); //HIEN THI SO BUOC CHUC output_d(0b11111101); delay_ms(10); output_d(255); output_c(0XBF); //HIEN THI DAU GACH PHAN CACH output_d(0b11111011); delay_ms(10); output_d(255); output_c(DIG[VDVI1]); //HIEN THI SO VONG DON VI output_d(0b11110111); delay_ms(10); output_d(255); output_c(DIG[VCHUC1]); //HIEN THI SO VONG CHUC output_d(0b11101111); delay_ms(10); output_d(255); } } /////////// HIEN THI DEM CHO NGHICH //////////////// void HIENTHI4() { i=0; SBUOC1 ; if(SBUOC1>95) { SBUOC1=0; SVONG1 ; if(SVONG1>99) { SVONG1=0; } } HEX_BCD_NGHICH(); while(i<10) { HIENTHI3(); i ; } } ///////////// HIEN THI SO CHO STOP //////////////// void HIENTHI2() { for(j=0;j<5;j ) { output_c(S[BDVI2]); //HIEN THI SO BUOC DON VI output_d(0b11111110); delay_ms(10); output_d(255); output_c(S[BCHUC2]); //HIEN THI SO BUOC CHUC output_d(0b11111101); delay_ms(10); output_d(255); output_c(0XBF); //HIEN THI DAU GACH PHAN CACH output_d(0b11111011); delay_ms(10); output_d(255); output_c(S[VDVI2]); //HIEN THI SO VONG DON VI output_d(0b11110111); delay_ms(10); output_d(255); output_c(S[VCHUC2]); //HIEN THI SO VONG CHUC output_d(0b11101111); delay_ms(10); output_d(255); } } //////////// HIEN THI SO CHO THUAN _DUNG CHO HIEN THI ////////////// void HIENTHI1() { for(j=0;j<5;j ) { output_c(DIG[BDVI]); //HIEN THI SO BUOC DON VI output_d(0b11111110); delay_ms(10); output_d(255); output_c(DIG[BCHUC]); //HIEN THI SO BUOC CHUC output_d(0b11111101); delay_ms(10); output_d(255); output_c(0XBF); //HIEN THI DAU GACH PHAN CACH output_d(0b11111011); delay_ms(10); output_d(255); output_c(DIG[VDVI]); //HIEN THI SO VONG DON VI output_d(0b11110111); delay_ms(10); output_d(255); output_c(DIG[VCHUC]); //HIEN THI SO VONG CHUC output_d(0b11101111); delay_ms(10); output_d(255); } } /////////////// HIEN THI DEM CHO NGHICH //////////////////// void HIENTHI() { i=0; SBUOC ; if(SBUOC>95) { SBUOC=0; SVONG ; if(SVONG>99) { SVONG=0; } } HEX_BCD_THUAN(); while(i<10) { HIENTHI1(); i ; } } ///////////////////////////////////////////////////////////////////// void QUAYTHUAN() { output_a(ROTATE[R_KEY]); HIENTHI(); if(R_KEY < 7) { R_KEY ; } else R_KEY=0; } ////////////////////////////////////////////////////////////////////// void QUAYNGICH() { if(R_KEY > 0) { R_KEY--; } else R_KEY=7; output_a(ROTATE[R_KEY]); HIENTHI4(); } ///////////////////////////////////////////////////////////////////////// void STP() { output_a(0XFF); HEX_BCD_STOP(); HIENTHI2(); } ////////////////////////////////////////////////////////////////////////// void TANGTOCDO() { } ////////////////////////////////////////////////////////////////////////// void main () { set_tris_a(0); // PORTA DIEU KHIEN DONG CO BUOC set_tris_b(0XFF); // PORTB LA PORT NHAP DU LIEU set_tris_c(0); // PORTC XUAT MA HIEN THI set_tris_d(0); // PORTD QUET LED ENABLE_INTERRUPTS(GLOBAL); //CHO PHEP NGAT TOAN CUC ENABLE_INTERRUPTS(INT_RB); //CHO PHEP NGAT RB EXT_INT_EDGE(H_TO_L); //CHO PHEP NGAT CANH XUONG A=0; while(true) { switch(A) { case 0 : {STP(); //NEU A=0 THI STOP SBUOC=0; /// XOA SO BUOC THUAN VE 0 //// SVONG=0; /// XOA SO VONG THUAN VE 0 //// SBUOC1=0; /// XOA SO BUOC NGHICH VE 0 /// SVONG1=0; /// XOA SO VONG NGHICH VE 0 /// } break; case 1 : /// // NEU A=1 THI QUAY THUAN /// { SBUOC1=0; /// XOA SO BUOC NGHICH VE 0 /// SVONG1=0; /// XOA SO VONG NGHICH VE 0 /// QUAYTHUAN(); } break; case 2 : /// NEU A=2 THI QUAY NGHICH /// { SBUOC=0; /// XOA SO BUOC THUAN VE 0 //// SVONG=0; /// XOA SO VONG THUAN VE 0 //// QUAYNGICH(); } break; case 3: { SBUOC=0; /// XOA SO BUOC THUAN VE 0 //// SVONG=0; /// XOA SO VONG THUAN VE 0 //// SBUOC1=0; /// XOA SO BUOC NGHICH VE 0 /// SVONG1=0; /// XOA SO VONG NGHICH VE 0 /// TANGTOCDO(); } } } } //////////////// TONG THOI GIAN QUET DAY LED LA 10x5/////// //////////////// VOI 10 LA VONG while(i<10) /////////////// ///////////////// VA 5 LA VONG LAP for(j=0;j<5;j )//////// khi e compile thì nó báo lỗi là too many nested #include xin moi ng giúp e |
|
|