这一篇文章主要介绍用C语言制作一个8x8矩阵LED灯。
基本电路图如下:
使用的代码如下:
#include<reg51.h>
unsigned char code table_1[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; //列扫描
unsigned char code table_2[] = {0xff, 0x83, 0x7d, 0x6d, 0x6d, 0x6d, 0x9b, 0xff}; //行扫描
void delay(unsigned int xms){ //延时函数
unsigned int i, j;
for(i=0; i<xms; ++i)
for(j=0; j<110; ++j)
;
}
void main(){
while(1){
unsigned char i;
for(i=0; i<8; ++i){
P2 = table_1[i]; //先列扫描
P3 = table_2[i]; //再行扫描
delay(5);
}
}
}
/*仅供学习参考*/