资源描述:
《河南理工大学微机原理课设--遥控窗帘.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#defineuintunsignedint#defineucharunsignedcharsbitK1=P3^6;sbitK2=P3^7;sbitkey1=P0^5;sbitkey2=P0^6;sbitkey3=P0^7;//按键定义sbita=P2^0;//A数据接口sbitb=P2^1;//B数据接口sbitc=P2^2;//C数据接口sbitd=P2^3;//D数据接口sbitin1=P2^4;//sbitin2=P2^5;//sbiten=P2^6;//使能开关sbi
2、thuo1=P3^2;//霍尔传感器扫描接口sbithuo2=P3^3;sbitlight=P3^4;//光敏扫描口sbitD10=P2^7;sbitD12=P3^5;biti=0,j=0;intv=100,ms=0,mms=0,s,sec,n=0,m=0,k1=6,k2=12,minu,hour,in;ucharopen[]={0x54,0x7b,0x73,0x5c};//{0x5c,0x73,0x7b,0x54};ucharclose[]={0x6d,0x5c,0x30,0x58};//{0x58,0x30
3、,0x5c,0x6d};ucharstop[]={0x73,0x5c,0x78,0x6d};//{0x6d,0x78,0x5c,0x73};uchargood[]={0x5e,0x5c,0x5c,0x6f};//{0x6f,0x5c,0x5c,0x5e};uchartable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//字型码ucharq[]={0,0,0,0};ucharqq[]={0,0,0,0};ucharwei[]={0xf7,0xfb
4、,0xfd,0xfe};//位选码voiddelay(uintx)//延时子函数{uchary;for(;x!=0;x--){for(y=100;y!=0;y--){;}}}voiddisplay(uchar*pp,uchar*p)//显示函数{uchary;for(y=0;y<4;y++){P0=wei[y];P1=pp[p[y]];delay(25);}}voiddisplay1(uchar*p)//显示函数{uchary;for(y=0;y<4;y++){P0=wei[y];P1=p[y];delay(2
5、5);}}//对已经选择好的模式进行掉电储存/*********关闭IAP功能**********/voidcloseiap(){IAP_CONTR=0;IAP_CMD=0;IAP_TRIG=0;IAP_ADDRH=0x80;IAP_ADDRL=0x00;}/***********IAP读********************/unsignedcharreadiap(unsignedintadd){unsignedchardat;IAP_CONTR=0x83;//0x80:SYSCLK<30M,0x81:SY
6、SCLK<24M,0x82:SYSCLK<20M,0x83:SYSCLK<12MIAP_CMD=0x01;//0:无操作1:读,2:写,3:删除IAP_ADDRH=add>>8;IAP_ADDRL=add%256;IAP_TRIG=0x5a;IAP_TRIG=0xa5;//IAP命令生效delay(3);dat=IAP_DATA;closeiap();return(dat);}/*************IAP写******************/voidwriteiap(unsignedintadd,uns
7、ignedchardat){IAP_CONTR=0x82;IAP_CMD=0x02;IAP_ADDRH=add>>8;IAP_ADDRL=add%256;IAP_DATA=dat;IAP_TRIG=0x5a;IAP_TRIG=0xa5;//IAP命令生效delay(3);closeiap();}voiddeliap(unsignedintadd)//擦除扇区{IAP_CONTR=0x82;IAP_CMD=0x03;//0:无操作1:读,2:写,3:删除IAP_ADDRH=add>>8;IAP_ADDRL=add
8、%256;IAP_TRIG=0x5a;IAP_TRIG=0xa5;delay(3);closeiap();}voidpwm()//对电机进行调速{K1=0;K2=1;if(key2==0){delay(1000);v+=5;if(v>100)v=100;}if(key3==0){delay(1000);v-=5;if(v<0)v=0;}deliap(0x0200);writeiap(0