rs485通訊程序接收0123456789,只接收不發(fā)送,使用LM1602液晶顯示.doc_第1頁
rs485通訊程序接收0123456789,只接收不發(fā)送,使用LM1602液晶顯示.doc_第2頁
rs485通訊程序接收0123456789,只接收不發(fā)送,使用LM1602液晶顯示.doc_第3頁
rs485通訊程序接收0123456789,只接收不發(fā)送,使用LM1602液晶顯示.doc_第4頁
rs485通訊程序接收0123456789,只接收不發(fā)送,使用LM1602液晶顯示.doc_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

rs485通訊程序接收0123456789,只接收不發(fā)送,使用LM1602液晶顯示2008-12-07 19:45#include #include #include #include/液晶為JDH162A 1602液晶 16*2/以下宏定義語句可根據(jù)實際情況更改#define dataport PORTB#define datapin PINB#define dataddr DDRB#define conport PORTA#define conddr DDRA#define rw PA5#define rs PA6#define e PA4unsigned char str1=Waiting.;volatile int num;/中斷接收函數(shù)ISR(USART_RXC_vect)writelocatechar(num,0,UDR);num+;unsigned char isbusy(void)unsigned char tmp;conport&=(1e); /先清0/設(shè)定dataport為輸出dataddr=0x00;conport&=(1rs);conport|=(1rw);_delay_us(1);conport|=(1e);_delay_us(2);tmp=datapin;tmp=tmp&(17);conport&=(1e);return tmp;void writecom(unsigned char com,unsigned char busy_flag)if (busy_flag) while(isbusy()!=0);dataddr=0xff;conport&=(1e); /先清0/設(shè)定dataport為輸出conport&=(1rs)|(1rw);_delay_us(1);dataport=com;_delay_us(1);conport|=(1e);_delay_us(2);conport&=(1e);dataddr=0x00;void uart_init(uint8_t ubbrh,uint8_t ubbrl)UCSRB = 0x00; /disable while setting baud rateUCSRA = 0x00;UCSRC =_BV(URSEL)| 0x06;UBRRL = ubbrl; /set baud rate lo/UBRRH = ubbrh; /set baud rate hiUCSRB = 0x90;void writedata(unsigned char com,unsigned char busy_flag)if (busy_flag) while(isbusy()!=0);dataddr=0xff;conport&=(1e); /先清0/設(shè)定dataport為輸出conport&=(1rw);conport|=(1rs);_delay_us(1);dataport=com;_delay_us(1);conport|=(1e);_delay_us(2);conport&=(1e);dataddr=0x00;unsigned char readcom(void)unsigned char tmp;conport&=(1e); /先清0/設(shè)定dataport為輸出dataddr=0x00;conport&=(1rs);conport|=(1rw);_delay_us(1);conport|=(1e);_delay_us(2);tmp=datapin;conport&=(1e);return tmp;void init_lcd(void) _delay_ms(15); writecom(0x38,0); _delay_ms(5); writecom(0x38,0); _delay_ms(5); writecom(0x38,0); _delay_ms(5); writecom(0x38,1); writecom(0x08,1); writecom(0x01,1);/清除屏幕 writecom(0x06,1); writecom(0x0c,1); /寫指定坐標(biāo),制定文字(x為橫向 y為縱向 x=0,.13 y=0,1void writelocatechar(unsigned char x,unsigned char y,unsigned char ch) writecom(128+x+y*0x40,1); writedata(ch,1);/字符串長度計算函數(shù) p指向字符串的指針/針對flash字符串長度unsigned char len(const char *p)unsigned char n;n=0;don+;p+; while(*p!=0);return n;/針對ram中字符串 返回字符串個數(shù)unsigned char lenr(char *p) unsigned char n;n=0;don+;p+; while(*p!=0);return n;/字符串清空 p:字符串指針 n:欲清空位數(shù)void cleanstr(char *p,unsigned char n) unsigned char i; for(i=0;in;i+) *p=0; p+; /字符串復(fù)制,由flash復(fù)制到內(nèi)存 從p2 復(fù)制到p1void strftor(char *p1,const char *p2)unsigned char n,i;n=len(p2);for(i=0;i=n;i+) *(p1+i)=*(p2+i);/寫字符串函數(shù)(針對flash字符串) 錯誤函數(shù) 待改進(jìn) 使用read_pgm_strunsigned char strout(const char *p,unsigned char x,unsigned char y) unsigned char n,i; n=len(p); if(n=(20-x+(1-y)*20) for(i=0;in;i+) writelocatechar(x,y,*(p+i); x+; if(x=20) x=x-20; y+; return 1; else return 0; /針對內(nèi)存字符串輸出unsigned char stroutr(char *p,unsigned char x,unsigned char y) unsigned char n,i; n=lenr(p); if(n=(16-x+(1-y)*16) for(i=0;i0;i-) writelocatechar(x+i-1,y,(*p+48); p+; void port_init(void)PORTA = 0x00;DDRA = 0xFF;PORTB = 0x00;DDRB = 0x00;PORTC = 0x00; /m103 output onlyDDRC = 0x00;PORTD = 0x00;DDRD = 0x00;/call this routine to initialize all peripheralsvoid init_devices(void)/stop errant interrupts until set upasm(cli); /disable all interruptsport_init();MCUCR = 0x00;GICR = 0x00;TIMSK = 0x00; /timer interrupt sourcesasm(sei); /re-e

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論