资源描述:
《河南理工大学微机原理课设--时钟》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include"stc10.h"#defineucharunsignedchar#defineuintunsignedintsbitD1=P2^0;sbitD2=P2^1;sbitD3=P2^2;sbitD4=P2^3;sbitP0_5=P0^5;sbitP0_6=P0^6;sbitP0_7=P0^7;sbitP3_6=P3^6;sbitP3_7=P3^7;unsignedcharDSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};uchartime
2、[]={0,0,0,0};ucharflag=0,flag1,flag2=0,num1,baojing=0;charfen,scend=0,fen1=0,scend1=0,shi=1,shi1;voiddelay(ucharmm){while(mm--);}voiddelay2(unsignedintcnt){unsignedchari;for(;cnt>0;cnt--)for(i=0;i<250;i++);}/*********关闭IAP功能**********/voidcloseiap(){IAP_CONTR=0;IAP_CMD=
3、0;IAP_TRIG=0;IAP_ADDRH=0x80;IAP_ADDRL=0x00;}/***********IAP读********************/unsignedcharreadiap(unsignedintadd){unsignedchardat;IAP_CONTR=0x82;//0x80:SYSCLK<30M,0x81:SYSCLK<24M,0x82:SYSCLK<20M,0x83:SYSCLK<12MIAP_CMD=0x01;//0:无操作1:读,2:写,3:删除IAP_ADDRH=add>>8;IAP_ADDR
4、L=add%256;IAP_TRIG=0x5a;IAP_TRIG=0xa5;//IAP命令生效delay2(1);dat=IAP_DATA;closeiap();return(dat);}/*************IAP写******************/voidwriteiap(unsignedintadd,unsignedchardat){IAP_CONTR=0x82;IAP_CMD=0x02;IAP_ADDRH=add>>8;IAP_ADDRL=add%256;IAP_DATA=dat;IAP_TRIG=0x5a;IAP_
5、TRIG=0xa5;//IAP命令生效delay2(1);closeiap();}voiddeliap(unsignedintadd)//擦除扇区{IAP_CONTR=0x82;IAP_CMD=0x03;//0:无操作1:读,2:写,3:删除IAP_ADDRH=add>>8;IAP_ADDRL=add%256;IAP_TRIG=0x5a;IAP_TRIG=0xa5;delay2(1);closeiap();}voiddisplay(){uchari;for(i=0;i<4;i++){P0=~(1<
6、g1==0&&i==3&&(scend%2==0))P1=(DSY_CODE[time[3]]+0x80);elseP1=DSY_CODE[time[i]];delay(30);P1=0x00;}}voidkeyscan(void){P0
7、=0xe0;P3_6=0;P3_7=1;if(P0_5==0){delay(3);if(P0_5==0){flag++;while(!P0_5);}}if(P0_6==0){delay(3);if(P0_6==0){if(flag==1)shi++;if(flag==3)shi1++;deliap(
8、0x0000);writeiap(0x0000,shi);deliap(0x0200);writeiap(0x0200,shi1);while(!P0_6);}}if(P0_7==0){delay(3);if(P0_7==0){if(flag==1)shi--;if(flag==3)shi1--;if(flag==0)flag2++;deliap(0x0000);writeiap(0x0000,shi);deliap(0x0200);writeiap(0x0200,shi1);while(!P0_7);}}P0
9、=0xef;P3_7=
10、0;P3_6=1;if(P0_5==0){delay(3);if(P0_5==0){flag1++;while(!P0_5);}}if(P0_6==0){delay(3);if(P0_6==0){if(flag==1)f