zoukankan      html  css  js  c++  java
  • 数码管左移

    #include<reg52.h>
    
    sbit LATCH1=P2^2;//段锁存
    sbit LATCH2=P2^3;//位锁存
    
    unsigned char code DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// 显示段码值0~9
    unsigned char code WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分别对应相应的数码管点亮,即位码
    unsigned char TempData[10]; //存储显示值的数组
    
    void Delay(unsigned int t); //函数声明
    void Display(unsigned char FirstBit,unsigned char Num);
    
    main()
    {
      unsigned int i,k,j;
      unsigned char s;
      while(1)
      {
        j++;
        if(j==20)  // 控制显示一定时间 
        {
          j=0;
          if(0==k)
          {
            for(s=0;s<10;s++) //完全循环完成后清零所有缓冲区
              TempData[s]=0;
          }
          TempData[8-i]=DuanMa[k]; //把需要显示的字符依次送缓冲区
          TempData[8+1-i]=0; //不需要显示的区域清零
          if(i==(8-k))
          {
            i=0;
            k++;
            if(k==8)
              k=0;
          }
          i++;
        }
        Display(
    0,8);//从第一位显示,共显示8位   } } void Delay(unsigned int t) {   while(--t); } void Display(unsigned char FirstBit,unsigned char Num) {   unsigned char i;   for(i=0;i<Num;i++)   {     P1=0; //清空数据,防止有交替重影     LATCH1=1; //段锁存     LATCH1=0;     P1=WeiMa[i+FirstBit]; //取位码     LATCH2=1; //位锁存     LATCH2=0;     P1=TempData[i]; //取显示数据,段码     LATCH1=1; //段锁存     LATCH1=0;     Delay(200); // 扫描间隙延时,时间太长会闪烁,太短会造成重影   } }

     通过将后一位赋值给前一位,达到向左移动,上面的代码逻辑比较复杂,记录下来慢慢看,先学下一个知识点了。

  • 相关阅读:
    一些恶作剧的vbs程序代码
    The Weather
    UEditor (富文本编译器)
    Redis 存储数组
    QQ第三方登录(完结篇)
    QQ第三方登录(预备节)
    谷歌浏览器添加JSON-Handle插件
    Nginx 之防盗链配置
    noi,ac第五场部分题解 By cellur925
    NOIp2002神经网络 【拓扑排序】By cellur925
  • 原文地址:https://www.cnblogs.com/coloregg/p/3588685.html
Copyright © 2011-2022 走看看