学习了一周的单片机,然后中途有事打断了两周,现在温习一下之前学的东西,用“普中科技单片机”上的LED点阵显示自己的名字。
P1接J19(绿)、P2接J20(红),P0接J12(数码管段选);5V电压;
显示图片如下:
LED点阵原理说明:链接: http://pan.baidu.com/s/1eQtqF 密码: h9b3
代码如下:
1 #include <reg52.h> 2 3 unsigned char code dispbit[] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //行选通 4 unsigned char myname[3][8] = { 5 {0x00,0x7f,0x08,0x7f,0x08,0x7f,0x00,0x00}, 6 {0x00,0x3e,0x08,0x7f,0x14,0x22,0x41,0x00}, 7 {0x00,0x3c,0x38,0x10,0x69,0x82,0x00,0x00}}; 8 9 10 void main() 11 { 12 int cntx = 0,cnty = 0;//分别行与列 13 int countx = 0,county = 0; 14 15 while(1) 16 { 17 P1 = 0xff; 18 P2 = dispbit[cnty]; 19 P0 = myname[cntx][cnty]; 20 21 //控制动态扫描速度 22 if(++county >= 50) 23 { 24 county = 0; 25 ++cnty; 26 if(cnty >= 8) 27 cnty = 0; 28 } 29 30 //控制字符间切换的速度 31 if( ++countx >= 20000) 32 { 33 countx = 0; 34 ++ cntx; 35 if(cntx >= 3) 36 cntx = 0; 37 } 38 39 } 40 }