电子万年历的设计毕业论文 下载本文

湖北文理学院理工学院 附录1:程序

CE = 1; //发送地址

for ( i=8; i>0; i-- ) //循环8次移位 {

SCLK = 0; temp = addr;

DIO = (bit)(temp&0x01); //每次传输低字节 addr >>= 1; //右移一位 SCLK = 1; }

//读取数据

for ( i=8; i>0; i-- ) {

ACC_7=DIO; SCLK = 1; ACC>>=1; SCLK = 0; } CE=0; dat1=ACC;

dat2=dat1/16; //数据进制转换 //十六进制转十进制 dat1=dat1; dat1=dat1+dat2*10; return (dat1); }

//初始化 DS1302

void Initial(void) //初始化1302 2010年09月30日23点58分56秒 星期一

{

湖北文理学院理工学院 附录1:程序

write_1302 (0x8e,0x00); //允许写保护 write_1302 (0x80,0x56);

//秒位初始化

write_1302 (0x82,0x58); //分钟初始化 write_1302 (0x84,0x23); //小时初始化 write_1302 (0x86,0x30); //日初始化

write_1302 (0x88,0x09); //月初始化 write_1302 (0x8c,0x10); //年初始化 write_1302 (0x8a,0x01); //日期始化 write_1302 (0x8e,0x80); //禁止写保护

}

void di()//蜂鸣器响函数 {

beep=0; delay(100); beep=1; }

void write_sfm(uchar add,uchar date) {

uchar shi,ge; shi=date/10; ge=date;

write_com(0x80+0x40+add); write_data(0x30+shi); write_data(0x30+ge); }

void write_nyrz(uchar add,uchar date)//显示年,月,日,周{

uchar shi,ge; shi=date/10; ge=date;

湖北文理学院理工学院 附录1:程序

write_com(0x80+add); write_data(0x30+shi); write_data(0x30+ge); }

void display_week(uchar we) {

write_com(0x80+12); switch(we) {

case 1: write_data('M');delay(5);

write_data('O');delay(5); write_data('N'); break;

case 2: write_data('T');delay(5);

write_data('U');delay(5); write_data('E'); break;

case 3: write_data('W');delay(5);

write_data('E');delay(5); write_data('D'); break;

case 4: write_data('T');delay(5);

write_data('H');delay(5); write_data('U'); break;

case 5: write_data('F');delay(5);

write_data('R');delay(5); write_data('T'); break;

case 6: write_data('S');delay(5);

湖北文理学院理工学院 附录1:程序

write_data('A');delay(5); write_data('T'); break;

case 7: write_data('S');delay(5);

write_data('U');delay(5); write_data('N'); break;

} }

void keyscan()//按键设置 {

if(key3==0)//功能键按下 {

flag=0; delay(5); if(key3==0) {

s1num++; while(!key3); di();

switch(s1num)//光标闪烁定位 {

case 1:write_com(0x80+0x40+7);//定位到秒的位置

write_com(0x0f); tempchange();

for(i=10;i>0;i--) { } break;

dis_temp(get_temp());