久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
STC11F02E單鍵控制的兩種模式選擇
[打印本頁]
作者:
liuda
時間:
2015-1-23 00:53
標題:
STC11F02E單鍵控制的兩種模式選擇
OMG! 今晚,出去買煙時,走著想著,構(gòu)思著,一個按鍵控制四個數(shù)碼管顯示;按第一下高位顯示1H并閃爍;按第二下低位顯2H并閃爍;
按第三下則把選擇后的狀態(tài)用拉幕的方式顯示出來;
PCB打了10個樣品收到了,今天組裝了并下載以前的程序個功能是好;現(xiàn)在程序改好了,空閑時下載到新的板子上,再調(diào)試調(diào)試,應(yīng)該是可以的;
好了,上代碼了!
//#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,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;
//uchar Display_number[]={0xd7,0x14,0xcd,0x5d,0x1e,0x5b,0xdb,0x15,0xdf,0x5f,0x00};
uchar code Display_number[]={0x28,0xeb,0x32,0xa2,0xe1,0xa4,0x24,0xea,0x20,0xa0,0xff,0xf7}; //0123456789 -
uchar code Display_string[]={0xff,0xff,0xff,0xf7,0xeb,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//0001HZ00000
uchar code Display_string2[]={0xff,0xff,0xff,0xf7,0x32,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//0002HZ00000;
uchar code Display_NUM[]={0,1,2,3,4,5,6,7,8,9,10,11};
uchar Clock[]={0xff,0xff,0xff,0xeb,0x32,0xf7,0xeb,0x32,0xf7,0xeb,0x32,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
//---------------------------------------------------
//---------------------------------------------------
//4COM 共陽數(shù)碼管 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 Clock_Prog();
void Clock_Prog_1();
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;
TF0=0;
Time_Count++;BTime_Count++;
BP_Count++;
if(BTime_Count==2000)
{
BT_Sec++;BTime_Flag=~BTime_Flag;
}
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)
{
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
//{
// Time_Count=0;
//BTime_Flag=~BTime_Flag;
//BT_Sec++;
// Dp=~Dp;
//BT_Sec_1++;
// Signle=~Signle;
/*/if(Key_flag==1)
{
BT_Sec=0;
if(BT_Sec_1==2)
{
BT_Sec_1=0;
Sec_1++;
if(Sec_1==60)
{
Sec_1=0;Min_1++;
}
if(Min_1==60)
{
Min_1=0;Hour_1++;
}
if(Hour_1==24)
{
Hour_1=0;
}
// Clock_Prog_1();
}
} */
// }
if(BT_Sec==2)
{
BT_Sec=0;
Sec++;
if(Sec==60)
{
Sec=0;Min++;
}
if(Min==60)
{
Min=0;Hour++;
}
if(Hour==24)
{
Hour=0;
}
//Clock_Prog();
}
}
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;
TR0=1;
Key_Select++;
if(Key_Select==3)
{
Key_Select=0;Key_flag=0;
}
// }
// if(Key_count>=20*50)
// {
// Key_count=500; // 設(shè)置長按快跳進度
// Key_long_flag=1;
// {
if(Key_Select==1)
{
Key_Select_Flag=0;
Key_Select_Flag=1;
// Min++; if(Min==60)Min=0;
}
if(Key_Select==2)
{
Key_Select_Flag=0;
Key_Select_Flag=2;
// Hour++; if(Hour==24)Hour=0;
}
// }
// }
}
}
else
{Key_count=0;Key_long_flag=0;Key_Select_Flag=0;}
}
void Clock_Prog()
{
//Clock[0]=Display_number[10];
//Clock[1]=Display_number[10];
Clock[3]=Display_number[Hour/10];
Clock[4]=Display_number[Hour%10];
Clock[5]=Display_number[11];//
Clock[6]=Display_number[Min/10];
Clock[7]=Display_number[Min%10];
Clock[8]=Display_number[11];//
Clock[9]=Display_number[Sec/10];
Clock[10]=Display_number[Sec%10];
//Clock[11]=Display_number[10];
//Clock[12]=Display_number[10];
//Clock[13]=Display_number[10];
//Clock[14]=Display_number[10];
}
void Clock_Prog_1()
{
//Clock[0]=Display_number[10];
//Clock[1]=Display_number[10];
Clock[3]=Display_number[Hour/10];
Clock[4]=Display_number[Hour%10];
Clock[5]=Display_number[11];//
Clock[6]=Display_number[Min_1/10];
Clock[7]=Display_number[Min_1%10];
Clock[8]=Display_number[11];//
Clock[9]=Display_number[Sec_1/10];
Clock[10]=Display_number[Sec_1%10];
//Clock[11]=Display_number[10];
//Clock[12]=Display_number[10];
//Clock[13]=Display_number[10];
//Clock[14]=Display_number[10];
}
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 第四個數(shù)碼管
case 2:SMG3=1;LM_Count++;break; //SMG排列 1 2 3 4 第三個數(shù)碼管
case 3:SMG2=1;LM_Count++;break; //SMG排列 1 2 3 4 第二個數(shù)碼管
case 4:SMG1=1;LM_Count++;break; //SMG排列 1 2 3 4 第一個數(shù)碼管
default:break;
}
//P1=Display_number[Clock[number]];
//P1=Display_string[number];
if(Key_Select==0||Key_Select_Flag==1)
{
P1=Display_string[number];
}
if(Key_Select_Flag==2)
{
P1=Display_string2[number];
}
//P1=Clock[number];
}
void CheckTime()
{
if(Led_Scan)
{
switch(Led_Loop)
{
case 0:SmgDisp(4,LM_Count+LM_GroupCNT);break; //第一個數(shù)碼管
case 1:SmgDisp(3,LM_Count+LM_GroupCNT);break; //第二個數(shù)碼管
case 2:SmgDisp(2,LM_Count+LM_GroupCNT);break; //第三個數(shù)碼管
case 3:SmgDisp(1,LM_Count+LM_GroupCNT);break; //第四個數(shù)碼管
}
Led_Scan=0;
}
}
void Display(void)
{
if(BTime_Flag&(Key_Select==2)&(Key_long_flag==0))
{
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_number[Hour/10];
P1=Display_string[4];
SMG1=1; //P3=0x80;
Delay_ms(1);
SMG1=0; //P3=0x00;
P1=0xff;
//P1=Display_number[Hour%10];
P1=Display_string[5];
SMG2=1; //P3=0x20;
Delay_ms(1);
SMG2=0; //P3=0x00;
P1=0xff;
}
if(BTime_Flag&(Key_Select==1)&(Key_long_flag==0))
{
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_number[Min/10];
P1=Display_string2[4];
SMG3=1; //P3=0x10;
Delay_ms(1);
SMG3=0; //P3=0x00;
P1=0xff;
//=Display_number[Min%10];
P=Display_string2[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=0x01;
P1=0xfe;
P3=0x80; //smg1
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfe;
P3=0x20; //smg2
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfe;
P3=0x10; //smg3
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfe;
P3=0x08; //smg4
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfe;
Delay_ms(100);
//---------"B"--------------
P1=0xfb;
P3=0x80;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfb;
P3=0x20;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfb;
P3=0x10;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfb;
P3=0x08;
Delay_ms(1);
P1=0xfb;
P1=0xff;
P3=0x00;
Delay_ms(100);
//---------"C"--------------
//P1=0x10;
P1=0xef;
P3=0x80;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xef;
P3=0x20;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xef;
P3=0x10;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xef;
P3=0x08;
Delay_ms(1);
P1=0xef;
P1=0xff;
P3=0x00;
Delay_ms(100);
//---------"D"--------------
P1=0xcf;
P3=0x80;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xcf;
P3=0x20;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xcf;
P3=0x10;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xcf;
P3=0x08;
Delay_ms(1);
P1=0xff;
P3=0x00;
Delay_ms(100);
//---------"E"--------------
P1=0x7f;
P3=0x80;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0x7f;
P3=0x20;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0x7f;
P3=0x10;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0x7f;
P3=0x08;
Delay_ms(1);
P1=0xff;
P3=0x00;
Delay_ms(100);
//---------"F"--------------
P1=0xfd;
P3=0x80;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfd;
P3=0x20;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfd;
P3=0x10;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xfd;
P3=0x08;
Delay_ms(1);
P1=0xff;
P3=0x00;
Delay_ms(100);
//---------"G"--------------
P1=0xf7;
P3=0x80;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xf7;
P3=0x20;
Delay_ms(1);
P1=0xff;
P3=0x00;
P1=0xf7;
P3=0x10;
Delay_ms(1);
P1=0xf7;
P3=0x08;
P1=0xff;
P3=0x00;
Delay_ms(1);
P1=0x00;
P3=0xfc;
Delay_ms(100);
//------------------------------
P1=0xff;
P3=0x00;
Delay_ms(200);
P1=0x00;
P3=0xfc;
Delay_ms(200);
//------------------------------
P1=0x00;
P3=0x80;
Delay_ms(30); //smg1
P1=0x00;
P3=0x20;
Delay_ms(30); //smg2
P1=0x00;
P3=0x10;
Delay_ms(30); //smg3
P1=0x00;
P3=0x08; //smg4
Delay_ms(30);
P1=0x00;
P3=0xfc;
Delay_ms(200);
P1=0xff;
P3=0x00;
Delay_ms(200);
P1=0x00;
P3=0xfc;
Delay_ms(200);
}
void main(void)
{
uint k;
Buz();Display_Scan();
T0_ini();Clock_Prog();
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;
}
////--------------------------------------------------------- */
//Clock_Prog();
if(Sec%5==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();
}
}
復(fù)制代碼
歡迎光臨 (http://m.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
欧美在线中文字幕
|
国产一区二区中文字幕
|
亚洲香蕉视频
|
亚洲午夜久久久
|
宅男噜噜噜66一区二区
|
高潮一区二区三区乱码
|
97在线免费视频
|
国产精品永久久久久久久久久
|
99re视频在线
|
黄视频免费观看
|
欧美日韩一二区
|
日韩精品久久久久久久
|
午夜免费观看视频
|
欧美一级色
|
国内精品在线播放
|
91国在线
|
人体free性hd
|
黄色小视频免费观看
|
午夜黄视频
|
中文字幕1区
|
久久夜色精品
|
日韩在线视频免费观看
|
久久亚洲国产
|
免费看大片a
|
国产视频一区在线观看
|
激情久久综合
|
欧美视频一二三区
|
夜夜夜夜操
|
精品毛片一区二区三区
|
在线伊人
|
亚洲精品乱码久久久久久蜜桃91
|
欧美成人三级
|
欧美三级三级三级爽爽爽
|
精品国产久
|
亚洲成肉网
|
成人免费毛片入口
|
欧美激情国产精品
|
国产视频999
|
91精品国产成人观看
|
免费不卡视频
|
中文在线观看免费视频
|