




已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
rs485通訊程序接收0123456789,只接收不發(fā)送,使用LM1602液晶顯示2008-12-07 19:45#include #include #include #include/液晶為JDH162A 1602液晶 16*2/以下宏定義語句可根據實際情況更改#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;/中斷接收函數ISR(USART_RXC_vect)writelocatechar(num,0,UDR);num+;unsigned char isbusy(void)unsigned char tmp;conport&=(1e); /先清0/設定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/設定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/設定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/設定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); /寫指定坐標,制定文字(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);/字符串長度計算函數 p指向字符串的指針/針對flash字符串長度unsigned char len(const char *p)unsigned char n;n=0;don+;p+; while(*p!=0);return n;/針對ram中字符串 返回字符串個數unsigned char lenr(char *p) unsigned char n;n=0;don+;p+; while(*p!=0);return n;/字符串清空 p:字符串指針 n:欲清空位數void cleanstr(char *p,unsigned char n) unsigned char i; for(i=0;in;i+) *p=0; p+; /字符串復制,由flash復制到內存 從p2 復制到p1void strftor(char *p1,const char *p2)unsigned char n,i;n=len(p2);for(i=0;i=n;i+) *(p1+i)=*(p2+i);/寫字符串函數(針對flash字符串) 錯誤函數 待改進 使用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; /針對內存字符串輸出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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年導游資格證考試筆試模擬試卷:旅游政策法規(guī)解讀解析題
- 環(huán)保事件背后的思考議論文(11篇)
- 2025年西式烹調師職業(yè)技能鑒定模擬試卷(中級實操篇)
- 2025年安徽省事業(yè)單位教師招聘考試學科專業(yè)知識英語試卷實戰(zhàn)演練
- 10-17翼神用戶手冊(含保養(yǎng))
- 文化遺產數字化展示與傳播:2025年文化遺產數字化資源整合策略報告
- 生物飼料添加劑研發(fā)成果鑒定報告:2025年行業(yè)競爭格局分析
- 汽車維修技術服務合同書
- 話劇劇本《瞎了一只眼》作者:丁西林
- 完成某行業(yè)市場調查問卷分析市場趨勢
- 護理三基技能培訓課件
- 拒絕假努力讓努力更高效-2023-2024學年熱點主題班會大觀園(全國通用)課件
- 新視野大學英語(第四版)讀寫教程2(思政智慧版)課件 Unit 4 Mission and exploration of our time Section A
- 五年級下冊語文試題課外名著閱讀之《三國演義》閱讀訓練(含答案)部編版
- 支原體感染后護理查房課件
- DB63-T 2220-2023 風積沙填筑路基技術規(guī)范
- 工程股權轉讓協(xié)議
- 高位截癱的護理查房
- 北京大學考博英語歷年真題及詳解
- lemontree中英文對照打印版
- 手術物品清點手術室護理實踐指南課件
評論
0/150
提交評論