DE1-SoC显示LED

问题描述 投票:0回答:1

我正在尝试使用DE1-SoC板来运行该程序。它应该允许用户输入一个字符,然后在板上的红色LED上以二进制形式返回该字母。它使用两个函数来接受用户输入,并将执行结果显示给终端。当我运行程序时,随机字符(如å)会得到输出,而不是常规字符。

这是我的代码。

#include "JTAG_UART.h"
#include "address_map_arm.h"

int main(void) {
    /* Declare volatile pointers to I/O registers (volatile means that IO load
       and store instructions will be used to access these pointer locations,
       instead of regular memory loads and stores) */
    volatile int * JTAG_UART_ptr = (int *)JTAG_UART_BASE; // JTAG UART address
volatile int * LED_ptr = (int*)LED_BASE;
    char  text_string[] = "\nJTAG UART example code\n> \0";
    char *str, * c;
  //  char *c_ptr=c;

    /* print a text string */
    for (str = text_string; *str != 0; ++str)
        put_jtag(JTAG_UART_ptr, *str);

    /* read and echo characters */
    while (1) {
        c = get_jtag(JTAG_UART_ptr);
         if (c != 0 && c<123 && c>96){
         *LED_ptr = *c ;
         put_jtag(JTAG_UART_ptr, *c);
        }
           // put_jtag(JTAG_UART_ptr, c);
    }
}

这是我引用的功能的代码。

#include "JTAG_UART.h"

/*******************************************************************************
 * Subroutine to send a character to the JTAG UART
 ******************************************************************************/
void put_jtag(volatile int * JTAG_UART_ptr, char c) {
    int control;
    control = *(JTAG_UART_ptr + 1); // read the JTAG_UART control register
    if (control & 0xFFFF0000)       // if space, echo character, else ignore
        *(JTAG_UART_ptr) = c;
}

/*******************************************************************************
 * Subroutine to read a character from the JTAG UART
 * Returns \0 if no character, otherwise returns the character
 ******************************************************************************/
char get_jtag(volatile int * JTAG_UART_ptr) {
    int data;
    data = *(JTAG_UART_ptr); // read the JTAG_UART data register
    if (data & 0x00008000)   // check RVALID to see if there is new data
        return ((char)data & 0xFF);
    else
        return ('\0');
}

输入像'a'这样的字符,它是ASCII中的十进制数字97。应该将自己显示为01100001,并在板上显示每个代表其自身的'1'。正如我所说的,我遇到逻辑错误,而读取输入时,“ a”将显示为00010000

c pointers embedded intel fpga
1个回答
1
投票

您已经明确地将c定义为char*时将其定义为char

char c ;

然后松开*c取消引用:

*LED_ptr = c ;
put_jtag(JTAG_UART_ptr, c);

行:

 c = get_jtag(JTAG_UART_ptr);

应该发出警告; GCC的示例输出:

warning: initialization makes pointer from integer without a cast [-Wint-conversion]

请勿忽略(或禁用)警告;至少不要忽略他们,然后在不提警告的情况下在这里提问。

© www.soinside.com 2019 - 2024. All rights reserved.