⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_all.c

📁 niosii c程序 niosii c程序
💻 C
字号:
#include "alt_types.h"
#include <stdio.h>
#include <unistd.h>
#include "system.h"
#include "sys/alt_irq.h"
#include "altera_avalon_pio_regs.h"

#define ESC 27
#define ESC_TOP_LEFT "[1;0H"
#define ESC_COL2_LEFT "[2;0H"
#define ESC_COL1_INDENT5 "[1;5H"
#define ESC_CLEAR "K"
volatile int edge_capture;
//----------button_capture-------------------------------
#ifdef BUTTON_PIO_BASE
static void handle_button_interrupts(void* context, alt_u32 id)
{
  volatile int* edge_capture_ptr = (volatile int*) context;
  /* Store the value in the Button's edge capture register in *context. */
  *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE);
  /* Reset the Button's edge capture register. */
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);
}
//---------------Initialize the button-----------------
static void init_button_pio()
{
  void* edge_capture_ptr = (void*) &edge_capture;
  /* Enable all 4 button interrupts. */
  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf);
  /* Reset the edge capture register. */
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0);
  /* Register the interrupt handler. */
  alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr, handle_button_interrupts ); 
}
#endif
//--------------------clear_lcd-----------------
void clear(FILE *lcd)
{
  fprintf(lcd,"%c%s\n",ESC,ESC_CLEAR);
  fprintf(lcd,"%c%s\n",ESC,ESC_CLEAR);
}
//------------------main---------------------------
int main(void)
{ 
/* Declare variables used only in main() */
FILE * lcd;
FILE * fp;
init_button_pio();
fp=fopen("/dev/uart", "w");
lcd=fopen("/dev/lcd_16207","w");
printf("\n*************************************\n");
printf("Hello to red logic world!\n");
printf("welcome to use the CY1C12 board\n");
printf("this is the flash progammer show\n");
printf("*************************************\n");
clear(lcd);
fprintf(fp,"wait for switch select...\n");
fprintf(lcd,"%c%swait switch mode       ",ESC,ESC_TOP_LEFT);
edge_capture=0; 
while(1)
{
  switch(edge_capture)
  {
    case 0x1:
    fprintf(fp,"welcome to red logic world\n");
    clear(lcd);
    fprintf(lcd,"%c%sred logic        ",ESC,ESC_TOP_LEFT);
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0x1);
    edge_capture=0;
    break;
    case 0x2:
    clear(lcd);
    fprintf(fp,"welcome to use the CY1C12 board\n");
    fprintf(lcd,"%c%sCY1C12 board       ",ESC,ESC_TOP_LEFT);
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0x3);
    edge_capture=0;
    break;
    case 0x4:
    clear(lcd);
    fprintf(fp,"this is the flash progammer show\n");
    fprintf(lcd,"%c%sflash progammer       ",ESC,ESC_TOP_LEFT);
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0x7);
    edge_capture=0;
    break;
    case 0x8:
    clear(lcd);
    fprintf(fp,"this is the uart transmit test\n");
    fprintf(lcd,"%c%sLCD Displaying..       ",ESC,ESC_TOP_LEFT);
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0xf);
    edge_capture=0;
    break;
  }
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -