SOPC课程设计--万年历(共15页)_第1页
SOPC课程设计--万年历(共15页)_第2页
SOPC课程设计--万年历(共15页)_第3页
SOPC课程设计--万年历(共15页)_第4页
SOPC课程设计--万年历(共15页)_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上 SOPC课程设计实验报告 万年历 学院: 专业: 学号: 姓名: 指导老师: 2012/06/04一、摘要本文介绍了一种基于片上可编程系统(SOPC)设计万年历的方法。本次设计从系统硬件出发,由CPU,总线,RAM,外接设备等构成SOPC Builder的硬件系统,通过Nios II DE2开发的嵌入式软件编写并嵌入SOPC Builder的硬件中实现万年历的整体开发。通过应用SoPC Builder开发工具,设计者可以摆脱传统的、易于出错的软硬件设计细节,从而达到加快项目开发、缩短开发周期、节约开发成本的目的并具有高集成度、设计灵活和可移植性较好。关键词:万年历

2、SOPC SOPC Builder Nios II DE2二、设计要求 用Nios II DE2 开发板的LCD显示电子钟的日期和时间。LCD分两行显示,第1行显示年、月、日;第2行显示时、分、秒。用输入BUTTON0来控制LCD行的修改,同时让Nios II DE2开发板上的绿色发光二极管亮灭来表示这个选择。当BUTTON0按一下后,LEDG3亮,可以修改年、月和日的数字;再按一下BUTTON0后,LEDG3灭,可以修改时、分和秒的数字。另外用输入按钮BUTTON3来控制日期和时间的修改,当处于日期修改方式时,每次按动一次BUTTON3,依次更换“年”、“月”和“日”的修改。当处于时间修改方

3、式时,每次按动一次BUTTON3,依次更换“时”、“分”和“秒”的修改。修改对象被选中后,按动BUTTON2输入按钮可以增加显示的数字;按动BUTTON1输入按钮可以减少显示的数字。三、设计内容1、按键信息BUTTON3:“年”、“月”、“日”或“时”、“分”、“秒”切换键BUTTON2:+键BUTTON1:-键BUTTON0:“年”、“月”、“日”与“时”、“分”、“秒”切换键显示信息LCD_Line1:显示“年”、“月”、“日” LCD_Line1:显示“时”、“分”、“秒”2、SOPC Builder 硬件建立 SOPC Builder是在Quartus II里的SOPC Builder

4、进行的,先建立工程,在SOPC Builder里添加硬件,包括CPU ,jtag_uart ,RAM,LCD,PIO,按键,LED,以及LCD_ON。3、Quartus II硬件处理 硬件会自动建立一个顶层模块,通过建一个原理图来对对应的硬件进行输入输出的添加,再锁定引脚,编译工程,硬件下载。 4、Nios II DE2嵌入软件编写 在Nios II里建立工程,选择相应的模块,编写需要嵌入的软件,添加缺少的头文件对应的宏定义,编译工程,进行软件下载,在观察结果。四、设计步骤1、打开Quartus II新建工程2、打开SOPC Builder生成相应的硬件如图所示 建立好后点击Generate运

5、行,看是否出错,然后点击exit退出。 3、调用刚才生成的硬件系统,在Quartus II中建立图形文件,然后进行引脚锁定。引脚锁定引脚文件如下:#Setup.tcl#Setup pin settingset_global_assignment -name RESERVE_ALL_UNUSED_PINS "AS INPUT TRI-STATED"set_global_assignment -name ENABLE_INIT_DONE_OUTPUT OFFset_location_assignment PIN_N2 -to clkset_location_assignment

6、 PIN_V18 -to led3set_location_assignment PIN_W19 -to led2set_location_assignment PIN_AF22 -to led1set_location_assignment PIN_AE22 -to led0set_location_assignment PIN_W26 -to KEY3set_location_assignment PIN_P23 -to KEY2set_location_assignment PIN_N23 -to KEY1set_location_assignment PIN_G26 -to KEY0s

7、et_location_assignment PIN_K4 -to LCD_RWset_location_assignment PIN_K3 -to LCD_ENset_location_assignment PIN_K1 -to LCD_RSset_location_assignment PIN_L4 -to LCD_ONset_location_assignment PIN_J1 -to LCD_DATA0set_location_assignment PIN_J2 -to LCD_DATA1set_location_assignment PIN_H1 -to LCD_DATA2set_l

8、ocation_assignment PIN_H2 -to LCD_DATA3set_location_assignment PIN_J4 -to LCD_DATA4set_location_assignment PIN_J3 -to LCD_DATA5set_location_assignment PIN_H4 -to LCD_DATA6set_location_assignment PIN_H3 -to LCD_DATA7 然后进行编译,在Quartus I下生成文件如下图:4、 Nios II运行打开Nios II IDE2,建立工程,选择count_binary模块,添加一个LCD.h

9、的顶层文件。LCD.h的顶层文件为:#ifndef _LCD_H_#define _LCD_H_/LCD Module 16*2#define lcd_write_cmd(base,data) IOWR(base, 0, data)#define lcd_read_cmd(base) IORD(base, 1)#define lcd_write_data(base,data) IOWR(base, 2, data)#define lcd_read_data(base) IORD(base, 3)/=void LCD_Init();void LCD_Show_Text(char*Text);vo

10、id LCD_Line2();void LCD_Test();/=#endif /_LCD_H_然后建立count_binary的C+文件。C+文件见附件。5、 连接开发板,将文件下载到开发板,运行文件检验是否正确。6、 检查错误并修改,知道结果正确。 五、运行情况与问题分析1、建立工程时,注意不能出现中文或者空格,且工程名需与文件名一致,选定芯片;2、在生成CPU硬件系统时,定义端口时,需注意设定端口输入与输出的位宽,需与程序定义的数值一致,否则运行溢出报错,须修改;3、建立图形文件后,需进行编译,出现错误得返回原理图核对,找到错误修改后重新编译;4、进行引脚锁定时,注意引脚文件的编写,否则

11、选择引脚文件点击Run后会不成功,从而影响后面程序的调试; 5、当日数为31时,调节月份日期不会随机改变,就会出现4月31日等错误,加入程序段但是还是没有完成跳变; 6、程序中闪烁程序段、跳变程序段不执行,程序还需后续修改。 六、结论采用NIOS集成开发环境提供的快捷开发手段,在Cyclone 1C6Q240C8芯片上创建了一个用户定制CPU和外设的片上系统,同时完成对液晶显示器和LED的编程控制。整个系统充分体现了SOPC设计方法的灵活性,设计时只定制系统需要的外设器件接口,避免过多的外围电路和器件造成体积、功耗的增多和可靠性的下降。由于采用软核结构,方便系统的升级和扩展,而不必硬件改版,节

12、约了成本,加快开发进度,缩短了产品的开发周期。综上所述,万年历的设计思想新颖独特,有很多创新之处。 七、心得体会 经过本次SOPC课程设计实验,使我更加熟悉了Quartus 与Nios DE2以及开发板的使用,熟练掌握了从理论设计到硬件开发的流程,了解了万年历通过编程实现的整个过程。从整个实验实现的过程中,碰到一些以前未出现过的问题,在自己的努力以及同学、老师的帮助下,使自己的理论及操作水平有所提高,在此我要郑重感谢指导老师黄乡生。附 件C+程序代码如下:#include "alt_types.h"#include <stdio.h>#include <s

13、tring.h>#include <unistd.h>#include "system.h"#include "sys/alt_irq.h"#include "altera_avalon_pio_regs.h"/#include"count_binary.h"#include "LCD.h"#include "io.h"/#include "basic_io.h"volatile int edge_capture;void LCD_Ini

14、t() lcd_write_cmd(LCD_BASE,0x38); usleep(2000); lcd_write_cmd(LCD_BASE,0x0C); usleep(2000); lcd_write_cmd(LCD_BASE,0x01); usleep(2000); lcd_write_cmd(LCD_BASE,0x06); usleep(2000); lcd_write_cmd(LCD_BASE,0x80); usleep(2000);void LCD_Show_Text(char*Text) int i; for(i=0;i<strlen(Text);i+) lcd_write_

15、data(LCD_BASE,Texti); usleep(2000); void LCD_Line1() lcd_write_cmd(LCD_BASE,0x80); usleep(2000);void LCD_Line2() lcd_write_cmd(LCD_BASE,0xC0); usleep(2000);static void handle_button_interrupts(void*context,alt_u32 id) volatile int*edge_capture_ptr=(volatile int*)context; *edge_capture_ptr=IORD_ALTER

16、A_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE,0);static void init_button_pio() void *edge_capture_ptr=(void*)&edge_capture; IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE,0xf); IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE,0x0); alt_irq_register(BUTTO

17、N_PIO_IRQ,edge_capture_ptr,handle_button_interrupts);void delay(unsigned int x) while(x-);int check_month(int month) if(month=1)|(month=3)|(month=5)|(month=7) |(month=8)|(month=10)|(month=12) return 1; else if(month=4)|(month=6)|(month=9)|(month=11) return 0; else /if(month=2) return 2;int check_yea

18、r(int year) if(year%400)=0)|(year%4)=0)&&(year%100)!=0) return 1; /是闰年,返回1 else return 0; /不是闰年,返回0int main (void) _attribute_ (weak, alias ("alt_main");int alt_main (void)/int main(void) int screen=0; int pos=0;/每行都有三个位置,第一行是年月日,第二行是时分秒 int i=0;/定义半秒标志位 int year,month,day,hour,min

19、ute,second; unsigned long sum; char date16; char time16; int year1=16; int year2=0; int year3=0; int year4=2; int month1=1; int month2=0; int day1=1; int day2=0; int hour4,hour3,hour2,hour1,minute2,minute1,second2,second1; unsigned int screenflag; hour=0;minute=0;second=0;year=2006;month=1;day=1; /年

20、月日时分秒初始化 alt_irq_init(ALT_IRQ_BASE); /使能中断 (很重要,相对于总的中断开关) init_button_pio(); IOWR_ALTERA_AVALON_PIO_DATA(LCD_ON_BASE,1); LCD_Init(); while(1) if(pos>=3) pos=0; if(screen>=2) screen=0; /na_LED8->np_piodata=1<<pos; if(screen=0) IOWR_ALTERA_AVALON_PIO_DATA(LEDG_BASE,0x2); else IOWR_ALTE

21、RA_AVALON_PIO_DATA(LEDG_BASE,0x0); usleep();/等待半秒的定时时间 if(i=0) i=1; else i=0; if(i=0) if(second<59) second+; else second=0; if(minute<59) minute+; else minute=0; if(hour<23) hour+; else hour=0; if(day<30) day+; else day=1; if (month<12) month+; else month=1; if(year<9999) year+; el

22、se year=2005; switch (edge_capture) /检测按钮 case 0x08: pos=pos+1; break; /改变调整位置 case 0x02: if (pos=0) if(screen=0) if (day>1) day-; else if (check_month(month)=0) day=30; if (check_month(month)=1) day=31; if (check_month(month)=2) if(check_year(year)day=29; else day=28; if (screen=1) if(second>

23、0) second-; else second=59; else if(pos=1) if(screen=0) if(month>1) month-; else month=12; if(day=31) if(month=4|month=6|month=9|month=11) day=30; else if (month=2) if(year%400)=0)|(year%4)=0)&&(year%100)!=0) day=29; else day=28; else day=31; if(screen=1) if(minute>0) minute-; else min

24、ute=59; if(pos=2) if(screen=0) if (year>0) year-; else year=2005; if (screen=1) if (hour>0) hour-; else hour=23; break; case 0x04: if (pos=0) if (screen=0) if(check_month(month)=0) if(day<30) day+; else day=1; else if (check_month(month)=1) if (day<31) day+; else day=1; else if(check_mon

25、th(month)=2) if (check_year(year) if(day<29) day+ ; else day=1; else if (day<28) day+ ; else day=1; else if(screen=1) if(second<59) second+; else second=0; else if (pos=1) if(screen=0) if (month<12) month+; else month=1; if(day=31) if(month=4|month=6|month=9|month=11) day=30; else if (mo

26、nth=2) if(year%400)=0)|(year%4)=0)&&(year%100)!=0) day=29; else day=28; else day=31; /* else if (screen=1) if (month<12) month+; else month=1; */ else if(screen=1) if (minute<59) minute+; else minute=0; if(pos=2) if (screen=0) if (year<9999) year+; else year=2005; else if (screen=1)

27、 if (hour<23) hour+; else hour=0; break; case 0x01: screen+; break; /换屏 edge_capture=0; year4=year/1000; year3=(year-year4*1000)/100; year2=(year-year4*1000-year3*100)/10; /year2=year-year4*1000-year3*100)/10; year1=year%10; month2=month/10; month1=month%10; day2=day/10; day1=day%10; LCD_Line1();

28、 date0=year4+0x30;date1=year3+0x30; date2=year2+0x30;date3=year1+0x30; date4=' ' date5=' ' date6=month2+0x30; date7=month1+0x30; date8=' 'date9=' ' date10=day2+0x30;date11=day1+0x30; date12=' ' date13=' ' date14=' 'date15=' ' LCD_Show_Text(date); hour4=0;hour3=0; hour2=hour/10;hour1=hour%10; minute2=minute/1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论