注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

东月之神

在单纯的观念里面,生命就容易变得比较深刻!

 
 
 

日志

 
 
关于我

别驻足,梦想要不停追逐,别认输,熬过黑暗才有日出,要记住,成功就在下一步,路很苦,汗水是最美的书!

网易考拉推荐

基于SOPC的数码管+矩阵键盘  

2011-08-19 13:10:06|  分类: FPGA |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#include <stdio.h>

#define seg *(volatile unsigned char *) SEG_BASE
#define bit *(volatile unsigned char *) BIT_BASE
#define row *(volatile unsigned char *) ROW_BASE
#define column *(volatile unsigned char *) COLUMN_BASE
 
int main (void) __attribute__ ((weak, alias("alt_main")));


void delay(int z)
{
    int x, y;
    for(y = z; y > 0; --y)
        for(x = 110; x > 0; --x);
}

int alt_main(void)
{
     const unsigned char table[16] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
                                      0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
     unsigned char temp, num = 0;
      bit = 0;
     //alt_u8 row, column;
     //IOWR_ALTERA_AVALON_PIO_DATA(BIT_BASE, bit);
     while(1)
     {              
         column = 0x0e;
         temp = row;
         temp = temp & 0x0f;
         if(temp != 0x0f)
         {
              delay(100);
              if(temp != 0x0f)
              {
                    //printf("%d\n", temp);
                delay(10000);
                switch(temp)
                {
                   case 0x0e: num = 0; break;
                   case 0x0d: num = 1; break;
                   case 0x0b: num = 2; break;
                   case 0x07: num = 3; break;
                }  
                while(temp != 0x0f)
                {
                    temp = row;
                    temp = temp & 0x0f;
                }
                seg = table[num];                
              }
         }
        
         column = 0x0d;
         temp = row;       
         temp = temp & 0x0f;
         if(temp != 0x0f)
         {
              delay(100);
              if(temp != 0x0f)
              {
                //printf("%d\n", temp);
                delay(10000);
                switch(temp)
                {
                   case 0x0e: num = 4; break;
                   case 0x0d: num = 5; break;
                   case 0x0b: num = 6; break;
                   case 0x07: num = 7; break;
                }
                while(temp != 0x0f)
                {
                    temp = row;
                    temp = temp & 0x0f;
                }
                seg = table[num];                  
              }  
          }    
         
         column = 0x0b;
         temp = row;       
         temp = temp & 0x0f;
         if(temp != 0x0f)
         {
              delay(100);
              if(temp != 0x0f)
              {
                //printf("%d\n", temp);
                delay(10000);
                switch(temp)
                {
                   case 0x0e: num = 8; break;
                   case 0x0d: num = 9; break;
                   case 0x0b: num = 10; break;
                   case 0x07: num = 11; break;
                }
                while(temp != 0x0f)
                {
                    temp = row;
                    temp = temp & 0x0f;
                }
                seg = table[num];                  
              }  
          }  
         
         column = 0x07;
         temp = row;       
         temp = temp & 0x0f;
         if(temp != 0x0f)
         {
              delay(100);
              if(temp != 0x0f)
              {
                //printf("%d\n", temp);
                delay(10000);
                switch(temp)
                {
                   case 0x0e: num = 12; break;
                   case 0x0d: num = 13; break;
                   case 0x0b: num = 14; break;
                   case 0x07: num = 15; break;
                }
                while(temp != 0x0f)
                {
                    temp = row;
                    temp = temp & 0x0f;
                }
                seg = table[num];                  
              }  
         }                  
     }
   return 0;
}

  评论这张
 
阅读(68)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017