+ Trả Lời Ðề Tài
kết quả từ 1 tới 4 trên 4

Đề tài: Pic 16f88

  1. #1
    Thất tinh ác ma linh's Avatar
    Tham gia
    Sat Jan 2009
    Bài
    280
    Thanks
    43
    Thanked 35 Times in 25 Posts

    Default Pic 16f88

    Con PIC 16F88 có giá 40k mua chợ trời hoặc hàn thuyên, giá này tính ra cũng ko đắt lắm cho thử nghiệm, nó khá bền ( nếu ko cắm sai mạch thì chắc là khó chết lắm )

    Program Memory Type Flash
    Program Memory (KB) 7
    RAM Bytes 368
    Data EEPROM (bytes) 256
    Digital Communication Peripherals 1-A/E/USART, 1-SSP(SPI/I2C)
    Capture/Compare/PWM Peripherals 1 CCP
    Timers 2 x 8-bit, 1 x 16-bit
    ADC 7 ch, 10-bit
    Comparators 2
    Pin Count 18
    1 PWM 10-bit
    8 MHz Internal Oscillator
    256 bytes of EEPROM data memory
    Temperature Range (C) -40 to 125
    Operating Voltage Range (V) 2 to 5.5

    Mình sẽ post 1 số bài mẫu cơ bản để ai mới bắt đầu có thể tham khảo !
    Nói chuyện không hợp, nửa câu là nhiều.
    Tri kỷ uống rượu, như gặp lại cố nhân ...

  2. #2
    Thất tinh ác ma linh's Avatar
    Tham gia
    Sat Jan 2009
    Bài
    280
    Thanks
    43
    Thanked 35 Times in 25 Posts

    Default code example IO

    dưới đây là 1 chương trình ví dụ thay đổi trang thái các chân ở port b, sử dụng dao động trong là 4Mhz, như vậy tần số làm việc là 4/4 =1Mhz, mỗi 1 câu lệnh đơn sẽ tương đương 1 us.

    /*************** Example code *****************
    Project : example 16F88
    Description : continuos change port b
    Created : 27-02-2009
    **********************************************/

    #include "main.h"
    void main()
    {
    int8 count;

    setup_adc_ports(NO_ANALOGS|VSS_VDD); // no use adc port
    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);
    setup_vref(FALSE);
    //Setup_Oscillator parameter not selected from Intr Oscillator Config tab

    // TODO: USER CODE!!
    set_tris_b(0x00); // set port b to output
    set_tris_a(0xff); // set port a to input
    for(;;)
    {
    if (++count > 200)
    {
    count = 0;
    }
    if(count > 100)
    {
    output_b(0xff); // set port b to 0xff
    }
    else
    {
    output_b(0x00); // down port b to 0
    }
    }
    }
    Nói chuyện không hợp, nửa câu là nhiều.
    Tri kỷ uống rượu, như gặp lại cố nhân ...

  3. #3
    Thành viên mới
    Tham gia
    Sun Jun 2012
    Bạn đang xài vB
    Cầu Giấy, HN
    Bài
    17
    Thanks
    35
    Thanked 0 Times in 0 Posts

    Default Em mới học Pic, mong mọi người giúp đỡ

    -Sử dụng PIC 16F877A
    -Phần mềm biên dịch CCS.Bài toán 1: Điều khiển Led không dùng phím bấm
    Code:
    #include "16f877a.h"
    #use delay(clock=20M)
    #fuses NOWDT,HS
    #include "math.h"
    int i;
    int8 m,a,b=0,c,d=0,e,f=0,g,h=0;
    void main()
    {
     set_tris_d(0x00); // Dat cong D lam cong ra
     output_d(0x00);  // Tat het cac led
      while(true)
         {
          // Sang roi tat
          output_d(0xff);
          delay_ms(1000);
          output_d(0x00);
          delay_ms(1000);
          // Sang led tu phai qua trai
          m=00000001;
          for(i=1;i<=7;i++)
            {
             output_d(m);
             delay_ms(1000);
             m=m<<1;
            }
          output_d(0xff);
          delay_ms(1000);
          // Sang dan led tu phai qua fai
          for(i=0;i<7;i++)
            {
             a= pow(2,i)+b;
             b=a;
             output_d(a);
             delay_ms(1000);
            }
            output_d(0xff);
            delay_ms(1000);
           // Sang led tu phai qua trai
           m=10000000;
           for(i=0;i<7;i++)
            {
             output_d(m);
             delay_ms(1000);
             m=m>>1;
            }
            output_d(0xff);
            delay_ms(1000);
            
           // Sang dan led tu trai qua phai
           for(i=7;i>=0;i--)
             {
              c=pow(2,i)+d;
              d=c;
              output_d(a);
              delay_ms(1000);
             }
           // Sang led tu ngoai vao trong
           output_d(pow(2,7)+pow(2,0));
           delay_ms(1000);
           for(i=0;i<=2;i++)
             {
              e= pow(2,6-i)+pow(2,i+1)+f;
              f=e;
              output_d(pow(2,7)+pow(2,0)+e);
              delay_ms(1000);
             }
           // Sang led tu trong ra ngoai
           output_d(pow(2,4)+pow(2,3));
           delay_ms(1000);
           for(i=0;i<=2;i++)
              {
               g=pow(2,5+i)+pow(2,2-i)+h;
               h=g;
               output_d(pow(2,4)+pow(2,3)+g);
               delay_ms(1000);
              }
         }
    }
    Hình kèm theo
    thay đổi nội dung bởi: DT2K50, 18-06-2012 lúc 09:49 PM

  4. #4
    Thành viên mới
    Tham gia
    Sun Jun 2012
    Bạn đang xài vB
    Cầu Giấy, HN
    Bài
    17
    Thanks
    35
    Thanked 0 Times in 0 Posts

    Default Em mới học Pic, mong mọi người giúp đỡ

    -Sử dụng PIC 16F877A
    - Biên dịch bằng CCS.Bài toán 2: ĐK Led dùng phím bấm
    Code:
    // Chưa bấm phím Led không sáng
       Bam phím lần 1:Led 0 va Led 4 sang
       Bam phim lan 2:Led sáng tắt
       Bâm phim lan 3:Dich Led
       Bam phim lan 4:Rết ve luc chua bam phim
    
    #include "16f877a.h"
    #use delay(clock=20M)
    #fuses NOWDT,HS
    int i=0,j=0,k;
    int8 a=00000001;
    void led(void)
         {
         output_d(0xff);
         delay_ms(1000);
         output_d(0x00);
         delay_ms(1000);
         }    
    void doc_phim(void)
        {
        if(input_state(pin_c0)==0&&i==0)
             i=1;
        if(input_state(pin_c0)==1&&i==1)             
            {
             i=0;
             j++;
            }
        }
    void dich_led (void)
     { 
                            
                          for(k=0;k<=7;k++) 
                             {
                               output_d(a);
                               delay_ms(1000);
                               a=a<<1;
                              }
                            a=10000000;
                           for(k=7;k>=0;k--)
                             {
                               output_d(a);
                               delay_ms(1000);
                               a=a>>1;
                              }
                             a=000000001;
     }                      
    void main()
    {
     set_tris_d(0x00); // Cong D lam ngo ra
     output_d(0x00);
     set_tris_c(0x01); // C0 lam nut nhan dieu khien
     while(true)
        {
            doc_phim();
            switch(j)
               {
                   case 0: output_d(0x00);
                           break;
                   case 1: output_d(0x11);
                           break;
                   case 2: led();
                           break; 
                   case 3:
                            dich_led();
                            break;
                   default:
                           j=0;
                           break;
               }
        }     
    }
    Cho em hỏi là: Khi bấm phím đến lần thứ 3 (chưa bấm phím lần 4) thì Led vẫn cứ dịch đều đều.Chương trình trên chỉ dich Led theo 1 chu ki, nó không liên tục.Vậy muốn nó chạy đều đều cần làm thế nào ạ?
    Hình kèm theo

+ Trả Lời Ðề Tài

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Quyền Sử Dụng Ở Diễn Ðàn

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts