- 寫了4個信號分兩組處理,1Hz,2Hz,8Hz,16Hz
- 不多說,看電完電視后,來上程序了!
- //#pragma src(signle.a51)
- #include <reg52.h>
- #include <display.c>
- #define uchar unsigned char
- #define uint unsigned int
- //sfr PCON = 0x87h;
- sbit Key1 = P3^2;
- sbit BUZ = P3^1;
- sbit Signle = P3^0;
- sbit Led0 = P1^0;
- sbit JDQ = P1^2;
- sbit Dp = P1^5;
- sbit SMG1 = P3^7;
- sbit SMG2 = P3^5;
- sbit SMG3 = P3^4;
- sbit SMG4 = P3^3;
- uint Key_count,Time_value,Time_Count,BTime_Count;
- uchar Beep_time,Key_flag,BTime_Flag,JDQ_flag,BP_Count,LM_Count,LM_GroupCNT;
- uchar BT_Sec,Sec,Min,Hour,Key_Select,Key_long_flag,Key_long_count;
- uchar Led_Scan,Led_Loop,Sec_1,Min_1,Hour_1,BT_Sec_1;
- uchar Key_Select_Flag,BT_4Sec;
- //uchar Display_number[]={0xd7,0x14,0xcd,0x5d,0x1e,0x5b,0xdb,0x15,0xdf,0x5f,0x00};
- uchar code Display_number[]={0xff,0xff,0x28,0xeb,0x32,0xa2,0xe1,0xa4,0x24,0xea,0x20,0xa0,0xf7,0xff}; //0123456789 -
- uchar code Display_string_1Hz[]={0xff,0xff,0xff,0xf7,0xeb,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//-1HZ-
- uchar code Display_string_2Hz[]={0xff,0xff,0xff,0xf7,0x32,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//-2HZ-
- uchar code Display_string_8Hz[]={0xff,0xff,0xff,0xf7,0x20,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//-8HZ-
- uchar code Display_string_16Hz[]={0xff,0xff,0xff,0xf7,0xeb,0x24,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//-16HZ-
- uchar Clock[]={0xff,0xff,0xff,0xeb,0x32,0xf7,0xeb,0x32,0xf7,0xeb,0x32,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
- //---------------------------------------------------
- //---------------------------------------------------
- //4COM 共陽數碼管 1234 SR410361K
- //---------------------------------------------------
- //P1.0 A; |---|
- //P1.2 B; | |
- //P1.4 C; |---|
- //P1.6 D; | |
- //P1.7 E; |---|
- //P1.1 F;
- //P1.3 G;
- //P1.5 Dp;
- //SMG1=P3.7,SMG2=P3.5,SMG3=P3.4,SMG4=P3.3;
- //---------------------------------------------------
- //---------------------------------------------------
- void display_Scan(void);
- void Delay_ms();
- void Delay_ms(uint Tms)
- {
- uint i,j;
- for(i=Tms;i>0;i--)
- for(j=1220;j>0;j--)
- {;}
- }
- void Delay_us(uint Tus)
- {
- while(--Tus);
- }
- void Buz(void)
- {
- uint i;
- for(i=0;i<200;i++)
- {
- BUZ=~BUZ;
- Delay_us(300);
- }
- BUZ=0;
- }
- void Beep_Bi(void)
- {
- if(Beep_time!=0)
- {
- Beep_time--;
- BUZ=~BUZ;
- }
- else
- {
- BUZ=0;
- }
- }
- void T0_ini()
- {
- TMOD=0x12;
- TH1=(65536-1000)/256;
- TL1=(65536-1000)%256;
- TR1=1;
- ET1=1;
- TH0=6;
- TL0=6;
- TR0=0;
- ET0=1;
- EA=1;
- }
- void TM0(void)interrupt 1
- {
- //uint Time_Count,BTime_Count;
- TF0=0;
- Time_Count++;BTime_Count++;BP_Count++;
- if(BTime_Count==1000)
- {
- BTime_Count=0;BT_Sec++;
- if(BT_Sec==2)
- {
- BT_Sec=0;BTime_Flag=~BTime_Flag;BT_4Sec++;
- if(BT_4Sec==8)
- {
- BT_4Sec=0;Key_Select=0;
- }
- }
- }
- if(BP_Count==2) //1ms DiDa Batime;
- {
- BP_Count=0;
- Beep_Bi();
- }
- if(Key_Select_Flag==1) //1Hz
- {
- if(Time_Count==2000)
- {
- Time_Count=0;Dp=~Dp;Signle=~Signle;
- }
- }
- if(Key_Select_Flag==2) //2Hz
- {
- if(Time_Count==1000) //500 4Hz//250 8Hz//125 16Hz
- {
- Time_Count=0;Dp=~Dp;Signle=~Signle;
- }
- }
- if(Key_Select_Flag==3) //8Hz
- {
- if(Time_Count==250)
- {
- Time_Count=0;Dp=~Dp;Signle=~Signle;
- }
- }
- if(Key_Select_Flag==4) //16Hz
- {
- if(Time_Count==125)
- {
- Time_Count=0;Dp=~Dp;Signle=~Signle;
- }
- }
- //if(Time_Count==2000) // ext atxl 12MHz;500ms
- //if(Time_Count==1333) // ext atxl 8MHz 500ms;
- //if(Time_Count==998) // built in atxl; 500ms
- }
- void TM1(void)interrupt 3
- {
- TH1=(65536-1000)/256;
- TL1=(65536-1000)%256;
- Led_Scan=1;Led_Loop++;Led_Loop=Led_Loop&0x03;
-
- Key1=1;
- if(Key1==0)
- {
- Key_count++;
- if(Key_count==20)
- {
- Beep_time=100;Key_flag=1;
- BTime_Count=0;BT_Sec=0;BT_4Sec=0;Time_Count=0;
- TR0=1;Key_Select++;
- if(Key_Select==5)
- {
- Key_Select=0;Key_Select_Flag=0;Key_flag=0;TR0=0;
- }
- if(Key_Select==1)
- {
- Key_Select_Flag=0;Key_Select_Flag=1;
- }
- if(Key_Select==2)
- {
- Key_Select_Flag=0;Key_Select_Flag=2;
- }
- if(Key_Select==3)
- {
- Key_Select_Flag=0;Key_Select_Flag=3;
- }
- if(Key_Select==4)
- {
- Key_Select_Flag=0;Key_Select_Flag=4;
- }
- }
- }
- else
- {Key_count=0;Key_long_flag=0;}
- }
- void SmgDisp(uchar ch,uchar num)
- {
- uchar number;
- number=num;
- //P3=0x03;
- P1=0xff;
- SMG1=0;SMG2=0;SMG3=0;SMG4=0;
- switch(ch)
- {
- case 1:SMG4=1;LM_Count=0;break; //SMG排列 1 2 3 4 第四個數碼管
- case 2:SMG3=1;LM_Count++;break; //SMG排列 1 2 3 4 第三個數碼管
- case 3:SMG2=1;LM_Count++;break; //SMG排列 1 2 3 4 第二個數碼管
- case 4:SMG1=1;LM_Count++;break; //SMG排列 1 2 3 4 第一個數碼管
- default:break;
- }
- if((Key_Select==0)&(Key_Select_Flag==1))
- { P1=Display_string_1Hz[number]; }
- else if((Key_Select==0)&(Key_Select_Flag==2))
- { P1=Display_string_2Hz[number]; }
- else if((Key_Select==0)&(Key_Select_Flag==3))
- { P1=Display_string_8Hz[number]; }
- else if((Key_Select==0)&(Key_Select_Flag==4))
- { P1=Display_string_16Hz[number]; }
- else
- P1=Display_number[number];
- }
- void CheckTime()
- {
- if(Led_Scan)
- {
- switch(Led_Loop)
- {
- case 0:SmgDisp(4,LM_Count+LM_GroupCNT);break; //第一個數碼管
- case 1:SmgDisp(3,LM_Count+LM_GroupCNT);break; //第二個數碼管
- case 2:SmgDisp(2,LM_Count+LM_GroupCNT);break; //第三個數碼管
- case 3:SmgDisp(1,LM_Count+LM_GroupCNT);break; //第四個數碼管
- }
- Led_Scan=0;
- }
- }
- void Display(void)
- {
- if((Key_Select==1)||(Key_Select==2))
- {
- if((BTime_Flag)&(Key_Select==1)&(Key_Select_Flag==1))
- {
- P1=0xff;SMG1=0;SMG2=0;SMG3=0;SMG4=0; //P3=0x00;
- }
- else
- {
- if(BTime_Flag)
- {
- Dp=0;SMG1=1; //P3=0x80;
- Delay_ms(1);SMG1=0; //P3=0x00;
- Dp=0;SMG2=1; //P3=0x20;
- Delay_ms(1);SMG2=0; //P3=0x00;
- }
- P1=Display_string_1Hz[4];
- SMG1=1; //P3=0x80;
- Delay_ms(1);
- SMG1=0; //P3=0x00;
- P1=0xff;
- P1=Display_string_1Hz[5];
- SMG2=1; //P3=0x20;
- Delay_ms(1);
- SMG2=0; //P3=0x00;
- P1=0xff;
- }
- if((BTime_Flag)&(Key_Select==2)&(Key_Select_Flag==2))
- {
- P1=0xff;SMG1=0;SMG2=0;SMG3=0;SMG4=0; //P3=0x00;
- }
- else
- {
- if(BTime_Flag)
- {
- Dp=0;SMG3=1; //P3=0x10;
- Delay_ms(1);SMG3=0; //P3=0x00;
- Dp=0;SMG4=1; //P3=0x08;
- Delay_ms(1);SMG4=0; //P3=0x00;
- }
- P1=Display_string_2Hz[4];
- SMG3=1; //P3=0x10;
- Delay_ms(1);
- SMG3=0; //P3=0x00;
- P1=0xff;
- P1=Display_string_2Hz[5];
- SMG4=1; //P3=0x08;
- Delay_ms(1);
- SMG4=0; //P3=0x00;
- P1=0xff;
- }
- }
- else
- if((Key_Select==3)||(Key_Select==4))
- {
- if((BTime_Flag)&(Key_Select==3)&(Key_Select_Flag==3))
- {
- P1=0xff;SMG1=0;SMG2=0;SMG3=0;SMG4=0; //P3=0x00;
- }
- else
- {
- if(BTime_Flag)
- {
- Dp=0;SMG1=1;
- Delay_ms(1);SMG1=0; //P3=0x00;
- Dp=0;SMG2=1; //P3=0x08;
- Delay_ms(1);SMG2=0; //P3=0x00;
- }
- P1=Display_string_8Hz[4];
- SMG1=1; //P3=0x10;
- Delay_ms(1);
- SMG1=0; //P3=0x00;
- P1=0xff;
- P1=Display_string_8Hz[5];
- SMG2=2; //P3=0x08;
- Delay_ms(1);
- SMG2=0; //P3=0x00;
- P1=0xff;
- }
- if((BTime_Flag)&(Key_Select==4)&(Key_Select_Flag==4))
- {
- P1=0xff;SMG1=0;SMG2=0;SMG3=0;SMG4=0; //P3=0x00;
- }
- else
- {
- if(BTime_Flag)
- {
- Dp=0;SMG3=1; //P3=0x10;
- Delay_ms(1);SMG3=0; //P3=0x00;
- Dp=0;SMG4=1; //P3=0x08;
- Delay_ms(1);SMG4=0; //P3=0x00;
- }
- P1=Display_string_16Hz[4];
- SMG3=1; //P3=0x10;
- Delay_ms(1);
- SMG3=0; //P3=0x00;
- P1=0xff;
- P1=Display_string_16Hz[5];
- SMG4=1; //P3=0x08;
- Delay_ms(1);
- SMG4=0; //P3=0x00;
- P1=0xff;
- }
- }
- }
- void exint0(void)interrupt 0
- {
- Buz();T0_ini();EX0=0;EA=1;
- }
-
- void Display_Scan(void)
- {
- P1=0x00;
- P3=0x00;
- //---------"A"--------------p1.0
- //P1=0x01;
- P1=0xfe;
- P3=0x80; //smg1
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfe;
- P3=0x20; //smg2
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfe;
- P3=0x10; //smg3
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfe;
- P3=0x08; //smg4
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfe;
- P3=0x40;
- Delay_ms(250);
- //---------"B"--------------p1.2
- P1=0xfb;
- P3=0x80;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfb;
- P3=0x20;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfb;
- P3=0x10;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfb;
- P3=0x08;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfb;
- P3=0x40;
- Delay_ms(250);
- //---------"C"--------------p1.4
- //P1=0x10;
- P1=0xef;
- P3=0x80;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xef;
- P3=0x20;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xef;
- P3=0x10;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xef;
- P3=0x08;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xef;
- P3=0x40;
- Delay_ms(250);
- //---------"D"--------------p1.6
- //-----p1.7 p1.6 p1.5 p1.4 p1.3 p1.2 p1.1 p1.0---//
- //-------1011 1111-------------------------------//
- P1=0xbf;
- P3=0x80;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xbf;
- P3=0x20;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xbf;
- P3=0x10;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xbf;
- P3=0x08;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xbf;
- P3=0x40;
- Delay_ms(250);
- //---------"E"--------------p1.7
- P1=0x7f;
- P3=0x80;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0x7f;
- P3=0x20;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0x7f;
- P3=0x10;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0x7f;
- P3=0x08;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0x7f;
- P3=0x40;
- Delay_ms(250);
- //---------"F"--------------p1.1
- P1=0xfd;
- P3=0x80;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfd;
- P3=0x20;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfd;
- P3=0x10;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfd;
- P3=0x08;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xfd;
- P3=0x40;
- Delay_ms(250);
- //---------"G"--------------p1.3
- P1=0xf7;
- P3=0x80;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xf7;
- P3=0x20;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xf7;
- P3=0x10;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xf7;
- P3=0x08;
- Delay_ms(5);
- P1=0xff;
- P3=0x00;
- P1=0xf7;
- P3=0x40;
- //------------------------------
- P1=0x00;
- P3=0xfc;
- Delay_ms(500);
- //------------------------------
- P1=0x00;
- P3=0x80;
- Delay_ms(100); //smg1
- P1=0x00;
- P3=0x20;
- Delay_ms(100); //smg2
- P1=0x00;
- P3=0x10;
- Delay_ms(100); //smg3
- P1=0x00;
- P3=0x08; //smg4
- Delay_ms(100);
- P1=0x00;
- P3=0xfc;
- Delay_ms(250);
- P1=0xff;
- P3=0x00;
- Delay_ms(250);
- P1=0x00;
- P3=0xfc;
- Delay_ms(250);
- }
- void main(void)
- {
- uint k;
- Buz();Display_Scan();
- T0_ini();
- while(1)
- {
- ///*/-------------按鍵小于2次有分鐘睡眠模式-----------------
- if(Hour==4)
- {
- EX0=1;
- EA=1;
- Key_flag=0;
- Min_1=0;
- Hour_1=0;
- Signle=1;
- TR0=1;
- P1=0xff;
- PCON=0x02;
- }
- ////--------------------------------------------------------- */
- if(Key_Select==0)
- {
- //for(LM_GroupCNT=0;LM_GroupCNT<13;LM_GroupCNT++)//拉幕時鐘時分秒顯示
- for(LM_GroupCNT=0;LM_GroupCNT<10;LM_GroupCNT++)
- {
- for(k=65500;k>0;k--)
- {
- CheckTime();
- }
- }
- }
- else
- Display();
- }
- }
復制代碼
|