|
本程序是《MSP430系列單片機(jī)系統(tǒng)工程設(shè)計(jì)與實(shí)踐》書里面的源碼,完整例程下載(包含工程文件 (例4.1.4))):http://www.torrancerestoration.com/bbs/dpj-46245-1.html
‘
關(guān)于本程序的詳細(xì)解說(shuō)大家可以下載電子書點(diǎn)擊上圖即可
- #include "msp430x42x.h" /*單片機(jī)寄存器頭文件*/
- #include "ctype.h" /*isdigit函數(shù)需要該頭文件*/
- #include "LCD_Display.h" /*LCD函數(shù)庫(kù)頭文件*/
- char FirstChrFlag=1; //第一個(gè)字符標(biāo)志位
- /****************************************************************************
- * 名 稱:putchar()
- * 功 能:向LCD顯示屏輸出一個(gè)ASCII字符。
- * 入口參數(shù):ch: 待發(fā)送的字符
- * 出口參數(shù):發(fā)出的字符
- * 說(shuō) 明: printf函數(shù)會(huì)調(diào)用該函數(shù)作為底層輸出。該函數(shù)將字符輸出到LCD上
- 因此printf的結(jié)果將顯示在LCD上。
- ****************************************************************************/
- int putchar(int ch)
- {
- if(FirstChrFlag) LCD_Clear(); //第一個(gè)字符到來(lái)的時(shí)候清除上一屏顯示內(nèi)容
- FirstChrFlag=0;
- if(ch=='\f') LCD_Clear(); //'\f'表示走紙翻頁(yè),相當(dāng)于清除顯示
- if(isdigit(ch)) LCD_InsertChar(ch-0x30); //若字符是數(shù)字則顯示數(shù)字
- //數(shù)字和對(duì)應(yīng)ASCII字母之間差0x30 '1'=0x31 '2'=0x32... isdigit也是C語(yǔ)言標(biāo)準(zhǔn)函數(shù)
- else //否則,不是數(shù)字,是字母
- {
- switch(ch) //根據(jù)字母選擇程序分支
- {
- case 'A': case 'a': LCD_InsertChar(AA);break; //字符A
- case 'B': case 'b': LCD_InsertChar(BB);break; //字符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; //字符Z
- case '-': LCD_InsertChar(BR);break; //字符-
- case '`': LCD_InsertChar(DT);break; //字符`
- case ' ': LCD_InsertChar(SP);break; //空格
- case '.': LCDM1|=0x10; break; //小數(shù)點(diǎn),直接顯示在右下角
- case '\n': case '\r': FirstChrFlag=1; break; //換行符的下一個(gè)字母將清屏
- default : LCD_InsertChar(SP);break;//顯示不出來(lái)的字母用空格替代
- }
- }
- return(ch); //返回顯示的字符(putchar函數(shù)標(biāo)準(zhǔn)格式要求返回顯示字符)
- }
- /****************************************************************************
- * 名 稱:putchar()
- * 功 能:向標(biāo)準(zhǔn)終端設(shè)備發(fā)送一字節(jié)數(shù)據(jù)(1個(gè)ASCII字符)
- * 入口參數(shù):ch: 待發(fā)送的字符
- * 出口參數(shù):發(fā)出的字符
- * 說(shuō) 明: UART.c內(nèi)的putchar函數(shù)printf函數(shù),這里從串口輸出字符到PC機(jī)的超
- 級(jí)終端軟件上,printf的結(jié)果將打印到超級(jí)終端上。供對(duì)比。
- ****************************************************************************/
- /*
- int putchar(int ch)
- {
- if (ch == '\n') // '\n'(回車)擴(kuò)展成 '\n''\r' (回車+換行)
- {
- UART_PutChar(0x0d) ; //'\r'
- }
- UART_PutChar(ch); //從串口發(fā)出數(shù)據(jù)
- return (ch);
- }
- */
復(fù)制代碼
|
|