您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 电气技术 > 39单片机80c51 实用程序大全
开发板实验程序总结开发板:学林电子xl2000单位:沈阳师范大学学院:物理科学与技术专业:电子信息工程姓名:孙巍日期:2011.6.272目录第一节:循环点亮二极管........................................................................3第二节、拨码开关控制灯......................................................................4第三节、数码管静态扫描........................................................................5第四节、按键控制数码管........................................................................6第五节、组合按键的实现数码管显示..................................................7第六节、步进电机按键控制..................................................................9第七节、串入并出..................................................................................10第八节、汉字显示指针调用法............................................................12第九节、汉字显示屠龙宝刀天下无敌..............................................14第十节、液晶屏幕显示..........................................................................17第十一节、基于adc转换的电压表数码管显示.................................25第十二节、基于adc转换的电压表液晶显示.....................................27第十三节、行列键盘数码管显示键值................................................35第十四节、行列键盘计算器+液晶显示................................................38第十五节、红外线遥控计算器..............................................................48附录:出错记录与心得体会..................................................................583第一节:循环点亮二极管//该程序通过P1循环点亮二极管#includereg52.h#includeintrins.hvoiddelayms(unsignedcharms){unsignedchari;while(ms--){for(i=0;i120;i++);}}main(){unsignedcharLED;LED=0xfe;P1=LED;while(1){LED+=1;//循环右移1位,点亮下一个LEDP1=LED;delayms(20);}}4第二节、拨码开关控制灯#includereg52.hunsignedcharshu[]={0x28,0x7E,0xA2,0x62,0x74,0x61,0x21,0x7A,0x20,0x60,0xff};sbitw1=P1^0;voiddelay(inta){inti,j;for(i=a;i0;i--){for(j=200;j0;j--);}}donw(chars){delay(50);while(1){if(w1){returns;}}}main(){inti=1;while(1){if(w1==0)i+=donw(1);P2=shu[i];delay(20);if(i==10)i=1;}}5第三节、数码管静态扫描#includereg52.hunsignedcharshu248[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D};voiddelay(inta){inti,j;for(i=a;i0;i--){for(j=200;j0;j--);}}main(){inti;while(1){for(i=1;i10;i++){P2=shu248[i];delay(500);}}}6第四节、按键控制数码管//通过按键,数码管显示值增加#includereg52.hunsignedcharshu[]={0x28,0x7E,0xA2,0x62,0x74,0x61,0x21,0x7A,0x20,0x60,0xff};sbitw1=P1^0;voiddelay(inta){inti,j;for(i=a;i0;i--){for(j=200;j0;j--);}}donw(chars){delay(50);while(1){if(w1){returns;}}}main(){inti=1;while(1){if(w1==0)i+=donw(1);P2=shu[i];delay(20);if(i==10)i=1;}}7第五节、组合按键的实现数码管显示#includereg52.hunsignedcharshu248[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D};unsignedcharshu[]={0x28,0x7E,0xA2,0x62,0x74,0x61,0x21,0x7A,0x20,0x60,0xff};unsignedcharwei[]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};sbitw1=P2^0;//数码管个位位选sbitw2=P2^1;//数码管十位位选sbitw3=P2^2;//数码管百位位选sbitw4=P2^3;//数码管百位位选sbitopen_1=P2^7;//按键1sbitopen_all=P2^6;voiddelay(inta){inti,j;for(i=a;i0;i--){for(j=200;j0;j--);}}voidprt(intrenshu){w3=1;w2=1;w1=0;P1=shu[renshu/100];delay(5);w1=1;w3=1;w2=0;P1=shu[(renshu%100)/10];delay(5);w3=0;w2=1;w1=1;P1=shu[renshu%10];delay(5);8w3=1;}intkey(){delay(20);if(open_1==0){while(!open_1)if(open_all==0&&open_1==0){while(1){if(open_all&&open_1)return3;}}if(open_1)return1;}if(open_all==0){while(!open_all){if(open_all==0&&open_1==0){while(1){if(open_all&&open_1)return3;}}if(open_all)return2;}}}main(){inti=255;while(1){prt(i);if(open_1==0||open_all==0)i+=key();}}9第六节、步进电机按键控制#includereg52.hunsignedcharshu[]={0x28,0x7E,0xA2,0x62,0x74,0x61,0x21,0x7A,0x20,0x60,0xff};sbitw1=P1^0;voiddelay(inta){inti,j;for(i=a;i0;i--){for(j=200;j0;j--);}}donw(chars){delay(50);while(1){if(w1){returns;}}}main(){inti=1;while(1){if(w1==0)i+=donw(1);P2=shu[i];delay(20);if(i==10)i=1;}}10第七节、串入并出/*****************************************************************************************************这是一个传入并出的程序实例使用单片机通信接口P3.0P3.1作为输出传入并出芯片使用74ls164在试验箱上可以驱动二极管以便验证结果编写时间2011.6.16copyrightfor:孙巍沈阳师范大学【声明】此程序仅用于学习与参考,引用请注明版权和作者信息!****************************************************************************************************/#includereg52.hunsignedcharshu[]={0x28,0x7E,0xA2,0x62,0x74,0x61,0x21,0x7A,0x20,0x60,0xff};sbitdate=P3^0;sbitclk=P3^1;voiddelay(inta){inti,j;for(i=a;i0;i--){for(j=200;j0;j--);}}voidwr_date(chardate){SBUF=date;while(TI==0);TI=0;}main(){chartemp;SCON==0x00;delay(5);temp=0x01;11while(1){wr_date(temp);delay(100);if(temp==0x40)temp=0x01;elsetemp*=2;}}12第八节、汉字显示指针调用法/*****************************************************************************************************这是一个16*16点阵显示程序使用P0口控制16*16显示器列上的高8位使用P2口控制16*16显示器列上的低8位使用P1口的第四位作为4线16线译码器(74ls154)的输入编写时间2011.6.15copyrightfor:孙巍沈阳师范大学【声明】此程序仅用于学习与参考,引用请注明版权和作者信息!****************************************************************************************************/#includereg52.hunsignedcharhanzi_da[16][2]={0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x38,0x38,0x7C,0x7C,0xFE,0xFE,0xFF,0xFE,0x7F,0xFC,0x3F,0xF8,0x1F,0xF0,0x0F,0xE0,0x0F,0xE0,0x07,0xC0,0x03,0x80,0x01,0x00};unsignedcharshu16[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};sbitdate=P3^0
本文标题:39单片机80c51 实用程序大全
链接地址:https://www.777doc.com/doc-4963397 .html