第一步:嘻嘻,申请完成期待中... ...
2011-11-08
****************************************
第二步:嘻嘻,已经在申请通过的名单中了... ...
2011-11-14
****************************************
第三步:收到板了... ...
来张快递单的靓照
看了看,板布的感觉有点粗糙哦,哈哈。。。。。。
来张我自己画过的图显摆一下
2011-11-27
****************************************
第四步:购买器件,遇到麻烦了... ...向下看,问题完美解决,同样适用于你... ...
来张装了部分器件的板、
现我把器件购买的淘宝连接也在本贴中贡献出来:
http://item.taobao.com/item.htm?spm=1103t4_c.3-AWc4.h-9Ax08&id=13591655754
2011-11-30
****************************************************
第五步:已经完成器件的焊接... ...
2011-12-05
**********************************************************
每六步:代码视频并发... ...
原代码:
#include "intrins.h"
#include "STC_NEW_8051.h"
#define uchar unsigned char
#define uint unsigned int
sbit LED2=P1^0;
sbit LED3=P1^1;
sbit LED4=P1^2;
sbit LED5=P1^3;
sbit LED6=P1^4;
sbit LED7=P1^5;
sbit LED8=P1^6;
sbit LED9=P1^7;
uchar LED_temp; //LED的初始状态
uchar LED_stu; //LED灯显示的状态
uchar LED_stu_1; //
uchar move_times; //移动的次数
uchar move_stu; //移动的状态
uint time_1S; //1S定时器计数器
uchar LED_i;
#define OscFreq 12000000
#define Timer0Cycle 1
#define Timer0_REG ( -1*( Timer0Cycle * (OscFreq/12)/1000) )//1Ms (1/(oSc(单位为Mz)/12))*n=T(单位为S)
#define LOW_BYTE( word ) ( ( unsigned char ) ( word ) )
#define HIGH_BYTE( word ) ( ( uchar ) ( ( word ) >> 8 ) )
//系统时钟初始化
void init_osc(void)
{
CLK_DIV = 0x00; //不分频
AUXR = 0x00; //特殊功能寄存器,12T
}
//IO口初始化
void init_IO(void)
{
P0M0 = 0xFF; //输出
P0M1 = 0x00;
P0=0;
P1M0 = 0xFF; //输出
P1M1 = 0x00;
P2M0 = 0x00; //输出 //P2.7-P2.0INPUT
P2M1 = 0xff;
P2=0;
P3M0 = 0xFF; //输出
P3M1 = 0x00;
P3=0;
}
//定时器初始化
void init_time0(void)
{
TMOD = 0x11; //T0 mode1 T1 mode1
TH0 = HIGH_BYTE(Timer0_REG);
TL0 = LOW_BYTE(Timer0_REG);
ET0 = 1; //enable TO int
}
//总的初始化
void init(void)
{
init_osc();
init_IO();
init_time0();
LED_temp=0x0FE;
move_times = 8;
}
//流水灯显示
void led_display(void)
{
if(time_1S >= 250)
{
time_1S = 0;
if(LED_stu == 0)
{
P1 = LED_temp;
LED_temp=_crol_(LED_temp,1);
if(LED_temp == 0x7F)
{
LED_stu = 1;
}
}
else if(LED_stu == 1)
{
P1 = LED_temp;
LED_temp=_cror_(LED_temp,1);
if(LED_temp == 0x0FE)
{
LED_stu = 2;
}
}
else if(LED_stu == 2)
{
P1 = LED_temp;
LED_temp=_crol_(LED_temp,1);
LED_temp--;
if(LED_temp == 0)
{
LED_stu = 3;
}
}
else if(LED_stu == 3)
{
P1 = LED_temp;
LED_temp++;
LED_temp=_cror_(LED_temp,1);
if(LED_temp == 0xFF)
{
LED_stu = 4;
}
}
else if(LED_stu == 4)
{
P1 = LED_temp;
LED_temp = LED_temp>>1;
if(LED_temp == 0)
{
LED_stu = 5;
}
}
else if(LED_stu == 5)
{
P1 = LED_temp;
LED_temp=_crol_(LED_temp,1);
LED_temp++;
if(LED_temp == 0xFF)
{
LED_stu = 6;
}
}
else if(LED_stu == 6)
{
if((LED_temp == 0x7F)||(LED_temp == 0x3F)||(LED_temp == 0x1F)||(LED_temp == 0x0F)
||(LED_temp == 0x07)||(LED_temp == 0x03)||(LED_temp == 0x01)||(LED_temp == 0x00))
{
LED_stu_1++;
}
P1 = LED_temp;
if(LED_stu_1==1)
{
LED_temp |=~0x7F;
}
else if(LED_stu_1==2)
{
LED_temp |=~0x3F;
}
else if(LED_stu_1==3)
{
LED_temp |=~0x1F;
}
else if(LED_stu_1==4)
{
LED_temp |=~0x0F;
}
else if(LED_stu_1==5)
{
LED_temp |=~0x07;
}
else if(LED_stu_1==6)
{
LED_temp |=~0x03;
}
else if(LED_stu_1==7)
{
LED_temp |=~0x01;
}
LED_temp=_crol_(LED_temp,1);
if(LED_temp==0xFF)
LED_temp=0xFE;
if(LED_stu_1==1)
{
LED_temp &=0x7F;
}
else if(LED_stu_1==2)
{
LED_temp &=0x3F;
}
else if(LED_stu_1==3)
{
LED_temp &=0x1F;
}
else if(LED_stu_1==4)
{
LED_temp &=0x0F;
}
else if(LED_stu_1==5)
{
LED_temp &=0x07;
}
else if(LED_stu_1==6)
{
LED_temp &=0x03;
}
else if(LED_stu_1==7)
{
LED_temp &=0x01;
}
if(LED_temp == 0)
{
LED_stu = 7;
LED_stu_1 = 0;
}
}
else if(LED_stu == 7)
{
if((LED_temp == 0x01)||(LED_temp == 0x03)||(LED_temp == 0x07)||(LED_temp == 0x0F)
||(LED_temp == 0x1F)||(LED_temp == 0x3F)||(LED_temp == 0x7F)||(LED_temp == 0xFF))
{
LED_stu_1++;
}
P1 = LED_temp;
if(LED_stu_1==1)
{
LED_temp &=~0x01;
}
else if(LED_stu_1==2)
{
LED_temp &=~0x03;
}
else if(LED_stu_1==3)
{
LED_temp &=~0x07;
}
else if(LED_stu_1==4)
{
LED_temp &=~0x0F;
}
else if(LED_stu_1==5)
{
LED_temp &=~0x1F;
}
else if(LED_stu_1==6)
{
LED_temp &=~0x3F;
}
else if(LED_stu_1==7)
{
LED_temp &=~0x7F;
}
LED_temp=_cror_(LED_temp,1);
if(LED_temp==0x00)
LED_temp=0x80;
if(LED_stu_1==1)
{
LED_temp |=0x01;
}
else if(LED_stu_1==2)
{
LED_temp |=0x03;
}
else if(LED_stu_1==3)
{
LED_temp |=0x07;
}
else if(LED_stu_1==4)
{
LED_temp |=0x0F;
}
else if(LED_stu_1==5)
{
LED_temp |=0x1F;
}
else if(LED_stu_1==6)
{
LED_temp |=0x3F;
}
else if(LED_stu_1==7)
{
LED_temp |=0x7F;
}
if(LED_temp == 0xFF)
{
LED_stu = 8;
LED_stu_1 = 0;
}
}
else if(LED_stu == 8)
{
P1 = LED_temp;
LED_stu = 0;
LED_temp= 0xFE;
}
}
}
//主函数
void main(void)
{
init();
TR0 = 1;
EA = 1;
time_1S = 0;
while(1)
{
led_display();
}
}
//time0定时器
void timer0() interrupt 1 using 1//1Ms
{
TH0 = HIGH_BYTE(Timer0_REG);
TL0 = LOW_BYTE(Timer0_REG);
time_1S++;
}
--------------------------------------------
视频如下:
流水灯:
时钟显示:
#include "intrins.h"
#include "STC_NEW_8051.h"
#define uchar unsigned char
#define uint unsigned int
#define long_T 2000
#define Buzz_T 500
sbit BUZZ =P1^0;
//DS1302
sbit SDA_1302=P3^4;
sbit RST_1302=P3^5;
sbit SCL_1302=P3^6;
uchar NUM; //数值
uchar com; //位选
uint time_1S; //1S定时器计数器
uchar flash_T; //时钟延时刷新
uchar key_code; //按键值
uchar pre_key_code; //前次按键值
uchar key_delay; //按键延时抖
uchar key_scan_T; //按键扫描间隔时间
uint flash; //闪烁显示时间0.5秒亮、0.5秒灭
uchar set_time_stu; //时钟设定状态
bit FLAG=0; //时钟设置标志位
uchar set_delay; //设定状态延时
uint long_key_T; //长键设定时间
uchar Buzz_time; //蜂鸣器响的时间
//1302
void Write_Data(uchar addr,uchar dat);
uchar Read_Data(uchar addr);
//KEY
void scan_key(void);
#define OscFreq 12000000
#define Timer0Cycle 1
#define Timer0_REG ( -1*( Timer0Cycle * (OscFreq/12)/1000) )//1Ms (1/(oSc(单位为Mz)/12))*n=T(单位为S)
#define LOW_BYTE( word ) ( ( unsigned char ) ( word ) )
#define HIGH_BYTE( word ) ( ( uchar ) ( ( word ) >> 8 ) )
const uchar SEG[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x40,0x80,0x00};//0,1,2,3,4,5,6,7,8,9,.,-, ,
//定义设置的时间:秒、分、时、日、月、星期、年
uchar time_date[7]={00,00,12,22,8,1,11};//2011年8月22日,星期1,12点00分00秒
//定义读取时间和日期存放表格10进制
uchar read_time_date[7];
//系统时钟初始化
void init_osc(void)
{
CLK_DIV = 0x00; //不分频
AUXR = 0x00; //特殊功能寄存器,12T
}
//IO口初始化
void init_IO(void)
{
P0M0 = 0xFF; //输出
P0M1 = 0x00;
P0=0;
P1M0 = 0xFF; //输出
P1M1 = 0x00;
P1=0xFF;
P2M0 = 0xFF; //输出
P2M1 = 0x00;
P2=0;
P3M0 = 0xF0; //P4-P7输出,P0-P3为准双向口
P3M1 = 0x00;
P3=0x0F;
}
//初始化1302
void init_DS1302(void)
{
uchar i,j,addr = 0x80;
for(i=0;i<7;i++)
{
j=time_date[i]/10;
time_date[i]=time_date[i]%10;
time_date[i]=time_date[i]+j*16;
}
time_date[0]&=0xEF;
Write_Data(0x8e,0x00); //去除写保护
for(i=0;i<7;i++)
{
Write_Data(addr,time_date[i]); //1302写入数据,秒数据中的CH位为0才能开1302晶振
addr+=2;
}
Write_Data(0x8e,0x80); //使能写保护
}
//定时器初始化
void init_time0(void)
{
TMOD = 0x11; //T0 mode1 T1 mode1
TH0 = HIGH_BYTE(Timer0_REG);
TL0 = LOW_BYTE(Timer0_REG);
ET0 = 1; //enable TO int
}
//总的初始化
void init(void)
{
init_osc();
init_IO();
init_time0();
TR0 = 1;
EA = 1;
time_1S = 0;
FLAG=0;
}
//***********************************************************************
//DS1302设置时间函数
//写入数据程序
void Write_Data(uchar addr,uchar dat)
{
uchar i;
P3M0 |= 0x70; //输出
P3M1 &= 0x8F;
RST_1302=0;
SCL_1302=0;
RST_1302=1;
//发送命令字
for(i=8;i>0;i--)
{
SCL_1302=0;
if(addr&0x01)
SDA_1302=1;
else
SDA_1302=0;
SCL_1302=1;
addr>>=1;
}
//在要发送数组中,取1字节数据
for(i=8;i>0;i--)
{
SCL_1302=0;
if(dat&0x01)
SDA_1302=1;
else
SDA_1302=0;
SCL_1302=1;
dat>>=1;
}
SCL_1302=0;
}
//读出数据程序
uchar Read_Data(uchar addr)
{
uchar i,dat_buf=0x00;
P3M0 |= 0x70; //输出
P3M1 &= 0x8F;
RST_1302=0;
SCL_1302=0;
RST_1302=1;
//发送要读的地址
for(i=8;i>0;i--)
{
SCL_1302=0;
if(addr&0x01)
SDA_1302=1;
else
SDA_1302=0;
SCL_1302=1;
addr>>=1;
}
//读出数据
P3M0 &= 0xEF; //输入
P3M1 |= 0x10;
for(i=0;i<8;i++)
{
SCL_1302=1;
SCL_1302=0;
if(SDA_1302==1)
dat_buf|=(1<<i);
}
RST_1302=0;
return (dat_buf/16*10+dat_buf%16);
}
//1302取时间数据
void GetTime()
{
uchar i,addr = 0x81;
if(FLAG==0)//非设定状态下读1302
{
for(i=0;i<7;i++)
{
read_time_date[i]=Read_Data(addr);
addr+=2;
}
time_date[0]=read_time_date[0];
time_date[1]=read_time_date[1];
time_date[2]=read_time_date[2];
time_date[3]=read_time_date[3];
time_date[4]=read_time_date[4];
time_date[5]=read_time_date[5];
time_date[6]=read_time_date[6];
}
}
//***********************************************************************
//数码管显示
void display(void)
{
P0=0;//数码管不显示
P2= com;
switch(com)
{
case 0:
if(((flash>500)&&(set_time_stu == 1))||(set_time_stu != 1))
{
P0=SEG[read_time_date[2]/10];
}
else
{
P0=SEG[12];
if(flash==0)
flash=1000;
}
break;
case 1:
if(((flash>500)&&(set_time_stu == 1))||(set_time_stu != 1))
{
P0=SEG[read_time_date[2]%10];
}
else
{
P0=SEG[12];
if(flash==0)
flash=1000;
}
break;
case 2:
P0=SEG[10]; //显示-
break;
case 3:
if(((flash>500)&&(set_time_stu == 2))||(set_time_stu != 2))
{
P0=SEG[read_time_date[1]/10];
}
else
{
P0=SEG[12];
if(flash==0)
flash=1000;
}
break;
case 4:
if(((flash>500)&&(set_time_stu == 2))||(set_time_stu != 2))
{
P0=SEG[read_time_date[1]%10];
}
else
{
P0=SEG[12];
if(flash==0)
flash=1000;
}
break;
case 5:
P0=SEG[10]; //显示-
break;
case 6:
if(((flash>500)&&(set_time_stu == 3))||(set_time_stu != 3))
{
P0=SEG[read_time_date[0]/10];
}
else
{
P0=SEG[12];
if(flash==0)
flash=1000;
}
break;
case 7:
if(((flash>500)&&(set_time_stu == 3))||(set_time_stu != 3))
{
P0=SEG[read_time_date[0]%10];
}
else
{
P0=SEG[12];
if(flash==0)
flash=1000;
}
break;
default:
break;
}
}
//***********************************************************************
//按键扫描
void scan_key(void)
{
uchar temp;
if(key_scan_T > 10)
{
key_scan_T=0;
if((P3&0x01)==0)
temp=1;//上升键
else if((P3&0x02)==0)
temp=2;//下降键
else if((P3&0x04)==0)
temp=3;//右移键
else if((P3&0x08)==0)
temp=4;//设定键
else
temp=0;
if(pre_key_code != temp)
{
pre_key_code = temp;
key_delay = 2;
}
else
{
if(key_delay != 0)
{
key_delay--;
if(key_delay == 0)
{
key_code = pre_key_code;
}
}
}
}
}
//扫键处理程序
void key_fun(void)
{
switch(key_code)
{
case 1:
if(set_time_stu==1) //调时
{
read_time_date[2]++;
if(read_time_date[2]>23)
read_time_date[2]=0;
time_date[2]= read_time_date[2];
}
else if(set_time_stu==2)//调分
{
read_time_date[1]++;
if(read_time_date[1]>59)
read_time_date[1]=0;
time_date[1]= read_time_date[1];
}
else if(set_time_stu==3)//调秒
{
read_time_date[0]++;
if(read_time_date[0]>59)
read_time_date[0]=0;
time_date[0]= read_time_date[0];
}
Buzz_time = Buzz_T;
key_code=0;
break;
case 2:
if(set_time_stu==1) //调时
{
if(read_time_date[2]>0)
read_time_date[2]--;
else
read_time_date[2]=23;
time_date[2]= read_time_date[2];
}
else if(set_time_stu==2)//调分
{
if(read_time_date[1]>0)
read_time_date[1]--;
else
read_time_date[1]=59;
time_date[1]= read_time_date[1];
}
else if(set_time_stu==3)//调秒
{
if(read_time_date[0]>0)
read_time_date[0]--;
else
read_time_date[0]=59;
time_date[0]= read_time_date[0];
}
Buzz_time = Buzz_T;
key_code=0;
break;
case 3:
if(FLAG==1)
{
if(set_time_stu<3)
set_time_stu++;
else
set_time_stu=1;
}
Buzz_time = Buzz_T;
key_code=0;
break;
case 4:
if(FLAG==0)
{
FLAG=1;
set_time_stu = 1;
flash=1000;
}
else
{
FLAG=0;
set_time_stu = 0;
flash=1000;
init_DS1302();
}
Buzz_time = Buzz_T;
key_code=0;
break;
default:
key_code=0;
break;
}
if(long_key_T>long_T)
{
if(pre_key_code==1)
{
long_key_T=1500;
flash=1100;
if(set_time_stu==1) //调时
{
read_time_date[2]++;
if(read_time_date[2]>23)
read_time_date[2]=0;
time_date[2]= read_time_date[2];
}
else if(set_time_stu==2)//调分
{
read_time_date[1]++;
if(read_time_date[1]>59)
read_time_date[1]=0;
time_date[1]= read_time_date[1];
}
else if(set_time_stu==3)//调秒
{
read_time_date[0]++;
if(read_time_date[0]>59)
read_time_date[0]=0;
time_date[0]= read_time_date[0];
}
}
else if(pre_key_code==2)
{
long_key_T=1500;
flash=1100;
if(set_time_stu==1) //调时
{
if(read_time_date[2]>0)
read_time_date[2]--;
else
read_time_date[2]=23;
time_date[2]= read_time_date[2];
}
else if(set_time_stu==2)//调分
{
if(read_time_date[1]>0)
read_time_date[1]--;
else
read_time_date[1]=59;
time_date[1]= read_time_date[1];
}
else if(set_time_stu==3)//调秒
{
if(read_time_date[0]>0)
read_time_date[0]--;
else
read_time_date[0]=59;
time_date[0]= read_time_date[0];
}
}
}
}
//主函数
void main(void)
{
init();
GetTime();//取出1302内的数据
if((read_time_date[0]==80)&&(read_time_date[1]==0)&&(read_time_date[2]==0))//取出的数据全为0时,初始化
init_DS1302();
while(1)
{
GetTime();
scan_key();
key_fun();
}
}
//time0定时器
void timer0() interrupt 1 using 1//1Ms
{
TH0 = HIGH_BYTE(Timer0_REG);
TL0 = LOW_BYTE(Timer0_REG);
//time_1S++;
key_scan_T++;
if(flash!=0)
flash--;
if(((pre_key_code==1)||(pre_key_code==2))&&(key_code==0)&&(key_delay==0)&&(FLAG==1))
long_key_T++;
if(Buzz_time != 0)
{
Buzz_time--;
BUZZ=!BUZZ;
}
com++;
if(com>7)
com=0;
display();
}
2011-12-22