您的位置:首页 > 其它

LED点阵显示名字

2013-11-25 16:12 211 查看
学习了一周的单片机,然后中途有事打断了两周,现在温习一下之前学的东西,用“普中科技单片机”上的LED点阵显示自己的名字。

P1接J19(绿)、P2接J20(红),P0接J12(数码管段选);5V电压;

显示图片如下:

#include <reg52.h>

unsigned char code dispbit[] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //行选通
unsigned char myname[3][8] = {
{0x00,0x7f,0x08,0x7f,0x08,0x7f,0x00,0x00},
{0x00,0x3e,0x08,0x7f,0x14,0x22,0x41,0x00},
{0x00,0x3c,0x38,0x10,0x69,0x82,0x00,0x00}};

void main()
{
int cntx = 0,cnty = 0;//分别行与列
int countx = 0,county = 0;

while(1)
{
P1 = 0xff;
P2 = dispbit[cnty];
P0 = myname[cntx][cnty];

//控制动态扫描速度
if(++county >= 50)
{
county = 0;
++cnty;
if(cnty >= 8)
cnty = 0;
}

//控制字符间切换的速度
if( ++countx >= 20000)
{
countx = 0;
++ cntx;
if(cntx >= 3)
cntx = 0;
}

}
}


代码如下:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: