giúp em với:Lập trình nút bấm cho pic 16f877a voi???

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • victory_1410
    Nhập môn đệ tử
    • May 2010
    • 3

    #16
    Nguyên văn bởi tanbka View Post
    Bạn phải đưa hàm banphim() vào trong vòng lặp while thì nó mới chạy được chứ
    Với lại việc khai báo hàm void convert_bcd(int8 x) phải đặt trước hàm main() chứ bạn
    cảm ơn bạn ! mình mới nhập môn ! mong học hỏi

    Comment

    • victory_1410
      Nhập môn đệ tử
      • May 2010
      • 3

      #17
      Nguyên văn bởi tdm View Post
      thôi thì để tôi chèn giúp bạn vài dòng lệnh để code hoàn chỉnh vậy.
      Code:
      #include <16F877A.h>
      #include <def_877a.h>
      #device *=16 adc=10
      #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,NOLVP, NOCPD, NOWRT
      #use delay(clock=20000000)
      #include <lcd_lib_4bit.c> // Thu vien ham cho LCD
      
      int8 low,high,min,max,i,sida=0xaa;
      int1 do_F;
      float value;
      #define nut1 RC2
      #define nut2 RC3
      #define nut3 RC4
      #INT_EXT
      void test()
         {
         if (do_F == 1) do_F=0;
         else do_F=1;
         }
         void banphim(void);
         void convert_bcd(int8 x);
         
      //-----------------------------------------------------------------
      void main()
         {
         min =0;      //nhiet do mim 
         max =40;    //nhiet do max 
         do_F =0 ;
         i = 10 ;
         trisa = 0xFF;
         trisb = 0x01;
         trisc = 0b00011100;
         output_low(pin_C0);
         output_low(pin_C1);
          //==== Khoi tao cho ngat ngoai===============================================
         enable_interrupts (INT_EXT);
         ext_int_edge(H_TO_L);
         enable_interrupts (GLOBAL);
         //=========== Khoi tao che do cho bo ADC=====================================
         setup_adc_ports(AN0);
         setup_adc(ADC_CLOCK_INTERNAL);
         LCD_init();
         LCD_putcmd(0x01);
         LCD_putchar("do_nhiet_do:");
         LCD_putcmd(0xC0);
         LCD_putchar("cho ty nhe ...");
         delay_us(10);// Lay mau nhiet do lan dau tien
         value=(float)read_adc();
         value = (value - 558.5)/2.048; // For 5V supply
         // value = (value - 754.8)/2.048; // For 3.7V Supply
         // value = (value - 698.2)/2.048; // For 4V supply
         convert_bcd(value); // Tach so tram, chuc, donvi de hien thi len LED 7
         delay_ms(100);
         LCD_putcmd(0xC0);
         LCD_putchar("Ok               ");
         delay_ms(100);
         while(1)
            {
            banphim();
            if (i==10)
               {
                if(sida==0xaa)
                {
               value = read_adc();
               value=(value-558.5)/2.048;
               
               if (do_F==1) 
                  value=1.8*value+32;
               convert_bcd(value);
      
               LCD_putcmd(0xC0);
               printf(LCD_putchar,"Nhiet do la:");
               LCD_putchar(high); LCD_putchar(low);
               
               if (do_F==0) 
                  printf(LCD_putchar," C");
               else 
                  printf(LCD_putchar," F");
               i=0;
                }
                else
                {
                }
               }//
              
         if (value <= max & min <=value) 
             {
                output_high(pin_C1);
             }
              else output_low(pin_C1);
         if(value > max ||value < min)
                output_high(pin_C0);
             else output_low(pin_C0); 
            i++;
            }
         }
      //The End=======================================================================
      void convert_bcd(int8 x)
         {
         low=x%10;      //chia lay phan du, so hang don vi
         high=x/10;     //tach hang tram va hang chuc
         low = low + 0x30;
         high = high + 0x30;
         }
      void banphim()
      { 
      if (nut1 == 0)
      {
      sida=~sida;
      if(sida!=0xaa)
      {
      LCD_putcmd(0x01);
      LCD_putchar("nhap nhiet do:");
      LCD_putcmd(0xC0);
      printf(LCD_putchar,"gia tri MAX:%d",max);
      }
       else
       {
       LCD_putcmd(0x01);
       LCD_putchar("do_nhiet_do:");
       value = read_adc();
               value=(value-558.5)/2.048;
               
               if (do_F==1) 
                  value=1.8*value+32;
               convert_bcd(value);
      
               LCD_putcmd(0xC0);
               printf(LCD_putchar,"Nhiet do la:");
               LCD_putchar(high); LCD_putchar(low);
               
               if (do_F==0) 
                  printf(LCD_putchar," C");
               else 
                  printf(LCD_putchar," F");
       }
      while(nut1 == 0)
      {
      }
      }
      else if (nut3 == 0)
      {
        if(sida!=0xaa)
        {
        max = max - 1;
        LCD_putcmd(0xC0);
        printf(LCD_putchar,"gia tri MAX:%d",max);
        }
      else
         {
         }
         while(nut3 == 0)//cho nha phim
         {
          }
         delay_ms(10);//chong nay phim
      }
      else if (nut2 == 0)
      {
        if(sida!=0xaa)
        {
        max = max +1;
        LCD_putcmd(0xC0);
        printf(LCD_putchar,"gia tri MAX:%d",max);
        }
         else
         {
         }
         while(nut2 == 0)//cho nha phim
         {
          }
         delay_ms(10);//chong nay phim
      }
      else
      {
      }
      }
      http://www.youtube.com/watch?v=nvtwwuzRkZI
      cảm ơn anh Minh nhiều ! em mới tìm hiểu Pic có được những bài như thế này rất hữu ích với em!
      Mong nhận được những bài hay từ anh!

      Comment

      Working...