• Tin mới

    [PIC TUTORIAL] BÀI 11 Chương trình nhấn RA4 thì 2 led trái và 2 led phải thay nhau sáng

    SƠ ĐỒ MẠCH ĐIỆN




    CHƯƠNG TRÌNH MẪU
    #include "16f887.h"
    #include "def_16f887.h"
    #fuses  NOWDT,NOPROTECT,PUT,NOLVP,XT 
    #use    delay(clock = 4000000)         //Tan so thach anh 4MHz
    #define SW RA4
    
    void main()
    {
    
        setup_adc_ports(NO_ANALOGS|VSS_VDD);
        setup_adc(ADC_OFF);
        setup_spi(SPI_SS_DISABLED);
        setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
        setup_timer_1(T1_DISABLED);
        setup_timer_2(T2_DISABLED,0,1);
        setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
        set_tris_a(0xff);       //PORTA nhap du lieu;
        set_tris_c(0x00);       //PORTC xuat du lieu.
        PORTC = 0x03;           //2 led trai sang.    
        while(1)    
        {
            if(!RA4)          //Cho nhan phim.
            {
                delay_ms(20); //Chong doi phim.
                while(!RA4);  //Cho nha phim.
                RC0 = !RC0;
                RC1 = RC0;
                RC6 = !RC0;
                RC7 = RC6;
            }
        }
    }
    



    DOWNLOAD FILE MÔ PHỎNG + CODE
    (Bấm vào link đợi 5s, sau đó bấm "Skip Ad" sẽ ra link download) 




    No comments