8段数码管显示电路
共阳极的数码管0~f的段编码是这样的:
unsigned char code table[]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
共阴极的数码管0~f的段编码是这样的:
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
2.
2.2 配置存储器
memories and memory controllers >> On-chip >>On-chip memory(RAM or ROM)
1.ROM
2. RAM
2.3配置并行输入/输出端口
peripherals >>microcontroller peripherals >> PIO(Parallel I/O)
2.4 重命名ram、rom、pio
2.5 软核处理器复位矢量和异常矢量的设置
2.6 分配系统各部分地址和中断
2.7 生成软核处理器系统
3.Nios 软核处理器系统产生
3.1 在原理图上insert>>Symbol>>project(选中seg7)
3.2 右键单击电路符号>>Generate Pins for Symbol Ports(自动生成引脚,这里可以更改自己想要的命名)
3.3 assignments >> settings >> analysis& synthesis settings :Optimization Technique 选中area
3.4 assignments>>device >>device and pin options>>Unused pins: Reserve all unused pins选中 As input tri-stated
3.5编译后分配引脚
4.编译下载
5.编写软件
#include "system.h"
#include "altera_avalon_pio_regs.h"
void delay(void);
void seg7(unsigned char x);
int alt_main(void)
{
unsigned char data_seg7;
while(1)
{
for(data_seg7=0;data_seg7<0x10;data_seg7++)
{
seg7(data_seg7);
delay();
}
}
return 0;
}
void seg7(unsigned char x)
{
unsigned char code_table[]=
{0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,
0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e};
unsigned char code_seg7;
code_seg7=code_table[x];
IOWR_ALTERA_AVALON_PIO_DATA(SEG7_PIO_BASE,code_seg7);
}
void delay(void)
{
unsigned int i;
i=1000000;
while(i>0)
{
i--;
}
}