- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i have a developed a program on interrupt of getting a character ahead of one on hyperterminal (eg: a gives me b, b gives me c etc. ) now i have to develop a programin which i store my name and print it unil \n function is used.i was told to use a put string function and then proceed again.. but i m very new to programming and i have to submit my project in less than 2 days.. please help what to add and where. ?
sharing the program with you all.. please help me??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is my solution without using interrupts.
#include "project.h"
int main(void) {
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
UART_CMD_Start();
for (;;) {
uint32 ch = UART_CMD_UartGetChar();
if (ch == 0) continue; // No character gotten.
if (ch != '\n') {
UART_CMD_UartPutChar(ch + 1);
} else {
UART_CMD_UartPutString("\r\n");
break;
}
}
for (;;) {
/* Place your application code here. */
}
}
Get a character in the variable ch and put an incremented code character (ch + 1) There is no need to use the interrupt.
Please let me know why are you going to use interrupts for this application.
Regards,
Noriaki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Then a simple sample using interrupt.
(I'm using CY8CKIT-044)
schematic
pins
Tera Term log
main.c
==================
#include "project.h"
#define EOL '\n'
#define CR '\r'
#define STR_LEN 64
char str[STR_LEN+1] ; /* 1 for NULL */
volatile int rx_index = 0 ;
volatile int str_received = 0 ;
CY_ISR(rx_isr)
{
UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY) ;
if (str_received) { /* previous str has not been taken care of */
return ;
}
if (UART_SpiUartGetRxBufferSize()) { /* something in the buffer */
str[rx_index] = UART_UartGetByte() ;
if ((str[rx_index] == EOL)||(str[rx_index] == CR)) { /* end of line detected */
str[rx_index] = 0 ;
rx_index = 0 ;
str_received = 1 ;
return ;
}
rx_index++ ;
if (rx_index >= STR_LEN) { /* str buffer over flow */
str[STR_LEN] = 0 ;
rx_index = 0 ;
str_received = -1 ;
return ;
}
}
}
void prompt(void)
{
UART_UartPutString("> ") ;
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
isr_1_ClearPending() ;
isr_1_StartEx(rx_isr) ;
UART_Start() ;
prompt() ;
for(;;)
{
if (str_received) {
UART_UartPutString(str) ;
UART_UartPutString("\n\r") ;
prompt() ;
str_received = 0 ;
}
}
}
==================
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And if you have used my tty_utils library, it would have been like below.
(Although may not be good for an assignment.)
main.c
===================
#include "project.h"
#include "tty_utils.h"
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
tty_init() ;
prompt() ;
for(;;) {
if (get_line()) { // got a line
print(str) ;
print("\n") ;
prompt() ;
}
}
}
===================
Tera Term log
schematic
pins
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is my solution without using interrupts.
#include "project.h"
int main(void) {
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
UART_CMD_Start();
for (;;) {
uint32 ch = UART_CMD_UartGetChar();
if (ch == 0) continue; // No character gotten.
if (ch != '\n') {
UART_CMD_UartPutChar(ch + 1);
} else {
UART_CMD_UartPutString("\r\n");
break;
}
}
for (;;) {
/* Place your application code here. */
}
}
Get a character in the variable ch and put an incremented code character (ch + 1) There is no need to use the interrupt.
Please let me know why are you going to use interrupts for this application.
Regards,
Noriaki