资源描述:
《天狼星51&avr课上程序代码》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、51篇51单片机第二十课PS2键盘键值解码所属类别:课程代码发布日期:2011-03-05点击量:383#include#defineucharunsignedchar#defineuintunsignedintsbitpsdata=P3^0;sbitpsclk=P3^2;ucharnumbit;ucharkeyv;ucharkey[3];ucharkeynum;ucharm,n;unsignedcharcodesmg_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
2、,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};unsignedcharcodesmg_we[]={0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78};//************************************************//延时函数,在12MHz的晶振频率下//大约50us的延时//************************************************voiddelay_50us(uintt){ucharj;for(;t>0;t--)
3、for(j=19;j>0;j--);}//************************************************//延时函数,在12MHz的晶振频率下//大约50ms的延时//************************************************voiddelay_50ms(uintt){uintj;for(;t>0;t--)for(j=6245;j>0;j--);}voidmain(){IT0=1;//外部中断下降沿触发EX0=1;//打开外部中断0EA=1;//打开总中断while(1){i
4、f(keynum==3){keynum=0;//0x1cn=key[0]/16;m=key[0]%16;}P1=smg_du[m];P2=smg_we[0];delay_50us(20);P1=smg_du[n];P2=smg_we[1];delay_50us(20);}}voidint0()interrupt0{if((numbit>0)&&(numbit<9))//>>{keyv=keyv>>1;//001000000if(psdata)keyv=keyv
5、0x80;//10000000}//01numbit++;//0if(numbit>1
6、0){numbit=0;key[keynum]=keyv;keynum++;}}51单片机第二十三课实时时钟芯片DS1302的读写所属类别:课程代码发布日期:2011-03-05点击量:531#include#include#defineucharunsignedchar#defineuintunsignedintsbitsck=P1^0;sbitio=P1^1;sbitrst=P3^6;sbitsmgen=P2^3;unsignedcharcodesmg_du[]={0x3f,0x06,0x5b,0x4f
7、,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x10};unsignedcharcodesmg_we[]={0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78};uchartime_data[7]={10,6,4,17,11,58,30};//年周月日时分秒ucharwrite_add[7]={0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};ucharread_add[7]={0x8d,0x8b,0x89,0
8、x87,0x85,0x83,0x81};uchardisp[8];voidwrite_ds1302_byte(uchardat);voidwrite_ds1302(ucharadd,uchardat);ucharread_ds1302(ucharadd);voidset_rtc(void);voidread_rtc(void);voidtime_pros(void);voiddisplay(void);//************************************************//延时函数,在12MHz的晶振频率下//大约
9、50us的延时//************************************************voiddelay_5