我们设计横排点阵显示名字和竖排显示名字,通过四个按钮实现名字上下左右平移;
例如我的名字,SYM开头。
其实算法很简单,写一个简单的滑动窗口就好,实现数组的平移。
实现代码:
#include "reg51.h"
typedef unsigned int u16;
typedef unsigned char u8;
void delay_10us(u16 ten_us) {
while (ten_us--);
}
u8 gled_row[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
unsigned char pattern[] = {
0xFF,
0xE3,
0xFB,
0xE3,
0xEF,
0xE3,
0xFF,
0xFF,
0xff,
0xbb,
0xd7,
0xef,
0xef,
0xef,
0xff,
0xff,
0xff,
0xff,
0xd7,
0xc7,
0xab,
0xbb,
0xff,
0xff,
};
unsigned char data_ms[] = {0xFF, 0xFF, 0xF1, 0xCF, 0xF7, 0xCF, 0xF1, 0xFF,0xFF, 0xFF, 0xFF, 0x8B, 0xAB, 0xA3, 0xFF, 0xFF,0xFF, 0xFF, 0xBF, 0xDF, 0xE1, 0xDF, 0xBF, 0xFF};
sbit K1 = P2^0;
sbit K2 = P2^1;
sbit K3 = P2^2;
sbit K4 = P2^3;
int main() {
if(K1 == 0){
int i=0;
int j=0;
int t=0;
while(K1 == 0){
j=t++;
if(t>24){
t = 0;
}
delay_10us(500);
for(i = 0;i<8;i++){
P0 = gled_row[i];
P1 = pattern[j];
j++;
if(j>=24){
j=0;
}
delay_10us(600);
}
}
}
if(K2 == 0){
int i=0;
int j=0;
int t=0;
while(K2 == 0){
t--;
if(t<0){
t = 24;
}
j = t;
delay_10us(500);
for(i = 0;i<8;i++){
P0 = gled_row[i];
P1 = pattern[j];
j++;
if(j>=24){
j=0;
}
delay_10us(500);
}
}
}
if(K3 == 0){
int i=0;
int j=0;
int t=0;
while(K3 == 0){
t--;
if(t<0){
t = 24;
}
j = t;
delay_10us(500);
for(i = 0;i<8;i++){
P1 = ~gled_row[i];
P0 = ~data_ms[j];
j++;
if(j>=24){
j=0;
}
delay_10us(500);
}
}
}
if(K4 == 0){
int i=0;
int j=0;
int t=0;
while(K4 == 0){
j=t++;
if(t>=24){
t = 0;
}
delay_10us(500);
for(i = 0;i<8;i++){
P1 = ~gled_row[i];
P0 = ~data_ms[j];
j++;
if(j>=24){
j=0;
}
delay_10us(600);
}
}
}
}
标签:24,10,12,delay,int,2024,0xFF,10us,0xff
From: https://www.cnblogs.com/AnnaStore/p/18597218