8*8点阵0~9显示程序(C语言)

8*8点阵0~9显示程序(C语言),第1张

#include <reg51.h>

unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}

unsigned char code digittab[10][8]={

{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0

{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1

{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2

{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3

{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4

{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5

{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6

{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7

{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8

{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00} //9

}

unsigned int timecount

unsigned char cnta

unsigned char cntb

void main(void)

{

TMOD=0x01

TH0=(65536-1000)/256

TL0=(65536-1000)%256

TR0=1

ET0=1

EA=1

while(1)

{

}

}

void t0(void) interrupt 1 using 0

{

TH0=(65536-1000)/256

TL0=(65536-1000)%256

P3=tab[cnta]

P1=digittab[cntb][cnta]

cnta++

if(cnta==8)

{

cnta=0

}

timecount++

if(timecount==333)

{

timecount=0

cntb++

if(cntb==10)

{

cntb=0

}

}

}

1、8*8双色点阵实际上是两个8*8点阵,必须增加一个端口来控制是使用哪个颜色的8*8点阵;或者连接成一个8*16点阵来控制。C语言代码和控制8*8点阵类似,增加扫描端口就可以了。

2、例程:

#include <reg51.h> 

unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f} 

unsigned char code digittab[10][8]={

                                    {0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0 

                                    {0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1 

                                    {0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2 

                                    {0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3 

                                    {0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4 

                                    {0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5 

                                    {0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6 

                                    {0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7 

                                    {0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8 

                                    {0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00} //9

                                    } 

  

unsigned int timecount 

unsigned char cnta 

unsigned char cntb 

  

void main(void) 

  TMOD=0x01 

  TH0=(65536-1000)/256 

  TL0=(65536-1000)%256 

  TR0=1 

  ET0=1 

  EA=1 

  while(1) 

    { 

    } 

  

void t0(void) interrupt 1 using 0 

  TH0=(65536-1000)/256 

  TL0=(65536-1000)%256 

  P3=tab[cnta] 

  P1=digittab[cntb][cnta] 

  cnta++ 

  if(cnta==8) 

    { 

      cnta=0 

    } 

  timecount++ 

  if(timecount==333) 

    { 

      timecount=0 

      cntb++ 

      if(cntb==10) 

        { 

          cntb=0 

        } 

    } 

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11106245.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存