avr单片机实现的485通讯从机接收程序(带帧校验)单片机(AVR microcontroller to achieve the 485 communication from the machine to receive procedures (with frame check), single-chip microcomputer).doc

avr单片机实现的485通讯从机接收程序(带帧校验)单片机(AVR microcontroller to achieve the 485 communication from the machine to receive procedures (with frame check), single-chip microcomputer).doc

  1. 1、本文档共18页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
avr单片机实现的485通讯从机接收程序(带帧校验)单片机(AVR microcontroller to achieve the 485 communication from the machine to receive procedures (with frame check), single-chip microcomputer)

avr单片机实现的485通讯从机接收程序(带帧校验)单片机(AVR microcontroller to achieve the 485 communication from the machine to receive procedures (with frame check), single-chip microcomputer) AVR MCU 485 communication receiving program from the machine (with frame check) chip 2009-08-31 14:15:48 read 442 comments 0 small subscription number: / / slave program The //01 data frame //02 command frame //03 frame 01 confirmed 02 deny #includeavr/io.h #includeavr/interrupt.h #includeinttypes.h #includeutil/delay.h #include avr/pgmspace.h #includestring.h #define myaddr 0x01 / / define the address of the machine #define (rx_485); ASM (CBI 0x13,2); //portd.2 cleared to the receiving state #define (tx_485); ASM (SBI 0x13,2); //portd.2 is set to send state Volatile struct conn{ Unsigned char buf[70]; Unsigned char data[64]; Unsigned char srcadd; / / source address Unsigned char aimadd; / / destination address Unsigned char TP; / / frame type Int num; Int tmp; Unsigned char ver; / / verification code; Unsigned char err; / / error code; 01: frame check. }tx, rx; Volatile unsigned char com; / / command Const unsigned char flash_str[] PROGMEM = 0123456789; ISR (USART_RXC_vect) { Rx.buf[rx.tmp]=UDR; /*test If (rx.tmp==0 and rx.buf[rx.tmp]==t) { (totx); Tx.num=16; Strcpy (tx.buf, can I help you); Tx.buf[15]=0x0D; UCSRB|= (1UDRIE); / / send frame }; * / If (rx.tmp==0 rx.buf[rx.tmp]! =myaddr) / / return directly to the wrong address { Receive 0.15 seconds / / ban. Feasible, because the use of interrupt mode, does not affect the normal use UCSRB=~ (1RXEN); //0.15 seconds after the automatic entry into the receiving state. (timer1_init); Return; }; If ((rx.tmp4) (rx.tmp==rx.buf[3]+4) (rx.buf[rx.tmp]! =rx.ver)) / / validation error { When receiving / / after the end, what things are not dry, just waiting to receive. Rx.err=0x01; }; If ((rx.tmp4) (rx.tmp==rx.buf[3]+5) rx.err==0 (rx.buf[rx.tmp]==0xcc)) / / normal end { / / frame type case / / deny frame or confirmation frame or other frame TCCR2 = 0

您可能关注的文档

文档评论(0)

jgx3536 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:6111134150000003

1亿VIP精品文档

相关文档