资源描述:
《EEPRO使用多个扇区》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/**存贮多个变量两个long型和一个char型(long型的转换成4个char型)用两个不同的按键控制显示存贮的值***/#include#includetypedefunsignedcharuchar;typedefunsignedintuint;typedefunsignedlongulong;#defineled_portP0sbitdm=P2^3;//数码管控制芯片段码控制位sbitwm=P2^2;//数码管控制芯片位码控制位sbitgn=P2^0;sbitgn1=P2^1;ulonga,a1,v
2、,v1;//uchara;uchartemp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8;bitbz1,bz2;ucharcodedxian[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//数码显示区0--9ucharcodewxian[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//选通哪位数码管控制位ucharbcd[8];//数码管bcd码缓冲区voiddelay(uintt);//延时函数声
3、明voidbin_bcd();//bcd分离函数voidsmxs();//数码管显示函数voidanjian();//掉电保持寄存器申明sfrIAP_DATA=0xe2;sfrIAP_ADDRH=0xe3;sfrIAP_ADDRL=0xe4;sfrIAP_CMD=0xe5;sfrIAP_TRIG=0xe6;sfrIAP_CONTR=0xe7;#defineCMD_IDLE0#defineCMD_READ1#defineCMD_PROGRAM2#defineCMD_ERASE3//定义Flash操作等待时间及允许IAP/ISP/EEPROM操作的常
4、数//#defineENABLE_IAP0x82//系统工作时钟<20MHZ#defineENABLE_IAP0x83//系统工作时钟<40MHZ#defineIAP_ADDRESS0x2000#defineIAP_ADDRESS10x2200voidcc(uintaddr);//擦除某一扇区voidxcx(uintaddr,uchardat);//写一字节uchardcx(uintaddr);//读一字节voidGB_IAP();//关闭IAP/IAP操作voiddelay(uintt){while(--t);}voidsmxs(){uchar
5、i;for(i=0;i<8;i++){led_port=0;dm=1;dm=0;led_port=wxian[i];wm=1;wm=0;led_port=dxian[bcd[i]];if(i==5)led_port=led_port
6、0x80;dm=1;dm=0;delay(300);}}voidbin_bcd(){bcd[0]=a/10000000;bcd[1]=a/1000000;bcd[2]=a/100000;bcd[3]=(a%100000)/10000;bcd[4]=(a%10000)/1000;bcd[5]=(a%1000)/100;
7、bcd[6]=(a%100)/10;bcd[7]=(a%100)%10;}voidbin_bcd1(){bcd[0]=a1/10000000;bcd[1]=a1/1000000;bcd[2]=a1/100000;bcd[3]=(a1%100000)/10000;bcd[4]=(a1%10000)/1000;bcd[5]=(a1%1000)/100;bcd[6]=(a1%100)/10;bcd[7]=(a1%100)%10;}voidxs32_8(){temp1=(a>>24)&0xff;temp2=(a>>16)&0xff;temp3=(a>>8
8、)&0xff;temp4=a&0xff;}voidxs8_32(){a=((ulong)(temp1)<<24)
9、((ulong)(temp2)<<16)
10、((ulong)(temp3)<<8)
11、temp4;}voidxs32_81(){temp5=(a1>>24)&0xff;temp6=(a1>>16)&0xff;temp7=(a1>>8)&0xff;temp8=a1&0xff;}voidxs8_321(){a1=((ulong)(temp5)<<24)
12、((ulong)(temp6)<<16)
13、((ulong)(temp7)<<8)
14、temp
15、8;}/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈函数:主程序┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈