ghdhair100
Dołączył: 15 Gru 2010
Posty: 1990
Przeczytał: 0 tematów
Ostrzeżeń: 0/5 Skąd: England
|
Wysłany: Czw 3:34, 03 Mar 2011 Temat postu: 最近做的X光 |
|
|
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit LE1=P2^0;
sbit LE2=P2^1;
sbit wei1=P2^2;
sbit wei2=P2^3;
sbit key_start=P1^0;
sbit key_enter=P1^1;
sbit key_up=P1^2;
sbit key_down=P1^3;
sbit LED_start=P2^4;
sbit LED_enter=P2^5;
sbit beef=P2^6;
bit TR_value,LED_value,t1,t2,t3;
uchar shi,ge,sec;
uint time,key_delay;
uchar code LED_tab[]=
{ //7段共阳数码管段码表
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,
0xc0&0x7f, //带小数点
0xf9&0x7f,
0xa4&0x7f,
0xb0&0x7f,
0x99&0x7f,
0x92&0x7f,
0x82&0x7f,
0xf8&0x7f,
0x80&0x7f,
0x90&0x7f
};
void delay(uint z) //延时1ms子函数
{
uint i,j;
for(i=z;i>0;i--)
for(j=125;j>0;j--);
}
void display(uchar shi,uchar ge) //数码管显示子函数
{
wei1=1;
P0=LED_tab[shi+10];
delay(5);
wei1=0;
wei2=1;
P0=LED_tab[ge];
delay(5);
wei2=0;
}
void scan_key(void) //按键检测子程序
{
if(key_enter==0) //enter键(确认键)按下
{
{
t3=~t3;
if(t3==0)
t2=0;
else
t2=1;
while(!key_enter) //松手检测
display(shi,ge);
}
LED_enter=t2;
}
else if(LED_enter==0) //设定模式中
{
if(key_up==0) //up键按下
{
{
while(!key_up)
display(shi,ge);
}
time++;
if(time==99)
time=1;
}
if(key_down==0) //down键按下
{
{
while(!key_down)
display(shi,ge);
}
time--;
if(time==0)
time=99;
}
}
else if(LED_enter!=0) //如果已经退出设定模式
{
if((t1|key_start)==0) //如果start(曝光开关)键按下
{
while(key_delay) //延时0.5秒
{
key_delay--;
display(shi,ge);
}
if((t1|key_start)==0) //start键按下够0.5秒
{
t1=~t1; //该句作用是:曝光过程中再按曝光键无效
TR_value=1;
LED_value=0;
while(!key_start) //松手检测
display(shi,ge);
}
}
TR0=TR_value; //开定时器
LED_start=LED_value; //曝光过程中LED灯亮提示
}
}
void initial(void) //初始化函数
{
P2=0xff;
key_delay=50;
//曝光完成显示0.0 (1秒)
LE1=1;
LE2=1; //这个地方以后要改变(只用一个74HC573)
wei1=wei2=1; //
P0=0xc0; //
LE1=0; //
LE2=0;
//蜂鸣器响1秒
beef=0;
delay(1000);
beef=1;
LE1=LE2=1; //P1送“1”
P1=0xff; //time赋初值,初始化显示数据3.0(以后改为读外部RAM)
time=30;
//定时器初始化
TMOD=0x01;
TH0=(65536-50000)/256; //定时50ms
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR_value=0;
LED_value=1;
t1=0;
t2=1;
t3=1;
sec=0;
display(shi,ge); //数码管显示初始化
}
void main() //主函数
{
loop:
initial(); //初始化函数声明
while(1)
{
scan_key(); //按键检测
shi=time/10;
ge=time%10;
if(time==0)
{
TR0=0;
LED_start=1;
goto loop; //曝光完成,系统复位
}
display(shi,ge); //调用数码管显示函数
}
}
void intr0() interrupt 1 //定时器中断处理函数
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
sec++; //0.1秒
if(sec==2)
{
sec=0;
time--; //time自减
}
}
/****************************************/
/***************未完待续*****************/
/****************************************/
/*
/*原理图不是我做的,所以无法献上,敬请原谅。
*/Many years ago there lived an Emperor who was so exceedingly fond of fine new clothes that he spent vast sums of money on dress. To him clothes meant more than anything else in the world. He took no interes
related links:
[link widoczny dla zalogowanych]
Post został pochwalony 0 razy
|
|