Thông báo

Collapse
No announcement yet.

Technometer (đèn nháy đồng hồ)

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Technometer (đèn nháy đồng hồ)

    Công trình dài hơi, chạy được nhưng vẫn trong phòng thí nghiệm, làm đã lâu và lười chưa muốn làm nốt. post lên cho bạn nào khoái nghịch phát triển tiếp
    Click image for larger version

Name:	111.png
Views:	658
Size:	78.2 KB
ID:	1646099
    các bạn chú ý giúp các trở nối led là 47Ohm nhé
    các chân nối vào chíp tương ứng với define ở code bên dưới nhé.
    Chân xung dữ từ động cơ đưa vào chân T1 của chip 16F628a.
    Code:
    #include <16F628a.h>
    
    #FUSES WDT                      //Watch Dog Timer
    #FUSES NOPUT                    //No Power Up Timer
    #FUSES HS                 //Internal RC Osc, no CLKOUT
    #FUSES NOMCLR                   //Master Clear pin used for I/O
    #FUSES NOBROWNOUT               //No brownout reset
    #FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
    #FUSES NOCPD                    //No EE protection
    #FUSES PROTECT                //Code not protected from reading
    
    #use delay(clock=20000000,restart_wdt)
    
    #define EXP_OUT_ENABLE  PIN_B4  //ST
    #define EXP_OUT_CLOCK   PIN_B1  //SH
    #define EXP_OUT_DO      PIN_B2  //DS
    
    #define CHR PIN_A0
    #define CHG PIN_B7
    #define CHB PIN_B5
    
    #define numled 32
    
    long step,value,datain,maxdata;
    char startcheck=0;
    signed int8 store=0;
    char sec;
    signed int8 CR,CG,CB,maxcolor;
    
    void init()
       {
       step=maxdata/numled;
       }
    
    void RGB(char red,char green,char blue)
    {
    static char index;
    
    if(red>0)
       {output_low(CHR);}
    if(green>0)
       {output_low(CHG);}
    if(blue>0)
       {output_low(CHB);}
    for(index=0;index<maxcolor;index++)
       {
       if(index==red)
          {output_high(CHR);}
       if(index==green)
          {output_high(CHG);}
       if(index==blue)
          {output_high(CHB);}
       }
    
    }
    void scanled(long data)
    {
    char i,count,color;
    long temp;
    temp=step;
    //temp=0;
    static long remain1,remain2;
    //For peak
    if(remain1>0)
       {
       remain1--;
       }
    if(remain1==0)
       {
       if(remain2--==0)
          {
          remain2=50;
          if(store<numled)
             {
             store++;
             }
          }
       }
    count+=4;
    if(count>=numled)
       {count=0;}
    //For scan
    color=0;
    for(i=0;i<numled;i++)
       {
       if(data>=(maxdata-temp))
          {
          color+=2;
          if((i>=count)&&(i<=count+4))
             {
             output_low(EXP_OUT_DO);
             if(store>i)
                {
                store=i;
                remain1=1500;//delay peak
                remain2=50;//speed down
                }
             }
          }
       else if(i==store)
          {output_low(EXP_OUT_DO);}
       else
          {output_high(EXP_OUT_DO);}   
       temp=temp+step;
       output_high(EXP_OUT_CLOCK);
       output_low(EXP_OUT_CLOCK);   
       }
    if(maxcolor<color){maxcolor=color;}
    
    //red
    CR=(color-20)*2;
    if(CR<0){CR=0;}
    if(CR>maxcolor){CR=maxcolor;}
    //green
    CG=(maxcolor-color-20)*2;
    if(CG<0){CG=0;}
    if(CG>maxcolor){CG=maxcolor;}
    //blue
    if(color>(maxcolor/2))
       {CB=maxcolor-15-color+4;}
    else {CB=color-15+4;}
    if(CB<0){CB=0;}
    output_high(EXP_OUT_ENABLE);
    output_low(EXP_OUT_ENABLE);
    RGB(CR,CG,CB);   
    }
    #int_timer0
    void timer0()
    {
    static char count;
    set_timer0(0);
       if(count++>10)
          {
          count=0;
          //output_toggle(PIN_A1);
          value=get_timer1();
          if(maxdata<value+step)
             {
             maxdata=value;
             init();
             }
          set_timer1(0);
          }
    }
    void main()
    {
    value=1024;
    maxdata=value;
    init();
    
    setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_256);
    disable_interrupts(INT_TIMER0);
    setup_timer_1(T1_EXTERNAL);
    enable_interrupts(GLOBAL);
    set_timer0(0);
    
    datain=0;
    output_high(CHR);
    output_high(CHG);
    output_high(CHB);
    While(TRUE)
       {
       restart_wdt();
       if(sec++>1)
          {
          sec=0;
          if(startcheck==0)
             {
             if(datain==value)
                {value=0;}
             if((value==0)&&(datain==0))
                {
                startcheck=1;
                maxdata=5;
                step=0;
                enable_interrupts(INT_TIMER0);
                set_timer1(0);
                }
             }
          //else
            // {enable_interrupts(INT_TIMER0);}
          
          if(value>datain)
             {datain+=1;}
          if(value<datain)
             {datain-=1;}
          }
       scanled(datain);
       //output_low(CHR);
       
       }
    }
    Nợ ít hình ảnh và video sản phẩm thí nghiệm tối về post sau!

  • #2
    Ít hỉnh ảnh sản phẩm demo!
    https://www.youtube.com/watch?v=IRQg...ature=youtu.be

    Comment

    Về tác giả

    Collapse

    nhanh0112 Tìm hiểu thêm về nhanh0112

    Bài viết mới nhất

    Collapse

    Đang tải...
    X