资源描述:
《单片机c语言程序库》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、单片机库姓名:[鹿子庆]联系电话:[13627264791]联系地址:[武汉理工大学]目录1点亮第一个发光二极管32不带参数的延时函数使灯闪烁33带参数的延时惭数使灯闪烁44左右移函数45流水灯56带蜂鸣器的流水灯57第一个数码管显示878六个数码管同时亮一次显示0-F79第一个数码管显示1,关闭,第二个数码管显示2,关闭,……810定时器中断程序1011键盘操作1312矩阵键盘扫描1613A/D1914D/A211点亮第一个发光二极管#includesbitDl=PlAO;voidmain(){Dl=0;2不带参数
2、的延时函数使灯闪烁#include#defineunitunsignedintsbita=PlA0;voiddelay();voidmain(){while(l){a=0;delay();a=l;delay();}}voiddelay()uniti,j;for(i=500;i>0;i-)for(j=110;j>0;j-);3带参数的延时函数使灯闪烁#include#defineunitunsignedintsbita=PlAO;voiddelayl(uint);voidmain(){while(l
3、){a=0;delay1(400);a=l;delay1(600);}}voiddelay1(unitxms){uniti,j;for(i=xms;i>0;i-)forG=110;j>0;j-);4左右移函数#include#defineuintunsignedcharuinta;voidmain(){a=0xba;while(l)a=a«l;〃右侧移动改变为>>即可5流水灯#include#include#defineuintunsignedint#defineucharu
4、nsignedcharvoiddelay1(uint);ucharaa;voidmain(){aa=0xfe;while(l){Pl=aa;delay1(500);aa=_crol_(aa,1);voiddelay1(uintz){uinti,j;for(i=z;i>0;i-)for(j=110;j>0;j-);6带蜂鸣器的流水灯#include#include#defineuintunsignedint#defineucharunsignedcharuchartemp,num,numl;sb
5、itbeep=P2A3;voiddelay(uint);voidmain()temp=Oxfe;while(l){for(num1=O;num1<3;numI++){for(num=0;numv&num++){Pl=temp;beep=O;delay(lOO);temp=_crol_(temp,1);//cror换方向移动Pl=Oxff;beep=1;delay(lOO);1}for(numl=0;numl<3;numl++){for(num=0;num<8;num++){Pl=temp;beep=O;delay(lOO);temp
6、=_cror_(temp,1);Pl=Oxff;beep=1;delay(lOO);}}while(l);}}voiddelay(uintz){uintx,y;for(x=z;x>0;x-)for(y=110;y>0;y-);7第一个数码管显示8#includesbitdula=P2A6;sbitwela=P2A7;voidmain(){wela=l;P0=0xc0;wela=0;dula=l;P0=0x06;dula=0;while(l);}8六个数码管同时亮一次显示0-F#include#de
7、fineuintunsignedint#defineucharunsignedcharsbitdula=P2A6;sbitwela=P2A7;ucharnum;ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddelay1(uint);voidmain(){wela=l;//l1101010P0=0xea;wela=0;while(l){for(num=0;numv16;num+
8、+){dula=l;P0=table[num];dula=0;delay(lOOO);voiddelayl(uintz){uintx,y;for(x=z;x>0;x—)for(y=110;y>0;y-);9第一个数码管显示1,关闭,第