#include "msp430x42x.h" /*MCU register header file*/
#include "ctype.h" /*isdigit function requires this header file*/
#include "LCD_Display.h" /*LCD function library header file*/
char FirstChrFlag=1; //First character flag
/****************************************************************************
* Name: putchar()
* Function: Output an ASCII character to the LCD display.
* Input parameter: ch: the character to be sent
* Output parameter: the character sent
* Description: The printf function will call this function as the bottom-level output. This function outputs the character to the LCD,
so the result of printf will be displayed on the LCD.
****************************************************************************/
int putchar(int ch)
{
if(FirstChrFlag) LCD_Clear(); //Clear the previous screen display when the first character arrives
FirstChrFlag=0;
if(ch=='\f') LCD_Clear(); //'\f' means paper feed and page turning, which is equivalent to clearing the display
if(isdigit(ch)) LCD_InsertChar(ch-0x30); //If the character is a number, display the number
//The difference between the number and the corresponding ASCII letter is 0x30 '1'=0x31 '2'=0x32... isdigit is also a standard C language function
else //Otherwise, it is not a number, but a letter
{
switch(ch) //Select program branch according to the letter
{
case 'A': case 'a': LCD_InsertChar(AA);break; //Character A
case 'B': case 'b': LCD_InsertChar(BB);break; //Character B
case 'C': case 'c': LCD_InsertChar(CC); break; //...
case 'D': case 'd': LCD_InsertChar(DD); break;
case 'E': case 'e': LCD_InsertChar(EE); break;
case 'F': case 'f': LCD_InsertChar(FF); break;
case 'G': case 'g': LCD_InsertChar(GG); break;
case 'H': case 'h': LCD_InsertChar( HH);break;
case 'I': case 'i': LCD_InsertChar(II);break;
case 'J': case 'j': LCD_InsertChar(JJ);break;
case 'K': case 'k': LCD_InsertChar(KK);break;
case 'L': case 'l': LCD_InsertChar(LL);break;
case 'M': case 'm': LCD_InsertChar(mm);break;
case 'N': LCD_InsertChar(NN);break;
case 'n': LCD_InsertChar(nn);break;
case 'O': LCD_InsertChar(OO);break;
case 'o': LCD_InsertChar(oo);break;
case 'P': case 'p': LCD_InsertChar(PP);break;
case 'Q': case 'q': LCD_InsertChar(QQ); break;
case 'R': case 'r': LCD_InsertChar(rr);break;
case 'S': case 's': LCD_InsertChar(SS);break;
case 'T': case 't': LCD_InsertChar(tt);break;
case 'U': case 'v': LCD_InsertChar(UU);break;
case 'V': case 'u': LCD_InsertChar(VV);break;
case 'W': case 'w': LCD_InsertChar(WW);break;
case 'Y': case 'y': LCD_InsertChar(YY);break; //...
case 'Z': case 'z': LCD_InsertChar(ZZ);break; //Character Z
case '-': LCD_InsertChar(BR);break; //Character -
case '`': LCD_InsertChar(DT);break; //Character `
case ' ': LCD_InsertChar(SP);break; //Space
case '.': LCDM1|=0x10; break; //decimal point, directly displayed in the lower right corner
case '\n': case '\r': FirstChrFlag=1; break; //the next letter of the line break will clear the screen
default : LCD_InsertChar(SP);break;//letters that cannot be displayed are replaced with spaces
}
}
return(ch); //return the displayed character (the standard format of putchar function requires the return of the displayed character)
}
/****************************************************************************
* Name: putchar()
* Function: Send one byte of data (1 ASCII character) to a standard terminal device
* Input parameter: ch: the character to be sent
* Output parameter: the character sent
* Description: The putchar function in UART.c and the printf function, here, output characters from the serial port to the
hyperterminal , and the result of printf will be printed on the hyperterminal. For comparison.
********************************************************************************/
/*
int putchar(int ch)
{
if (ch == '\n') // '\n' (carriage return) is expanded to '\n''\r' (carriage return + line feed)
{
UART_PutChar(0x0d); //'\r'
}
UART_PutChar(ch); //Send data from the serial port
return (ch);
}
*/
|