I got it partially working, but I it was kind of messy. So I reorganized the code, but haven't got it working since.
I've tried in the numcheck function
Code:
while(character !='1' || .... character !='9' || character !='d')
also tried with converting it to decimal using
Code:
character = character - 48;
then using
while((0 > character > 10) || character !='d')
I then resorted to this, still no luck. The program will recognize the d to disalble the program now, but still gives invalid character for anything else.
Code:
/* Serial Communication exercise on the Axiom CME11E9 EVBU and PC. */
/* A character is entered on the keyboard in terminal mode and it */
/* is returned to the terminal by the EVB over COM1 with a message */
/* stating whether it is even or odd and prompting another entry. */
/* */
/****************************************************************************/
/* Includes (libraries) */
/****************************************************************************/
#include <hidef.h>
/****************************************************************************/
/* Definitions */
/****************************************************************************/
#define baud *(volatile unsigned char *)0x102B /* baud rate reg. */
#define sccr1 *(volatile unsigned char *)0x102C /* sci cont. reg. 1 */
#define sccr2 *(volatile unsigned char *)0x102D /* sci cont. reg. 2 */
#define scsr *(volatile unsigned char *)0x102E /* sci status reg. */
#define scdat *(volatile unsigned char *)0x102F /* sci data reg. */
#define tdre 0x80 /* transmit mask bit */
#define rdrf 0x20 /* receive mask bit */
/*****************************************************************************/
/* Declarations (variables and function prototypes) */
/*****************************************************************************/
char input(void);
void onsci(void);
void numcheck(void);
void oncheck(void);
void output(char);
void outcrlf(void);
void outstr(char *strg);
char Msg1[] = "Enter a number...";
char Msg2[] = "Enter another number..";
char Msg3[] = "... is an odd number";
char Msg4[] = "... is an even number";
char Msg5[] = "The Evaluator Is Off, Press 'e' To Enable It";
char Msg6[] = "The Evaluator Is On, Press 'd' To Disable It";
char Msg7[] = "You entered an invalid character, please try again!";
char character;
/*****************************************************************************/
/* Main */
/*****************************************************************************/
void main(void)
{
EnableInterrupts;
onsci();
outstr(Msg5);
outcrlf();
oncheck();
while(1)
{
outstr(Msg6);
outcrlf();
outstr(Msg1);
outcrlf();
while(1)
{
numcheck();
output(character);
if (character !='d')
{
if ((character & 0x01) == 0 )
{
outstr(Msg4);
}
else
{
outstr(Msg3);
}
outcrlf();
outstr(Msg2);
outcrlf();
outcrlf();
}
else
{
outcrlf();
main();
}
}
}
}
/****************************************************************************/
/****************************************************************************/
/* Locally Defined Functions */
/****************************************************************************/
void oncheck(void)
{
character = input();
while(character != 'e')
{
outstr(Msg7);
outcrlf();
character = input();
}
}
void numcheck(void)
{
character = input();
character = character -48;
while((0 > character > 9) || character != 'd')
{
outstr(Msg7);
outcrlf();
character = input();
}
}
/****************************************************************************/
void outstr(char *strg) /* Output a string of characters */
{ /* String ends in NULL */
char character; /* Exits loop when onechar = NULL */
while (character = *strg)
{
output(character);
*strg++;
}
}
/****************************************************************************/
char input(void) /* Read a character from the sci */
{ /* wait for rx data then get it */
while ((scsr & rdrf) == 0 ){};
return scdat;
}
/****************************************************************************/
void onsci(void) /* Initialize SCI for 9600 baud with 8 MHz xtal. */
{
baud = 0x30;
sccr1 = 0x00;
sccr2 = 0x0C;
}
/****************************************************************************/
void output(char character) /* output one character */
{ /* wait for tx data reg. empty, then */
while ((scsr & tdre) == 0){};
scdat = (character & 0x7F); /* clear MSB (parity bit) and send. */
}
/****************************************************************************/
void outcrlf(void) /* output a carriage return and line feed */
{
output(0x0D);
output(0x0A);
}
/****************************************************************************/
/* End of module. */
/****************************************************************************/