tags: Professional courses from stepping on the pit to living in the pit MCU
A 16*16 LED dot matrix screen is designed to imitate the floor display device of elevator operation. The I/O port of the single-chip microcomputer is used to connect 8 switches, representing the floor buttons of 1-8 floors. The current position scrolls up or down smoothly to the position of the designated floor. When the designated position is reached, the buzzer emits a sound and the led light flashes, and the number continues to scroll.


#include<reg52.h>
#include<intrins.h>
void delayms(unsigned char t);
void dataset(unsigned char a);
void dataset1(unsigned char a);
void dataset2(unsigned char a);
void dataset3(unsigned char a);
void setlie(unsigned char a,unsigned char b);
void sethang(unsigned char a,unsigned char b);
void hang(unsigned char a);
void lie(unsigned char a);
void hanglie(unsigned char a,unsigned char b);
void clear();
void hangbianli(unsigned char *a);
void liebianli(unsigned char *a);
void all(unsigned char a);
void all1(unsigned char a);
void num(unsigned char n);
void shangxia(unsigned char x);
unsigned char code hanglist[16][2] = {{0x80,0x00},{0x40,0x00} ,{0x20,0x00} ,{0x10,0x00} ,{0x08,0x00} ,{0x04,0x00} ,{0x02,0x00} ,{0x01,0x00} ,
{0x00,0x80},{0x00,0x40} ,{0x00,0x20} ,{0x00,0x10} ,{0x00,0x08} ,{0x00,0x04} ,{0x00,0x02} ,{0x00,0x01}};
unsigned char code shang[8][2] = {{0x01,0x80},{0x03,0xc0} ,{0x07,0xe0} ,{0x0f,0xf0} ,{0x03,0xc0} ,{0x03,0xc0} ,{0x03,0xc0} ,{0x03,0xc0}};
unsigned char code zero[16][2] = {{0x00,0x00},{0x00,0x00} ,{0x0f,0xf0} ,{0x0f,0xf0} ,{0x0c,0x30} ,{0x0c,0x30} ,{0x0c,0x30} ,{0x0c,0x30} ,
{0x0c,0x30},{0x0c,0x30} ,{0x0c,0x30} ,{0x0c,0x30} ,{0x0f,0xf0} ,{0x0f,0xf0} ,{0x00,0x00} ,{0x00,0x00}};
unsigned char code one[16][2] = {{0x00,0x00},{0x00,0x00} ,{0x01,0x80} ,{0x03,0x80} ,{0x07,0x80} ,{0x01,0x80} ,{0x01,0x80} ,{0x01,0x80} ,
{0x01,0x80},{0x01,0x80} ,{0x01,0x80} ,{0x01,0x80} ,{0x07,0xe0} ,{0x07,0xe0} ,{0x00,0x00} ,{0x00,0x00}};
unsigned char code two[16][2] = {{0x00,0x00},{0x00,0x00} ,{0xf,0xf0} ,{0x0f,0xf0} ,{0x00,0x30} ,{0x00,0x30} ,{0x00,0x30} ,{0x0f,0xf0} ,
{0x0f,0xf0},{0x0c,0x00} ,{0x0c,0x00} ,{0x0c,0x00} ,{0x0f,0xf0} ,{0x0f,0xf0} ,{0x00,0x00} ,{0x00,0x00}};
unsigned char code three[16][2] = {{0x00,0x00},{0x00,0x00} ,{0xf,0xf0} ,{0x0f,0xf0} ,{0x00,0x30} ,{0x00,0x30} ,{0x00,0x30} ,{0x0f,0xf0} ,
{0x0f,0xf0},{0x00,0x30} ,{0x00,0x30} ,{0x00,0x30} ,{0x0f,0xf0} ,{0x0f,0xf0} ,{0x00,0x00} ,{0x00,0x00}};
unsigned char code four[16][2] = {{0x00,0x00},{0x00,0x00} ,{0xc,0x30} ,{0x0c,0x30} ,{0x0c,0x30} ,{0x0c,0x30} ,{0x0c,0x30} ,{0x0f,0xf0} ,
{0x0f,0xf0},{0x00,0x30} ,{0x00,0x30} ,{0x00,0x30} ,{0x00,0x30} ,{0x00,0x30} ,{0x00,0x00} ,{0x00,0x00}};
unsigned char code five[16][2] = {{0x00,0x00},{0x00,0x00} ,{0xf,0xf0} ,{0x0f,0xf0} ,{0x0c,0x00} ,{0x0c,0x00},{0x0c,0x00} ,{0x0f,0xf0},
{0x0f,0xf0} ,{0x00,0x30} ,{0x00,0x30} ,{0x00,0x30},{0x0f,0xf0} ,{0x0f,0xf0} ,{0x00,0x00} ,{0x00,0x00}};
unsigned char code six[16][2] = {{0x00,0x00},{0x00,0x00} ,{0xf,0xf0} ,{0x0f,0xf0} ,{0x0c,0x00} ,{0x0c,0x00},{0x0c,0x00} ,{0x0f,0xf0},
{0x0f,0xf0} ,{0x0c,0x30} ,{0x0c,0x30} ,{0x0c,0x30},{0x0f,0xf0} ,{0x0f,0xf0} ,{0x00,0x00} ,{0x00,0x00}};
unsigned char code seven[16][2] = {{0x00,0x00},{0x00,0x00} ,{0xf,0xf0} ,{0x0f,0xf0} , {0x00,0x30}, {0x00,0x30}, {0x00,0x30}, {0x00,0x30},
{0x00,0x30}, {0x00,0x30}, {0x00,0x30}, {0x00,0x30}, {0x00,0x30}, {0x00,0x30},{0x00,0x00} ,{0x00,0x00}};
unsigned char code eight[16][2] = {{0x00,0x00},{0x00,0x00} ,{0xf,0xf0} ,{0x0f,0xf0} ,{0x0c,0x30} ,{0x0c,0x30},{0x0c,0x30} ,{0x0f,0xf0},
{0x0f,0xf0} ,{0x0c,0x30} ,{0x0c,0x30} ,{0x0c,0x30},{0x0f,0xf0} ,{0x0f,0xf0} ,{0x00,0x00} ,{0x00,0x00}};
sbit sj0 = P0^1;
sbit hs0 = P0^0;
sbit dpt0 = P0^2;
sbit sj1 = P0^4;
sbit hs1 = P0^3;
sbit dpt1 = P0^5;
sbit sj2 = P2^1;
sbit hs2 = P2^0;
sbit dpt2 = P2^2;
sbit sj3 = P2^4;
sbit hs3 = P2^3;
sbit dpt3 = P2^5;
sbit LED = P3^0;
sbit beep = P3^1;
unsigned char p = 0; //¶à´Î
unsigned char state = 0; //µ±Ç°Â¥²ã±ê־λ
unsigned char ctrl = 0; //Â¥²ã¿ØÖÆÎ»
void main()
{
state = 1;
ctrl = 1;
LED = 0;
beep = 0;
while(1)
{
switch(~P1)
{
case 0x01:
ctrl = 1;
break;
case 0x02:
ctrl = 2;
break;
case 0x04:
ctrl = 3;
break;
case 0x08:
ctrl = 4;
break;
case 0x10:
ctrl = 5;
break;
case 0x20:
ctrl = 6;
break;
case 0x40:
ctrl = 7;
break;
case 0x80:
ctrl = 8;
break;
default: break;
}
if(ctrl > state)
{
LED = 0;
for( ; state < ctrl ; state ++) //Ò»¸öСËã·¨ µ½´ïÌØ¶¨Â¥²ãʱºò²»ÔÙÏÔʾÁË ÒòΪelse{}¾ÍÊÇÏÔʾ
{
for(p = 0; p<50; p++)
num(state);
shangxia(1);
}
beep = 1;
}
else if (ctrl < state)
{
LED = 0;
for( ; state > ctrl ; state --) //Ò»¸öСËã·¨ µ½´ïÌØ¶¨Â¥²ãʱºò²»ÔÙÏÔʾÁË ÒòΪelse{}¾ÍÊÇÏÔʾ
{
for(p = 0; p<50; p++)
num(state);
shangxia(0);
}
beep = 1;
}
else{
num(state);
LED = 1;
beep = 0;
}
}}
void shangxia(unsigned char x)
{
if(x == 0 )
{
//ÏÂ
for(p = 0; p<30; p++)
all1(0);
delayms(300);
for(p = 0; p<30; p++)
all1(4);
delayms(300);
for(p = 0; p<30; p++)
all1(8);
delayms(300);
for(p = 0; p<30; p++)
all1(0);
delayms(300);
for(p = 0; p<30; p++)
all1(4);
delayms(300);
for(p = 0; p<30; p++)
all1(8);
delayms(300);
}
else
//ÉÏ
{
for(p = 0; p<30; p++)
all(0);
delayms(100);
for(p = 0; p<30; p++)
all(4);
delayms(100);
for(p = 0; p<30; p++)
all(8);
delayms(100);
for(p = 0; p<30; p++)
all(0);
delayms(100);
for(p = 0; p<30; p++)
all(4);
delayms(100);
for(p = 0; p<30; p++)
all(8);
delayms(100);
}
}
void num(unsigned char n)
{
unsigned char i = 0;
for(i = 0; i<16; i++)
{
hangbianli(hanglist[i]);
if(n == 0)
{
liebianli(zero[i]);
}
else if(n == 1)
{
liebianli(one[i]);
}
else if(n == 2)
{
liebianli(two[i]);
}
else if(n == 3)
{
liebianli(three[i]);
}
else if(n == 4)
{
liebianli(four[i]);
}
else if(n == 5)
{
liebianli(five[i]);
}
else if(n == 6)
{
liebianli(six[i]);
}
else if(n == 7)
{
liebianli(seven[i]);
}
else if(n == 8)
{
liebianli(eight[i]);
}
else
{}
delayms(10);
}
clear();
}
void all(unsigned char a)
{
unsigned char i = 0;
for(i = 8; i<16; i++)
{
hangbianli(hanglist[i-a]);
liebianli(shang[i-8]);
delayms(10);
}
clear();
}
void all1(unsigned char a)
{
unsigned char i = 0;
for(i = 0; i<9; i++)
{
hangbianli(hanglist[i+a]);
liebianli(shang[7-i]);
delayms(10);
}
clear();
}
//µ¥¶ÀµãµÆµÄ´úÂë
//void hanglie(unsigned char a,unsigned char b)
//{
// lie(b);
// hang(a);
//}
//void hang(unsigned char a)
//{
// if(a == 0)
// sethang(0x80,0x00);
// else if (a == 1)
// sethang(0x40,0x00);
// else if (a == 2)
// sethang(0x20,0x00);
// else if (a == 3)
// sethang(0x10,0x00);
// else if (a == 4)
// sethang(0x08,0x00);
// else if (a == 5)
// sethang(0x04,0x00);
// else if (a == 6)
// sethang(0x02,0x00);
// else if (a == 7)
// sethang(0x01,0x00);
// else if (a == 8)
// sethang(0x00,0x80);
// else if (a == 9)
// sethang(0x00,0x40);
// else if (a == 10)
// sethang(0x00,0x20);
// else if (a == 11)
// sethang(0x00,0x10);
// else if (a == 12)
// sethang(0x00,0x08);
// else if (a == 13)
// sethang(0x00,0x04);
// else if (a == 14)
// sethang(0x00,0x02);
// else if (a == 15)
// sethang(0x00,0x01);
//}
//void lie(unsigned char a)
//{
// if(a == 0)
// setlie(0x80,0x00);
// else if (a == 1)
// setlie(0x40,0x00);
// else if (a == 2)
// setlie(0x20,0x00);
// else if (a == 3)
// setlie(0x10,0x00);
// else if (a == 4)
// setlie(0x08,0x00);
// else if (a == 5)
// setlie(0x04,0x00);
// else if (a == 6)
// setlie(0x02,0x00);
// else if (a == 7)
// setlie(0x01,0x00);
// else if (a == 8)
// setlie(0x00,0x80);
// else if (a == 9)
// setlie(0x00,0x40);
// else if (a == 10)
// setlie(0x00,0x20);
// else if (a == 11)
// setlie(0x00,0x10);
// else if (a == 12)
// setlie(0x00,0x08);
// else if (a == 13)
// setlie(0x00,0x04);
// else if (a == 14)
// setlie(0x00,0x02);
// else if (a == 15)
// setlie(0x00,0x01);
//}
void hangbianli(unsigned char * a)
{
sethang(a[0],a[1]);
}
void liebianli(unsigned char * a)
{
setlie(a[0],a[1]);
}
void clear()
{
sethang(0xff,0xff);
setlie(0x00,0x00);
}
void sethang(unsigned char a,unsigned char b)
{
dataset2(~a);
dataset3(~b);
}
void setlie(unsigned char a,unsigned char b)
{
dataset(a);
dataset1(b);
}
void dataset(unsigned char a)
{
unsigned char i;
unsigned char b = 0x01;
dpt0 = 0;
for (i = 0;i<8;i++)
{
hs0 = 0;
sj0 = a&b;
hs0 = 1;
b = b << 1;
}
dpt0 = 1;
}
void dataset1(unsigned char a)
{
unsigned char i;
unsigned char b = 0x01;
dpt1 = 0;
for (i = 0;i<8;i++)
{
hs1 = 0;
sj1 = a&b;
hs1 = 1;
b = b << 1;
}
dpt1 = 1;
}
void dataset2(unsigned char a)
{
unsigned char i;
unsigned char b = 0x01;
dpt2 = 0;
for (i = 0;i<8;i++)
{
hs2 = 0;
sj2 = a&b;
hs2 = 1;
b = b << 1;
}
dpt2 = 1;
}
void dataset3(unsigned char a)
{
unsigned char i;
unsigned char b = 0x01;
dpt3 = 0;
for (i = 0;i<8;i++)
{
hs3 = 0;
sj3 = a&b;
hs3 = 1;
b = b << 1;
}
dpt3 = 1;
}
void delayms(unsigned char t)
{
unsigned char i,j;
for(i=t;i>0;i--)
for(j=123;j>0;j--);
}
Article Directory 1. Pin diagram of 8*8 dot matrix, drawing diagram: 2. 16*16 dot matrix 74HC595 cascade diagram: 3. Dot matrix software model: Fourth, the schematic 5. Code: Six, renderings 1. Pin di...
Proteus learning production 16 * 16 dot matrix The first step: first find the 8 * 8 dot matrix in the component library, and enter the keyword as the key. The second step: add four 8 * 8 lattices and ...
This system takes the high-speed single-chip microcomputer STCF1132 as the core, and designs and manufactures a 32×32 dot matrix LED module display. The dot matrix can achieve two working modes:...
Using the 74HC595 chip, as long as three wires are connected to the CPU, the LED dot matrix can be driven, which can be described as a driving artifact. Before writing the code, you must look at the w...
Greedy Positioning Video Video of Looping Snake Walking This article describes the two different methods of greedy method and loop method to achieve the automatic path finding of greedy food. Among th...
aims: 1. Light up an LED lamp 2. Realize the blinking of LED lights 3. Implement a running light...
github portalhttps://github.com/hao297531173/8051BigAssignment In this article, we will first look at the simplest case: flashing Chinese characters. part1 interrupt vector table This part records the...
Article Directory SPI-based OLED screen display and Chinese character dot matrix coding 1. About SPI 1 Introduction 2. SPI features 2. OLED display 1. Show your student ID and name 2. Display temperat...
/Dot matrix screen displays WXH cycle/ #include<reg52.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int sbit DIO = P3^4; sbit S_CLR = P3^5; sbit R_CLR = P3^6; ui...
Add an ad, my Taobao shop, Dot matrix LED display principle (transfer to May 24, 2007) I watched a friend do the LED screen a few days ago and wanted to see if I could do it. Find this on the Internet...