• 实验8 LCD8*8点阵


    1.控制点阵红绿交替显示,分别从上到下,从左到右循环闪烁三次

    接线:

    P0J12P1J20P2J19

    /**

    1.控制点阵红绿交替显示,分别从上到下,从左到右循环闪烁三次

    **/

     

    #include <REG51.H>

     

    unsignedchar code table_LeftRight[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

    unsignedchar code table_TopBottom[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

    enum DisplayDirecte{

        Left2Right,

        Right2Left,

        Top2Bottom,

        Bottom2Top

    };

     

    void delay(void)

    {

        unsignedchar i,j,k;

     

        for(k=10;k>0;k--)

        for(i=20;i>0;i--)

        for(j=248;j>0;j--);

     

    }

     

    /***********************************************************

        显示的规则

    ***********************************************************/

    void DisplayRule(enum DisplayDirecte displayDirecte,unsignedchar index){

        switch(displayDirecte){

           case Left2Right:

               P2=table_LeftRight[index];

               P0=0xff;

               P1=0xff;

           break;

     

           case Right2Left:

               P1=table_LeftRight[7-index];

               P0=0xff;

               P2=0xff;

           break;

          

           case Top2Bottom:

               P2=0x00;

               P1=0xff;

               P0=table_TopBottom[7-index];

           break;

          

           case Bottom2Top:

               P1=0x00;

               P2=0xff;

               P0=table_TopBottom[index];

           break;

        }

    }

    /***********************************************************

        显示3

    ***********************************************************/

    void Display3Time(enum DisplayDirecte displayDirecte){

        unsignedchar i,RepeatTime;

        for(RepeatTime=0;RepeatTime<3;RepeatTime++)//控制重复的次数

        {

           for(i=0;i<8;i++)                  

           {

               DisplayRule(displayDirecte,i);

               delay();

           }

        }

    }

    void main(void)

    {

        while(1)

        {

          

           Display3Time(Left2Right);

           Display3Time(Right2Left);

           Display3Time(Top2Bottom);

           Display3Time(Bottom2Top);

       }

    }

     

    2.自行编码,控制LCD显示0~F或一些简单汉字(红绿交替显示)

    3./*****************************************************************************************

    4.2.自行编码,控制LCD显示0~F或一些简单汉字(红绿交替显示)     

    5.******************************************************************************************/

    #include<reg51.h>

    #define Lenth 19

    unsignedchar code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//列选通

     

    unsignedchar code digittab[Lenth][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

     

    {0x00,0x00,0x7F,0x48,0x48,0x30,0x00,0x00},//P

     

    {0x00,0x00,0x7F,0x48,0x4C,0x73,0x00,0x00},//R

     

    {0x00,0x00,0x7F,0x49,0x49,0x49,0x00,0x00},//E

     

    {0x00,0x00,0x3E,0x41,0x41,0x62,0x00,0x00},//C

     

    {0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00},//H

     

    {0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00},//I

     

    {0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00},//N

     

    {0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00},  //

     

    {0x18,0x24,0x42,0x21,0x42,0x24,0x18,0x00}  //心形

    };

     

    unsignedint timecount1 , timecount2;

     

    unsignedchar cntx , cnty ;

     

    void main(void)

    {

      cnty=0;

       

      while(1)

      {

         if(cnty<Lenth)//红色

        {

         P1=0xFF;

         P2=tab[cntx];  // 列线

         P0=digittab[cnty][cntx];   // 行线

        }

        else//绿色

        {

         P2=0xFF;

         P1=tab[cntx];   // 列线

         P0=digittab[cnty-Lenth][cntx];  // 行线

        }

     

       //用于控制动态扫描的速度

        if(++timecount1>=50)

        {

         timecount1=0;

         if(++cntx>=8) cntx=0;

        }

     

       //用于控制动字符间的切换速度

        if(++timecount2>=20000)

        {

         timecount2=0;

         if(++cnty>=Lenth*2)cnty=0;

        }

      }

     

    }

     

     

     

  • 相关阅读:
    安全测试的概述和用例设计
    性能测试(四)常见调优
    性能测试(三)常见的性能测试缺陷
    Jmeter(七)六种参数化的方式
    Jmeter(六)所有的断言
    接口测试的问题解答
    ES学习
    flutter 之BottomNavigationBar属性
    flutter StaggeredGridView.countBuilder 上方取消空白
    flutter升级、回退到指定版本---mac版
  • 原文地址:https://www.cnblogs.com/kissazi2/p/3174560.html
Copyright © 2020-2023  润新知