2019年10月31日 星期四

107 year


#include <at89x52.h>
char seg7[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
char seg_data[]={0xa4,0xc0,0xf9,0x80};
char seg_data1[]={0xc0,0x82,0xc0,0x90};
char seg_data2[]={0x82,0xf8,0x80,0x90};
char left_move[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
char increase[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
char increase2[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
unsigned char scanline=0x80;
sbit sw1=P3^7;//left
sbit sw2=P3^6;//right
int k,x=0;

void delay_1ms(int x)
{
        int i,j;
        for(i=0;i<x;i++)
          for(j=0;j<114;j++)
               ;
}
void debouncer()
{
        int i,j;
        for(i=0;i<20;i++)
          for(j=0;j<114;j++)
               ;
}
void init()
{
        int i;
        for(i=0;i<2;i++)
        {
           P0=0x00;P2=0x00;P1=0XFF;delay_1ms(200);P0=0xFF;P2=0x00;P1=0XFF;delay_1ms(200);              
        }
        for(i=0;i<2;i++)
        {
            P1=0XFF;P2=0xFF;P0=0x0F;delay_1ms(200);P1=0XFF;P2=0x00;P0=0x0F;delay_1ms(200);
        }
        P0=0XFF;
        for(i=0;i<2;i++)
        {
           P1=0x00;P0=0xff;P2=0x00;delay_1ms(200);P1=0xff;P0=0xff;P2=0x00;delay_1ms(200);
        }
        P1=seg7[k];
}
main()
{
         init();
        IE=0x82;
     TMOD=0x01;
     TH0=(65536-20000)/256;
         TL0=(65536-20000)%256;
         TR0=1;
     while(1)
         {
           if (k==1)
                {
                         P2=0x00;
                         P1=seg7[k];
             P0=0x00;delay_1ms(200);
                         P0=0xff;delay_1ms(200);
                   // LED  循環不斷閃爍
                 }
               if (k==2)
               {
         int i;
                 P2=0x00;
                 P1=seg7[k];
                 if(x==0)
                 {
                    for(i=0;i<=7;i++)
                    {
                           P0=~left_move[i];delay_1ms(200);
                    }
                     x=1;
                  }        
                          else if(x==1)
                         {
                                        P0=0xff;
                         }
                 }
         //LED  單顆左移,這種方法叫什麼控制
               if (k==3)
                {
       int i;
                         P2=0x00;
                         P1=seg7[k];
                         if(x==1)
                         {
                           for(i=7;i>=0;i--)
                           {
                                   P0=~left_move[i];delay_1ms(200);
                           }
                                 x=0;
                         }
                         if(x==0)
                         {
                                 P0=0xff;
                         }
                   //LED  單顆右移
                }

                 if(k==4)
                 {
       int i;
                         P2=0x00;
                         P1=seg7[k];
                         if(x==0)
                         {
                          for(i=0;i<=7;i++)
                          {
                                  P0=~increase[i];delay_1ms(200);
                          }
                         x=1;
                         }
       if(x==1)
                         {
                                 P0=0xff;
                         }                            
                   //  LED  左移漸亮(逐一多顆亮)
               }
                 if (k==5)
                {
                   //LED 右移漸亮(逐一多顆亮)
       int i;
                         P2=0x00;
                         P1=seg7[k];
                         if(x==1)
                         {
                          for(i=0;i<=7;i++)
                          {
                                 P0=~increase2[i];delay_1ms(200);
                          }
                                x=0;
                   }
       if(x==0)
       {
                                 P0=0xff;
       }      
                 }
               if (k==6)
                {
                         int i,j;
                         P1=seg7[k];
                         for(j=0;j<=100;j++)
                         {
                          scanline=0x80;
                          for(i=0;i<=3;i++)
                          {
                                 P2=0x00;//要先關掉四位數七段顯示器,否則無法正常顯示
                                 P0=~scanline;
                                 P2=~seg_data[i];delay_1ms(4);
                                 scanline=scanline>>=1 ;
                           }
                          }
                         for(j=0;j<=100;j++)
                         {
                          scanline=0x80;
                          for(i=0;i<=3;i++)
                          {
                                 P2=0x00;//要先關掉四位數七段顯示器,否則無法正常顯示
                                 P0=~scanline;
                                 P2=~seg_data1[i];delay_1ms(4);
                                 scanline=scanline>>=1 ;
                           }
                          }

                                 // 四位七段出現 2018  0609 交替顯示。      
             for(j=0;j<=100;j++)
                         {
                          scanline=0x80;
                          for(i=0;i<=3;i++)
                          {
                                 P2=0x00;//要先關掉四位數七段顯示器,否則無法正常顯示
                                 P0=~scanline;
                                 P2=~seg_data2[i];delay_1ms(4);
                                 scanline=scanline>>=1 ;
                           }
                          }
                        }      
               if (k==0)
               {
                        P1=seg7[k];
      P0=0xFF;P2=0x00;
                        //LED 四位、七段均需熄滅

               }
                if (k==7)
               {
                        P1=seg7[k];
            P0=0xFF;P2=0x00;
                        //LED 四位、七段均需熄滅

               }
                if (k==8)
               {
                        P1=seg7[k];
            P0=0xFF;P2=0x00;
                        //LED 四位、七段均需熄滅

               }
                if (k==9)
               {
                        P1=seg7[k];
      P0=0xFF;P2=0x00;
                        //LED 四位、七段均需熄滅

               }

 }
}
void my_time0(void) interrupt 1
{
        TH0=(65536-20000)/256;
        TL0=(65536-20000)%256;
        if (sw1==0)
        {
               debouncer();
                while(sw1!=1);
                debouncer();
                k=k+1;
                if (k>9) k=0;
        }
        if (sw2==0)
        {
               debouncer();
                while(sw2!=1);
                debouncer();
                k=k-1;
                if (k<0) k=9;
        }
}

沒有留言:

張貼留言

algorithm

 #include <iostream> #include <string.h> using namespace std; int main(int argc, char** argv)  { for(int j=2;j<=100;j++)//j...