赞
踩
一、八位数码管
- #include<reg51.h>
- void delay(unsigned int i);
- void main()
- {
- unsigned char button;
- unsigned char code disp[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0xbf};
- P0=0xff;
- P1=disp[8];
- while(1)
- {
- button=P0;
- delay(1200);
- button=P0;
- switch(button)
- {
- case 0xfe:P1=disp[0];delay(10000);while(1);break;
- case 0xfd:P1=disp[1];delay(10000);while(1);break;
- case 0xfb:P1=disp[2];delay(10000);while(1);break;
- case 0xf7:P1=disp[3];delay(10000);while(1);break;
- case 0xef:P1=disp[4];delay(10000);while(1);break;
- case 0xdf:P1=disp[5];delay(10000);while(1);break;
- case 0xbf:P1=disp[6];delay(10000);while(1);break;
- case 0x7f:P1=disp[7];delay(10000);while(1);break;
- default:break;
- }
- }
- }
二、数码管显示0-9
- #include<reg51.h>
- void delay(unsigned int i);
- void main()
- {
- P1=0xc0;
- delay(1000);
- P1=0xf9;
- delay(1000);
- P1=0xa4;
- delay(1000);
- P1=0xb0;
- delay(1000);
- P1=0x99;
- delay(1000);
- P1=0x92;
- delay(1000);
- P1=0x82;
- delay(1000);
- P1=0xf8;
- delay(1000);
- P1=0xbf;
- delay(1000);
- }
三、在显示屏上输入abc
- #include <reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit RS=P3^1;
- sbit E=P3^2;
- uchar code table[]="I LOVE YOU ZZY";
- void delay(ms){
- uint i,j;
- for(i=0;i<ms;i++){
- for(j=0;j<123;j++){
- }
-
- }
- }
- void write_com(uchar com){
- E=0;
- RS=0;
- P0=com;
- delay(5);
- E=1;
- delay(5);
- E=0;
- }
-
- void write_data(uchar dat){
- E=0;
- RS=1;
- P0=dat;
- delay(5);
- E=1;
- delay(5);
- E=0;
- }
-
- void init(){
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- }
-
- void main(){
- uint i;
- init();
- write_com(0x80+0x40);
- for(i=0;i<16;i++){
- write_data(table[i]);
- delay(5);
- }while(1);
-
- }
仿真
链接:https://pan.baidu.com/s/1VZf1vfGFXAgWXgk8R3Mrlg
提取码:2222
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。