基于51单片机开发的简易的8X8点阵

简易的8X8点阵,拿去
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)

基于51单片机开发的简易的8X8点阵_第1张图片

#include 
#include 
#define uchar unsigned char
#define uint unsigned int
void delayms(unsigned int n);
sbit KEY=P2^0;
sbit KEY1=P2^1;
sbit KEY2=P2^2;

//添加取模记得定义数组数量
uchar code M[11][8]=                                                                               
{
        {0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00},
        {0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00},
        {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
        {0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00},
        {0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00},
        {0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00},
        {0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00},
        {0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00},
        {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
        {0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00},
        {0x00,0x20,0x30,0x38,0x3c,0x3e,0x00,0x00}
};

uchar i,j;
void main()
{
        P0 = 0xff;
        P1 = 0xff;
        P2 = 0xff;
       
        TMOD = 0x01;
        TH0  = (65535-2000)/256;
        TL0  = (65535-2000)%256;
        IT0 = 1;
        IE  = 0x83;
        i   = 0xfc;                                                                        //开头修改这即可
        while(1)
        {
                if(!KEY)
                {
                        delayms(100);
                        while(!KEY)
                        {
                                         P0 = 0xff;
                                        P1 = 0x80;
                                        j = 0;
                                        i = (i+1)%11;
                        }
                }
                if(!KEY1)
                {
                        delayms(100);
                        while(!KEY1)
                        {
                                         P0 = 0xff;
                                        P1 = 0x80;
                                        j = 0;
                                        i = (i+1)%11;
                        }
                }
                if(!KEY2)
                {
                        delayms(100);
                        while(!KEY2)
                        {
                                         P0 = 0xff;
                                        P1 = 0x80;
                                        j = 0;
                                        i = (i+1)%11;
                        }
                }               
        }
}

你可能感兴趣的:(51单片机DIY项目,c语言,单片机)