静态数码管
#include
typedef unsigned char u8;
typedef unsigned int u16;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
u8 code smgduan[]={0x06,0x4f,0x6d,0x07,0x6f};
void delay(u16 i)
{
while(i--);
}
void display()
{
u8 a;
for(a=0;a<5;a++)
{
P0=smgduan[a];
delay(100000);
P0=0x00;
}
}
void main()
{
LSA=0;
LSB=0;
LSC=0;
while(1)
{
display();
}
}
矩阵键盘控制led
#include "reg52.h"
#include //因为要用到左右移函数,所以加入这个头文件
typedef unsigned int u16;
typedef unsigned char u8;
#define LED P2
#define GPIO_KEY P1
u8 KeyValue; //用来存放读取