傳送一字串給文字型 LCM 的C語言寫法 |
答題得分者是:penguin5
|
PSIR
初階會員 發表:106 回覆:51 積分:31 註冊:2008-01-03 發送簡訊給我 |
|
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
|
penguin5
資深會員 發表:116 回覆:317 積分:431 註冊:2004-05-09 發送簡訊給我 |
<br />
#include "reg51.h" #define RS P2_0 #define RW P2_1 #define Enable P2_2 sbit P2_0=0xa0; sbit P2_1=0xa1; sbit P2_2=0xa2; void delay(void); void InitialLCD(void); void WriteIns(char); void WriteData(char); void WriteString(char,char *); void CheckBusy(void); void KeyScan(void); char one=0; char zero=0; int KeyData=0xff; int KeyTemp=0xff; main() { char MSG1[]="0123456789"; char MSG2[]="I Love YOU"; char MSG3[]="06..17..2008"; while(1) { KeyScan(); //掃瞄鍵盤 if(KeyData!=0xff) //有按鍵盤 { WriteIns(0x01); // 清除 LCDM if(KeyData==1) //鍵盤值1 WriteString(10,MSG1); //將字串MSG1寫入LCDM中及及顯示0123456789 else if(KeyData==2) //鍵盤值2 WriteString(12,MSG2); //將字串MSG2寫入LCDM中及及顯示I Love YOU else if(KeyData==3) //鍵盤值3 WriteString(13,MSG3); //將字串MSG3寫入LCDM中及及顯示06..17..2008 KeyData=0xff; //清除鍵盤值 } } } /* main */ void InitialLCD(void) { WriteIns(0x38); WriteIns(0x38); WriteIns(0x38); WriteIns(0x38); WriteIns(0x08); /* off display */ WriteIns(0x01); /* clear buffer */ WriteIns(0x0e); /* on display */ WriteIns(0x06); /* set input mode */ } /* InitialLCD */ void WriteIns(char instruction) { RS=0; RW=0; Enable=1; P1=instruction; Enable=0; CheckBusy(); } /* WriteIns */ void WriteData(char i) { RS=1; RW=0; Enable=1; P1=i; Enable=0; CheckBusy(); } /* WriteData */ void WriteString(count,MSG) char count; char MSG[]; { char i; for(i=0;i } /* WriteString */ void CheckBusy(void) { char i=0x80; while(i&0x80) { RS=0; RW=1; Enable=1; i=P1; Enable=0; delay(); } } /* CheckBusy */ void delay(void) { int i; for(i=0;i<500;i ) ; } /* delay */ void KeyScan(void) { char key=0; char KeyStatus; char KeyScanLine=0x01; char col; char row; for(col=0;col<2;col ) { P3=~KeyScanLine; KeyStatus=~P3; KeyStatus>>=2; for(row=0;row<2;row ) { if(KeyStatus==0x01) { one=0; if(KeyTemp!=key) { KeyTemp=key; zero=1; } else { zero ; if(zero==5) KeyData=KeyTemp; } } key ; KeyStatus>>=1; } /* row */ KeyScanLine<<=1; } /* col */ one ; if(one==5) { zero=0; KeyTemp=0xff; KeyData=0xff; } } /* KeyScan */ ===================引 用 PSIR 文 章=================== 大家好: 我想用一個函數傳送一個字串到 LCM 上顯示,例如這樣寫: SEND_STRING("Single Chip"); 請問若要實現這個函數的話,刮號內應該要怎麼宣告,才能接收那一串文字,以及要放在何處,謝謝。
編輯記錄
penguin5 重新編輯於 2008-06-17 21:36:01, 註解 無‧
|
src
高階會員 發表:1 回覆:94 積分:154 註冊:2005-08-23 發送簡訊給我 |
[code c#] void SEND_STRING(unsigned char *Str) { while(*Str) { Write(*Str ); //將字串填入 } } [/code] ===================引 用 PSIR 文 章=================== 大家好: 我想用一個函數傳送一個字串到 LCM 上顯示,例如這樣寫: SEND_STRING("Single Chip"); 請問若要實現這個函數的話,刮號內應該要怎麼宣告,才能接收那一串文字,以及要放在何處,謝謝。 |
PSIR
初階會員 發表:106 回覆:51 積分:31 註冊:2008-01-03 發送簡訊給我 |
|
penguin5
資深會員 發表:116 回覆:317 積分:431 註冊:2004-05-09 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |