下面是详细WPS2000注释工作过程的代码1

上传人:平*** 文档编号:13844018 上传时间:2017-10-26 格式:DOC 页数:12 大小:48.77KB
返回 下载 相关 举报
下面是详细WPS2000注释工作过程的代码1_第1页
第1页 / 共12页
下面是详细WPS2000注释工作过程的代码1_第2页
第2页 / 共12页
下面是详细WPS2000注释工作过程的代码1_第3页
第3页 / 共12页
下面是详细WPS2000注释工作过程的代码1_第4页
第4页 / 共12页
下面是详细WPS2000注释工作过程的代码1_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《下面是详细WPS2000注释工作过程的代码1》由会员分享,可在线阅读,更多相关《下面是详细WPS2000注释工作过程的代码1(12页珍藏版)》请在金锄头文库上搜索。

1、下面是详细注释工作过程的代码:#define RX_BEGIN_BYTE 0XAAvoid sendchar1(unsigned char c) /串口 1 发送与计算机相连UDR1 = c;while(!(UCSR1A & 0x40);void sendchar0(unsigned char c) /串口 0 发送与 KWP2000 相连UDR0 = c;while(!(UCSR0A & 0x40);#pragma ctask delay /*delay dt+1 us */void delay(unsigned int dt)while(dt)WDR(); /ICC 编译器 复位看门狗 喂

2、狗NOP();NOP();NOP(); dt-; #pragma ctask wakeup /150msvoid wakeup(void)delay(50000);delay(50000);delay(50000);delay(50000);delay(50000);delay(50000); void watchdog_init(void)WDR();WDTCR = 0x0f; /*MAIN PROGRAM*/unsigned char rev256,send100,revhead,revtail,send_byte,hostbuf20; /接收数据包的长短,发送头尾,unsigned ch

3、ar csc,cp,tempcsc; /CRC 校验 CP 指针 unsigned char combyte236= 0x82,0x11,0xf1,0x1a,0x80,0x1e; /* read ECU ID */struct dataunsigned bit0:1; /* receive period or send period, 0: send ; 1: receives 收发状态控制*/unsigned bit1:1; /* receiving or waiting , 0: waiting, 1: receive the first byte */unsigned bit2:1; /

4、* receive end, 0: not ,1: receive end,may send data to host K 线帧已经收到*/unsigned bit3:1; /* receiving the host command 0: waiting,1: receiving */unsigned bit4:1; /* indication the host com buffer have data 来自主机的帧已经收到*/unsigned bit5:1; /* 600 ms send tester present 保持在线? command to ECU */unsigned bit6:

5、1; /* */unsigned bit7:1;mfig;/*MAIN FUNCTION START*/void main( void ) /* */ unsigned char c_char,i;DDRA = 0x00;PORTA = 0xff;DDRB = 0x00;PORTB = 0xff;DDRC = 0x07;PORTC = 0xff;DDRD = 0x00;PORTD = 0xff;DDRE = 0x00;PORTE = 0xff;mfig.bit0 = 0;mfig.bit1 = 0;mfig.bit2 = 0;mfig.bit3 = 0; mfig.bit4 = 0;mfig.

6、bit5 = 0;mfig.bit6 = 0;for(i=0;i27;i+)wakeup(); /* Wait for Initial finish 7800ms */*/watchdog_init();OCR0 = 0x4e; /* 78 * 1024/8 = 10ms 10ms 定时,用于检测 ECU 是否已经结束应答帧*/TCCR0 = 0x0f; /*ctc 模式,1024 分频*/TCNT0 = 0x00;TIMSK &= 0x02; /* disable T/C0 cmp 输出比较中断 int*/ TCCR3B = 0x05; /* 1024 prescale 128*(ffff-

7、edb0)=600ms*/TCNT3H = 0xed;TCNT3L = 0xb0;ETIMSK |= 0x04; /T/C3 溢出中断使能UCSR1A |= 0x02; /* UART1 init 分频因子 8 倍速 */UCSR1B = 0x98; /* RXCIE1,RXEN1,TXEN1 接收中断使能 使能收发*/UCSR1C = 0b00110110; /8 位,奇校验UBRR1H = 0x00;UBRR1L = 0x10; /*14400 70us/bit */ /与上位机的通讯使用 14400波特率UCSR0A &= 0x02; /* UART0 init 分频因子 16 */UC

8、SR0B = 0x98; /接收中断使能,使能收发UCSR0C = 0x06; /8 位 for(i=0;i100;i+)revi=0; revhead=revtail=0; /* buffer pointer init*/delay(5000);sendchar1(0xaa); /TEST *1 发送 AA 56 00 间隔 1usdelay(1000);sendchar1(0x56);delay(1000);sendchar1(0x00);asm(sei); /开中断 等待 HOST 发来的数据 hostbuf3 = 0x00; /先初始化 host 缓冲 3 为 00while(!mfi

9、g.bit4) /host 缓冲未接收完,一直等待不断喂狗?NOP();NOP();NOP();WDR();while(hostbuf3!=0x55) /* Wait for Kline Start command 没收到开始 K 线的通讯 一直等待*/mfig.bit4 = 0; /清 host 缓冲标志位 while(!mfig.bit4)NOP();NOP();NOP();WDR();mfig.bit4 = 0x00; /清 HOST 缓冲标志asm(cli); /关中断wakeup();WDR();wakeup(); /* delay 300 ms */asm(sei); /* ENA

10、BLE INTERRUPT*/delay(1000);sendchar1(0x56); /TEST *3 Kline Start Flag 告知主机 k 线开始初始化delay(1000);sendchar1(0xaa);delay(1000);sendchar1(0x00);/*/UBRR0H = 0x0a; /初始化串口 0,200baudUBRR0L = 0x3a;WDR();send_byte = 0xf0;sendchar0(send_byte); /* wake up pulse */delay(5000); /* delay 5 ms */UBRR0H = 0x00;UBRR0L

11、 = 0x30; /* baud rate 10400 */ /*/WDR();send_byte = 0x81;sendchar0(send_byte); /* send start communication commmand */sendchar1(send_byte); /把初始化帧头发给 HOSTdelay(5000);send_byte = 0x11;sendchar0(send_byte);delay(5000);send_byte = 0xf1;WDR(); /喂狗sendchar0(send_byte);delay(5000);send_byte = 0x81;sendcha

12、r0(send_byte);delay(5000);send_byte = 0x04;sendchar0(send_byte);delay(5000); /* start communication end */mfig.bit0 = 1; /* send data over, enter receive period 进入收状态*/mfig.bit2 = 0; /状态位初始化 K 线帧未收完mfig.bit5 = 0; /暂时不需要发送保持在线信息WDR(); /喂狗,这时其实是开始对 ECU 回应时间的计数,2s 无回应说明连接不上,单片机复位while(!mfig.bit1) /等待接收 K 线上的数据,没收到则一直等待NOP(); /超时会导致看门狗复位sendchar1(0x52); /*2 发送现在的工作状态,已经开始接收TIMSK |= 0x02; /开 T0 比较中断while (!mfig.bit2) /

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号