首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DE1-SoC显示LED

DE1-SoC显示LED
EN

Stack Overflow用户
提问于 2020-05-18 10:42:49
回答 1查看 97关注 0票数 0

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

这是我的代码。

代码语言:javascript
复制
#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);
    }
}

这是我引用的函数的代码。

代码语言:javascript
复制
#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

EN

回答 1

Stack Overflow用户

发布于 2020-05-19 03:51:17

您已经将c定义为char*,而它显然应该是一个char

代码语言:javascript
复制
char c ;

然后松开*c引用:

代码语言:javascript
复制
*LED_ptr = c ;
put_jtag(JTAG_UART_ptr, c);

这行代码:

代码语言:javascript
复制
 c = get_jtag(JTAG_UART_ptr);

应该已经发出警告了,以GCC为例,输出:

代码语言:javascript
复制
warning: initialization makes pointer from integer without a cast [-Wint-conversion]

不要忽略(或禁用)警告;至少不要忽略它们,然后在这里提问,而不是提到警告。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61861623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档