2019年10月3日 星期四

進入 Mode0 模式,七段顯示器顯示 00



/*4.進入 Mode0 模式,七段顯示器顯示 00 5%
   5. 按下按鈕開始上數 00~99,到 99 時需回到 00 不斷重複 5%
*/
#include "REG51.h"   
int i=20;             
int j=0;
int q;
int x=1;
sbit sw1=P3^2;
char count=0;       
char bcd[2]={0,0};     
static const char P1table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
static const char P2table[]={1,2};
void delay_1ms(int k)
{
 int i,j;
 for(i=0;i<k;i++)
  for(j=0;j<110;j++)
       ;
}
void mode()
{

P1=P1table[0];P2=~P2table[0];
P1=P1table[0];P2=~P2table[1];
}
void main() 
{
    IE=0x8a;         
    TMOD=0x10;       
    TH0=(8192-5000)/32; 
    TL0=(8192-5000)%32;
    TH1=(65536-50000)/256;
    TL1=(65536-50000)%256;
    TR0=0;         
    TR1=0;         
    while(1)
{
for(q=0;q<50;q++)
{
if(x==1) mode();
if(sw1==0)
{
x=0;
TR0=1;TR1=1;
}
}
}
} /* main */
void T0_int(void) interrupt 1
{
    TH0=(8192-5000)/32; 
    TL0=(8192-5000)%32;
    P1=P1table[ bcd[j] ];   
    P2=~P2table[j];     
    j++;             
    if(j==2)         
      j=0;           
}
void T1_int(void) interrupt  3
{
    TH1=(65536-50000)/256; 
    TL1=(65536-50000)%256;
  i = i-1;
    if(i==0)         
    {
        i=20;         
        count++;       
        if(count==100)       
          count=0;       
        bcd[1]=count/10;   
        bcd[0]=count%10;   
    }
}

00-99 8051

#include "REG51.h"   
int i=20;             
int j=0;             
char count=0;         
char bcd[2]={0,0};       
static const char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
static const char P2table[]={1,2}; 
void main()   
{
    IE=0x8a;         
    TMOD=0x10;         
    TH0=(8192-5000)/32; 
    TL0=(8192-5000)%32;
    TH1=(65536-50000)/256;
    TL1=(65536-50000)%256;
    TR0=1;         
    TR1=1;           
    while(1);       
}
void T0_int(void) interrupt 1
{
    TH0=(8192-5000)/32; 
    TL0=(8192-5000)%32;
    P1=table[ bcd[j] ];   
    P2=~P2table[j];     
    j++;               
    if(j==2)         
      j=0;           
}
void T1_int(void) interrupt  3 
{
    TH1=(65536-50000)/256; 
    TL1=(65536-50000)%256;
  i = i-1;
    if(i==0)         
    {
        i=20;         
        count++;       
        if(count==100)       
          count=0;       
        bcd[1]=count/10;   
        bcd[0]=count%10;     
    }
}

2019年10月2日 星期三

逆時針左旋三圈+8顆LED 左右移三次 +蜂鳴器”Bi~Bi~Bi~”響三次


/*
1.七段顯示器從個位數”a”開始,逆時針左旋三圈,最後停在個位數”a”約 0.5 秒(旋轉時間自訂)
2.8顆LED 左右移三次 5%
3.蜂鳴器”Bi~Bi~Bi~”響三次 5%
*/
#include <at89x52.h>
int P1table[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x02,0x04,0x08,0x10,0x20,0x40};
int i,ii;
sbit buzzer = P3^7;
int anti_cck_i;
int pili_led_i;
void delay_1ms(int k)
{
 int i,j;
 for(i=0;i<k;i++)
 for(j=0;j<110;j++)
       ;
}
 void anti_cck()
 {
   for(anti_cck_i=0;anti_cck_i<3;anti_cck_i++)
   {
   P2=0XFE;P0=0XFE;delay_1ms(500);//亮a 個位數
   P2=0XFD;P0=0XFE;delay_1ms(500); //亮a十位數
   P2=0XFB;P0=0XFE;delay_1ms(500); //亮a百位數
   P2=0XF7;P0=0XFE;delay_1ms(500); //亮a千位數
   P2=0XF7;P0=0XDF;delay_1ms(500); //亮f千位數
   P2=0XF7;P0=0XEF;delay_1ms(500); //亮e千位數
   P2=0XF7;P0=0XF7;delay_1ms(500); //亮d千位數
   P2=0XFB;P0=0XF7;delay_1ms(500); //亮d百位數
   P2=0XFD;P0=0XF7;delay_1ms(500); //亮d十位數
   P2=0XFE;P0=0XF7;delay_1ms(500); //亮d個位數
   P2=0XFE;P0=0XFB;delay_1ms(500); //亮c個位數
   P2=0XFE;P0=0XFD;delay_1ms(500); //亮b個位數
   }
   P2=0XFE;P0=0XFE;delay_1ms(500); //亮a個位數
 }
void pili_led()
{
 for(ii=0;ii<3;ii++)
 {
  for(pili_led_i=0;pili_led_i<14;pili_led_i++)
  {
  P1=~P1table[pili_led_i];delay_1ms(500);
   }
  }
}
void pulse_BZ(int count,int TH,int TL)
{
 int i;     
 for(i=0;i<count;i++)
 {
  buzzer=0;   
  delay_1ms(TL); 
  buzzer=1;   
  delay_1ms(TH);
 }
}

main()
{
 P0=~0xFF;P2=0XFF;
 anti_cck();
 P0=~0xFF;P2=0XFF;
 pili_led();
 P1=~0x80;delay_1ms(500);P1=0xFF;
 pulse_BZ(100,1,1);delay_1ms(1000);     
 pulse_BZ(100,1,1);delay_1ms(1000);
 pulse_BZ(100,1,1);delay_1ms(1000);
 while(1)
 {
  ;
 }
}

beep 3聲

#include  <reg51.h>
sbit buzzer = P3^7 ;
void delay_1ms(int k)
{
 int i,j;
 for(i=0;i<k;i++)
  for(j=0;j<55;j++)
       ;
}
void pulse_BZ(int count,int TH,int TL)
{
int i;
for(i=0;i<count;i++)
{
buzzer=0;
delay_1ms(TL);
buzzer=1;
delay_1ms(TH);
}
}
main()
{
pulse_BZ(100,1,1);delay_1ms(1000);
pulse_BZ(100,1,1);delay_1ms(1000);
pulse_BZ(100,1,1);delay_1ms(1000);
while(1);
}

2019年10月1日 星期二

Atheros_lan_vx_mb


逆時針繞三圈+pili_led左商三次


#include <at89x52.h>
int P1table[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x02,0x04,0x08,0x10,0x20,0x40};
int i,ii;
int anti_cck_i;
int pili_led_i;
void delay_1ms(int k)
{
 int i,j;
 for(i=0;i<k;i++)
for(j=0;j<110;j++)
      ;
}
void anti_cck()
{
for(anti_cck_i=0;anti_cck_i<3;anti_cck_i++)
{
P2=0XFE;P0=0XFE;delay_1ms(500);//亮a 個位數
P2=0XFD;P0=0XFE;delay_1ms(500); //亮a十位數
P2=0XFB;P0=0XFE;delay_1ms(500); //亮a百位數
P2=0XF7;P0=0XFE;delay_1ms(500); //亮a千位數

P2=0XF7;P0=0XDF;delay_1ms(500); //亮f千位數
P2=0XF7;P0=0XEF;delay_1ms(500); //亮e千位數
P2=0XF7;P0=0XF7;delay_1ms(500); //亮d千位數
P2=0XFB;P0=0XF7;delay_1ms(500); //亮d百位數
P2=0XFD;P0=0XF7;delay_1ms(500); //亮d十位數

P2=0XFE;P0=0XF7;delay_1ms(500); //亮d個位數
P2=0XFE;P0=0XFB;delay_1ms(500); //亮c個位數
P2=0XFE;P0=0XFD;delay_1ms(500); //亮b個位數
}
P2=0XFE;P0=0XFE;delay_1ms(500); //亮a個位數
}
void pili_led()
{
for(ii=0;ii<3;ii++)
{
for(pili_led_i=0;pili_led_i<14;pili_led_i++)
{
P1=~P1table[pili_led_i];delay_1ms(500);
   }
  }
}
main()
{
P0=~0xFF;P2=0XFF;
anti_cck();
P0=~0xFF;P2=0XFF;
  pili_led();
  P1=~0x80;delay_1ms(500);P1=0xFF;
 while(1)
 {
;
 }
}

四位數_逆時針繞三圈


#include <at89x52.h>
int i;
int anti_cck_i;
void delay_1ms(int k)
{
 int i,j;
 for(i=0;i<k;i++)
for(j=0;j<110;j++)
      ;
}
void anti_cck()
{
for(anti_cck_i=0;anti_cck_i<3;anti_cck_i++)
{
P2=0XFE;P1=0XFE;delay_1ms(500);//亮a 個位數
P2=0XFD;P1=0XFE;delay_1ms(500); //亮a十位數
P2=0XFB;P1=0XFE;delay_1ms(500); //亮a百位數
P2=0XF7;P1=0XFE;delay_1ms(500); //亮a千位數

P2=0XF7;P1=0XDF;delay_1ms(500); //亮f千位數
P2=0XF7;P1=0XEF;delay_1ms(500); //亮e千位數
P2=0XF7;P1=0XF7;delay_1ms(500); //亮d千位數
P2=0XFB;P1=0XF7;delay_1ms(500); //亮d百位數
P2=0XFD;P1=0XF7;delay_1ms(500); //亮d十位數

P2=0XFE;P1=0XF7;delay_1ms(500); //亮d個位數
P2=0XFE;P1=0XFB;delay_1ms(500); //亮c個位數
P2=0XFE;P1=0XFD;delay_1ms(500); //亮b個位數
 }
  P2=0XFE;P1=0XFE;delay_1ms(500); //亮a個位數,因為最後停留在a
}
main()
{
 P1=~0xFF;P2=0XFF;
 anti_cck();
 P1=~0xFF;P2=0XFF;
 while(1)
 {
;
 }
}

algorithm

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