avr单片机实现的485通讯从机接收程序(带帧校验)单片机(AVR microcontroller to achieve the 485 communication from the machine to receive procedures (with frame check), single-chip microcomputer).doc
- 1、本文档共18页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 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
您可能关注的文档
- 6级人防覆土2米等效静荷载多少(What is the equivalent static load of 6 meters covered with air defense 2 meters).doc
- 6陈安之告诉你-超级快速致富秘诀(6 Chen Anzhi tells you - super quick tips for getting rich).doc
- 7 商店建筑设计规范(7 code for design of shop building).doc
- 7.工期保证措施(7. time limit guarantee measures).doc
- 72非风湿性二尖瓣返流疾病(72 non rheumatic mitral regurgitation disease).doc
- 74-中国船级社广州分社海关监管集装箱式货车车厢申请及检验流程(74- China Classification Society, Guangzhou branch, customs supervision, container type freight car application and inspection process).doc
- 76uut(76uut).doc
- 7.4__dll函数入口及其导出函数(7.4__dll function entry and its export function).doc
- 75-3和75-5视频线参数(75-3 and 75-5 video line parameters).doc
- 770-南京市优秀专利奖(770- Nanjing excellent Patent Award).doc
文档评论(0)