1.添加头文件
#include <REGX52.H>
#include <INTRINS.H>
2.定义延时函数,无需手写,打开STC软件设置延时策略后进行C,V操作
void Delay(unsigned int xms)
{
unsigned char i, j;
_nop_();
_nop_();
while(xms){
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
xms--;
}
}
3.定义函数,通过位置get需要亮灯的位置
char getPostion(unsigned int pos){
char s = '0';
switch(pos){
case 1:
s = 0xFE; // 1111 1110
break;
case 2:
s = 0xFD; // 1111 1101
break;
case 3:
s = 0xFB; // 1111 1011
break;
case 4:
s = 0xF7; //1111 0111
break;
case 5:
s = 0xEF; //1110 1111
break;
case 6:
s