c++
Copy code
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11} //定义LED引脚
int numPins[][7] = { //定义数字0~9的LED点阵图形
{1, 1, 1, 1, 1, 1, 0}, //0
{0, 1, 1, 0, 0, 0, 0}, //1
{1, 1, 0, 1, 1, 0, 1}, //2
{1, 1, 1, 1, 0, 0, 1}, //3
{0, 1, 1, 0, 0, 1, 1}, //4
{1, 0, 1, 1, 0, 1, 1}, //5
{1, 0, 1, 1, 1, 1, 1}, //6
{1, 1, 1, 0, 0, 0, 0}, //7
{1, 1, 1, 1, 1, 1, 1}, //8
{1, 1, 1, 1, 0, 1, 1} //9
}
void setup() {
for (int i = 0i <10i++) { //初始化LED引脚为输出缺嫌模式
pinMode(ledPins[i], OUTPUT)
}
}
void loop() {
for (int num = 9num >= 0num--) { //从数字9到0循环
for (int i = 0i <7i++) { //依次点亮数字的7个LED
digitalWrite(ledPins[i], numPins[num][i])//控制LED引脚输出高低电平
}
delay(1000) //伏塌手延时1秒
}
}
该程序利用数组存储数字09的LED点阵图形,并通过循环依次点亮每个数字的7个LED,从而实现数字09的循环显示。可以根据需要对延时时间进行调整,以达到合适的显示效果。
这个程序可以循环显示0~9.#include<reg51.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned intuchar code Table_of_Digits[]={0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, //00x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00, //10x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00, //20x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00, //30x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00, //40x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00, //50x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00, //60x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00, //70x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //80x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00, //90xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff}uchar code xdat[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}uchar code ydat[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}uchar i=0,j=0,t=0,Num_Index,key,xi,yisbit we1=P1^1sbit we2=P1^3//主程序void main(){//P1=0x80Num_Index=0//从0 开始显示TMOD=0x01//T0 方式0TH0=(65536-2000)/256//2ms 定时TL0=(65536-2000)%256IE=0x82key=0xi=0yi=0EX0=1IT0=1TR0=1//启动T0while(1)}//T0 中断函数void ext_int0() interrupt 0{key++ key&=0x03}void LED_Screen_Display() interrupt 1{TH0=(65536-2000)/256//2ms 定时TL0=(65536-2000)%256switch(key){case 0: P0=0xffwe1=1P0=~Table_of_Digits[Num_Index*8+i]we1=0P0=0xff//输出位码和段码 we2=1P0=xdat[i]we2=0if(++i==8) i=0//每屏一个数字由8 个字节构成 if(++t==250) //每个数字刷新显庆慎祥示一段时间 { t=0if(++Num_Index==10) Num_Index=0//显示下一个数字 } breakcase 1: we1=1P0=~xdat[xi]we1=0we2=1P0=ydat[yi]we2=0if(++t==250) //每个数字刷新显示一段时间 { t=0yi++if(yi>7){yi=0xi++} if(xi>7)xi=0} breakcase 2: we1=1P0=0x00we1=0P0=0xff//输出位码和段码 we2=1P0=xdat[i]we2=0if(++t==250) //每个数字刷新显示一段时间 { if(++i==8) i=0//孝野每屏誉搏一个数字由8 个字节构成 t=0} breakdefault:key=0 i=0 j=0 t=0 xi=0 yi=0 Num_Index=0 we1=1 P0=0xff we1=0 we2=1 P1=0x80 we2=0break}}设计点阵数字的显示效果 为了简化,我们这岩野州里只考脊哗虑0~9这十个阿拉伯数字,每个数字点阵都是5行4列,在Python中可以用tuple来表示。(在设计点粗蔽阵字模的过程中,你也可以体验一下当美工或字体设计师的感觉,@_@)。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)