|
Tài trợ cho PIC Vietnam |
Đóng góp ý kiến Nơi tiếp nhận những ý kiến đóng góp của thành viên |
|
Ðiều Chỉnh | Xếp Bài |
08-12-2015, 09:38 PM | #14 |
Nhập môn đệ tử
Tham gia ngày: Jun 2009
Bài gửi: 1
: |
Huong Dan code pic 16f877a
Mình là dân tay ngang nhưng đam mê điện tử, mình mới tìm hiểu lập trình pic một thời gian, nhưng chưa đủ trình độ để hiểu chương trình này, xin mọi người giúp đỡ giải thích những dòng lệnh dưới đây, hoặc trong file đính kèm.Xin cám ơn rất nhiều. Mình có một ý tưởng để giúp đỡ ba mẹ đỡ nhọc nhằn, chỉ cần hiểu được code này mình tin sẽ lam được!
#include <16F877A.h> #include <def_877a.h> #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT #use delay(clock=20000000) int1 gt1, gt2, gt3, gt4; char num=0,val=0; char read_BCD() { if(input(PIN_A0))val |= 0x01; if(input(PIN_A1))val |= 0x02; if(input(PIN_A2))val |= 0x04; if(input(PIN_A3))val |= 0x08; return(val); } void kiemtra1() { gt1 = INPUT(pin_c0); if(gt1==1) { output_high(pin_d0); delay_ms(200); output_low(pin_d0); delay_ms(50); output_high(pin_d0); delay_ms(100); output_low(pin_d0);} if(gt1==0) { output_high(pin_d0); delay_ms(200); output_low(pin_d0); delay_ms(50);} } void kiemtra2() { gt2 = INPUT(pin_c1); if(gt2==1) { output_high(pin_d0); delay_ms(100); output_low(pin_d0); delay_ms(50); output_high(pin_d0); delay_ms(100); output_low(pin_d0); } if(gt2==0) { output_high(pin_d0) ;delay_ms(100); output_low(pin_d0); delay_ms(50); } } void kiemtra3() { gt3 = INPUT(pin_c2); if(gt3==1) { output_high(pin_d0); delay_ms(100); output_low(pin_d0); delay_ms(50); output_high(pin_d0); delay_ms(100); output_low(pin_d0);} if(gt3==0) { output_high(pin_d0); delay_ms(100); output_low(pin_d0); delay_ms(50); } } void kiemtra4() { gt4 = INPUT(pin_c3); if(gt4==1) { output_high(pin_d0); delay_ms(100); output_low(pin_d0); delay_ms(50); output_high(pin_d0); delay_ms(100); output_low(pin_d0); } if(gt4==0) { output_high(pin_d0); delay_ms(100); output_low(pin_d0); delay_ms(50);} } void main() { int1 m=1; set_tris_a(0xFF); set_tris_c(0xff); set_tris_d(0x00); set_tris_b(0b00000001); output_b(0x00); output_d(0x00); while(true) { if((input(PIN_B0))&&(m==1)) { num=read_BCD(); val=0;m=0; } if((input(PIN_B0))==0)m=1; switch(num) { case 0:break; case 1: { output_toggle(PIN_B1); num=0; break; } case 2: { output_toggle(PIN_B2); num=0; break; } case 3: { output_toggle(PIN_B3); num=0; break; } case 4: { output_toggle(PIN_B4); num=0; break; } case 5: { kiemtra1(); num=0; break; } case 6: { kiemtra2(); num=0; break; } case 7: { kiemtra3(); num=0; break; } case 8: { kiemtra4(); num=0; break; } }}} |
|
|