I am trying to use the DE1-SoC board to run this program. It is supposed to allow the user to input a character, and return that letter in binary on red LEDs on the board. It uses two functions that take in user input and displays the execution to the terminal. When I run the program, random characters (like å) get output and not regular characters.
Here's my code.
#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);
}
}
This is the code for the functions I referenced.
#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');
}
Inputting a character like 'a' which is the decimal number 97 in ASCII. Should display itself as 01100001 with each '1' representing itself lit up on the board. As I stated I'm having a logic error, while input is being read 'a' would appear as 00010000
You have defined c
as a char*
when it should clearly be a char
.
char c ;
Then loose the *c
de-references:
*LED_ptr = c ;
put_jtag(JTAG_UART_ptr, c);
The line:
c = get_jtag(JTAG_UART_ptr);
should have issued a warning; GCC for example outputs:
warning: initialization makes pointer from integer without a cast [-Wint-conversion]
Do not ignore (or disable) warnings; at least don't ignore them then ask a question here without mentioning the warning.
User contributions licensed under CC BY-SA 3.0