|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
c51单片机MODBUS参考程序) A1 Z G" J& A y; f% ~
( @6 I% n9 ?$ Q+ H5 @
) r( x) p/ v$ F5 r9 K9 R$ x8 u9 q7 x; y" w* @0 h* @/ X
//在触摸屏上作个位开关,单片机系统用LED指示5 Q1 A* j8 N6 J& I: P0 {$ Z
- n( C% n/ E% s u, W9 D$ x) ~8 K8 J//在弹片机的硬件系统中用拨码开关来模拟数据输入,在EVIEW上显示
* X G1 C# S! G! e2 ^, r, h- H" k a0 b d
//本程序实现位的读写和字的读写,为一对一通讯,EVIEW为主机6 p, S. X9 ~- j; ^) C* `; c0 Y
, ]- C& _* x- H7 k4 T#include<reg52.h>/ V. R$ b! O q. `5 D" e. U
5 t: W# a# ^$ j6 y4 @
#include<absacc.h>
& I0 v' O6 [/ r. v1 Z
9 B, T+ ?6 H* y+ E$ W#include<intrins.h>
: r6 F6 L% [0 }; Z
6 J( u/ O4 P6 f) T3 O3 R, r#include<ctype.h> V' ?4 U/ G5 f2 I. x2 _1 d
6 {+ `! S8 G+ X% V6 s# o1 @. Y0 K0 ]( K
/* These macro define simple data type */; [: L- l8 q0 _2 L1 E$ z4 x
6 N3 ~" _5 y7 s" z
#define uchar unsigned char+ h7 f9 H d0 O9 W/ T
$ m, H* j7 Y) {
#define ulint unsigned long
' n4 f* x% J8 E- ]. K
1 U, ?; {. k# A, }$ W; a. ^#define uint unsigned int
) O% N& L) z9 |. l f+ ?6 a% W9 N, b4 f3 ~/ G* h
/* These macro for Mudbus function code */
! r8 U1 M- y0 n! f9 q" f3 i" S" j/ _7 U- S, Z8 _% [- ^) P- t
#define ReadCoilSta 0x01 // 0X read coil function
& o1 b L; }: L+ s# B# Z$ J. v7 _) O- I! I3 L
#define ForceSingleCoil 0x05 // 0X force single coil function3 }" D8 Q+ Y: H. J( n' i
' G% @! H) Z/ \+ Q; I9 L2 f
#define ReadHoldReg 0x03 // 4X read input register) M- c& j+ V+ Q& p' b
5 w# U6 Q$ z8 C) X0 o5 I6 J' Y. |
#define PresetMulReg 0x10 // 4X write multi register, u! _( e. a) i2 B
% a8 A8 w$ c% U& m7 M0 [0 W! A
/* These macro describe index of communiction message from start to end *// \6 W$ s$ P. Q+ W
) K& M5 r# d3 R3 `$ d, V) {
#define CommIndexSlaveID 0 // macro for slave ID
/ U7 D9 {* E+ s8 r/ t3 ~' L+ }3 ~9 `
$ q, U# W4 N Q; `#define CommIndexFunction 1 // macro for function code4 o; S+ s# _5 \
* X1 Q5 J% O- o#define CommIndexStartAdrHi 2 // macro for data hight adr
& A: L: q4 _- y1 X1 u- r7 G$ W6 J/ R) Q9 ^( P/ r$ K
#define CommIndexStartAdrLo 3 // macro for data low adr
5 _. N0 w' c* o. E/ `' ]" E! O( j: F/ O/ N7 D: G6 N
#define CommIndexNoPointHi 4 // macro for hight quantity datas/ s' `' q: V' m
2 k0 ]( b$ {/ H- \/ M
#define CommIndexNoPointLo 5 // macro for low quantity datas& Q& q! z0 T8 i7 D0 \
@7 [- f- d- D1 r
/* These macro describe recieve message lenght of different function code */
; i, p0 g- q% i& c3 }7 {; b. m. m7 _( _9 I5 o, H$ s" w
/* But not include data lenght ,the data is master write to slave */1 v$ e* r9 U3 a1 [& A3 ~
5 K5 p- B# l% J& g) L0 v7 v
/* because we don't know the data lenght prior, it depend on ComBuf[ComIndexNoPoint] value */
) E- A, }. W/ [" v, y- z/ u
8 d; l1 e. Y7 `2 K#define ReadCoilStaIndexEnd 7 // 0~7,0x01,0X
; a& d/ V% W* M0 s/ o* s/ z; W' {+ k. C- S# W$ K
#define ForceSingleCoilIndexEnd 7 // 0~7,0x05,0X) m; ?1 S3 N! P! N
! \1 r# Q m$ Q$ k
#define ReadHoldRegIndexEnd 7 // 0~7,0x03,4X
9 y' w6 q! @+ W$ R. Z$ N
) w4 a( m: L3 y- f( `6 x2 i. ~* f#define PresetMulRegIndexEnd 8 // 0~8,0x10,4X
* A) i2 d5 l: v' ]) W
- J: I( Y1 y" o. I! u* `/* these macro describe send or recieve allowed */
% z8 Q5 i9 Y5 i6 u) @3 Z5 V. m' E
$ g2 P3 t1 f. b; n7 J#define SEND 1 // send allowed
& a, ?" z) ^, Q
# D! I9 @# R5 T& }) Z#define RECIEVE 0 // recieve allowed
( c" b# I( N6 e8 J
" K1 W# c1 r8 ^, ~#define SlaveID 0x01 // the slave's ID
8 T1 P& }/ W% [: e3 O2 P4 n" j7 H* d) |& a( P. W6 e
#define SendRecieveDelay 50 // Send turn to Recieve or Recieve turn to Send delay time vlaue
* f5 }, F" n4 k+ k5 t
8 l7 g4 O( `3 `! m#define MaxDataLen 30 // preset CommBuf array Max lenght! o: R; x5 p' n% m$ c0 R
0 C( O6 v* H" o5 e#define MaxRegLen 20 // preset SlaveOutputBuf Max lenght
' x1 l' J* ?7 S9 C. y3 y/ }* d7 B# n5 e$ L5 M8 A" |
/* variable for modbus is following */
0 S% `" m! f, x/ [' }4 D
7 @. E" v6 Q4 z# F% cbit data RecFinishF;& q9 D& F8 R2 l2 j3 A) ]
+ }. `) F* f# cuchar data CommIndex;
% @" b. T. S* [' s2 Q% i# e3 y j+ }- C$ `
uchar data CommIndexEnd;
0 \* Z; C6 M. ]; d( b7 w
& g3 O" k F! ^uchar idata CommBuf[MaxDataLen];2 G, b" Y$ d0 y# l
+ G2 R4 q0 e9 s4 e3 L( Yuchar idata SlaveOutputBuf[MaxRegLen]; // Hight 8 bit of word is front,Low 8 bit is back
/ Q8 ` Z4 [7 w' b, _( Q3 u! p- }) ]& j" I/ `# e1 B8 ]
uchar idata SlaveInputBuf[MaxRegLen];# \+ d+ Z1 y- K" q7 h- e" @
8 Y" }$ ` ^0 M$ H+ l: g
/* exp data define */
* b% g& V' _0 i+ I6 i1 d$ {( ^: e5 Q% l
: @" w% c* O( c" J6 R/ E#define SlaveAdr XBYTE [0xD800]
7 _# \0 J2 `, O
9 x! v5 K) f0 \- i; Gsbit LED0=P1^0;
$ p3 J- S' l* N" r, i& B. H" O
7 O: A. l7 }7 S$ c0 @6 R9 duchar idata ForceCoilBuf[10];: J# F8 P! u% F) M* p! U, X
9 z! z/ n. ~( i8 X+ K, z4 I9 Luchar count=0;6 @1 z" a8 o: `' C) k. j! p& r; N
3 z, E+ N9 k* \! r0 m& b2 r* g4 h8 xuchar forceval=0x00;0 M: f# y. h: s! r
( T) d2 b' {* \* x- B//bit forcesendF=0;* {9 I1 p, Z; Q; }
4 x# X3 r2 D" R) e, V/* Table Of CRC Values for high-order byte */
/ n8 T) N2 F2 c0 e: K, H4 K- p9 P' \- M
uchar code auchCRCHi[] = {
' j7 [; Q6 O$ D! x% m. k9 H; e6 J, K4 a* l6 x5 Z
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
4 g$ h! Y8 a1 _1 ]* C8 T5 v/ e
/ C4 C/ H* G! q; N% a# G/ c0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,7 y9 l. B1 u. F4 V1 Q2 `1 o
! t; @0 p1 A: {
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
8 ~8 l9 ^. S. B, u/ N8 h, S2 ?; z
7 j6 B! ~0 x3 _. h8 u0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
: i9 m8 C0 x7 M4 b1 L$ A* b) T3 h" n, x
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
2 Y8 z0 w- E$ S+ o8 U! K/ ]
' F4 G$ y+ M# h! b9 U0x00, 0xC1, 0x81,! {( h" J7 k D8 [' O6 [% Y( n
9 X8 E( X `( S+ y0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,2 {7 V" E2 R+ [# I5 H+ u
8 Y2 O7 n9 _/ m7 B: U q; r0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,- d0 Y: E* p# D; N8 U; i& |
6 v$ e* r+ Z1 Z6 B& c. _" d4 B
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40," k! P, a: ~. C8 w2 H& W
- e8 U. w. e7 d2 ^( ^8 ~4 h0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
& |( S$ H- t8 q, N& x7 C4 d& }7 W+ Y" ^
0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,7 s. X: Y1 |8 Y0 i' u2 N% p
% w! p7 T' K) }) z6 U
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
. t1 m* p) Q7 x; T( ]) Z% M S
8 F# y. T8 }, D7 _) D0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,9 |4 X- d+ u5 C u( d: B
* M3 D6 [3 p/ W& ?1 p" _0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,% O, j& ?$ G6 }- b$ [
+ j6 ~; A: k, b' {8 p4 I v0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,, ^7 ^! N; k2 [' e
% S2 | h; b/ n5 y9 B& v3 Y$ r" [0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,; G# u9 k$ h8 f: B) [: x, ?
" A% K. P5 b) E8 ~5 r! o0 g0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
7 _4 ^6 d% b* x2 ?3 z( x. x1 \% ^$ _8 E; b$ k7 _) `( {
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,3 ^/ ]/ _- {1 e( B" a/ u8 {1 m$ n
1 x7 P+ _5 O) \% q0 q! U5 W- {4 p0x40
0 D1 ?% D# N0 o) \8 b
/ }; D. l9 b+ ]5 ]- x9 i& V( N} ;
: Y8 a+ `6 |1 h' Y
* ~/ e& y5 W* Q7 L4 Z" t/* Table of CRC values for low-order byte */% s6 ]3 y5 l8 x
J+ M) @9 n9 Y6 buchar code auchCRCLo[] = {
9 f; o9 {% T0 m5 x5 H1 x k3 @2 A- C @ A* _2 c, g+ X0 M! t7 Z
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,* A) t, z$ f- [& G4 c" K f
% W/ R+ i, K K1 I
0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
* y6 D8 j/ A' s- G' {9 m! T! k' h" l U7 u- ?% E( ^* U: P
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,% F7 y+ u! _. u4 e7 [
- L7 ^: r- {8 {3 u6 H6 [. n0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
8 c9 F( _# N; |/ e1 Q4 D1 ~% w
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7,
4 V/ P1 p* W% g; v/ R7 c! F: \, ]' d+ i+ O+ n" K4 y. ?
0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,. ^9 J: H, h8 l9 g, w0 L# w
' ]* j$ ]- X4 C
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE,! N% w) l) S' }5 G4 r! x# U, e
5 M- a1 n2 |* \! p0 j* c+ U1 w
0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,: {2 j8 M$ `% G/ n9 p6 a
# b! m5 D0 x* e( M0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2,
3 f' y2 L/ P. r' A1 |' d+ T& f( ^3 ?: ^& D
0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,5 j l# |* T J
( `0 l. W W0 `% u2 g( O! E5 e0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB,/ P" g& B4 ]) {, S
" S/ G h, N$ J* n0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
4 M3 }% \! d7 e% B9 z3 b
% P6 c/ |! z2 q+ f4 A0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91,, C R1 Q# W- {9 b8 e5 T
& D/ v5 L+ \ L6 U' S5 C
0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C," x8 Y8 ]9 F8 }
6 v5 T0 \" F0 z( X. P7 A
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88,
6 W5 i9 W. E4 C3 G- t7 N8 k2 _( E
0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
4 l& X- q: c( |- \: n9 v6 C8 |6 T! n! _ ?8 _7 s7 e
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,
) g. e) L2 [ w/ L R& A& O
, J, o( M6 y7 F/ m1 m0x404 V0 l) q% Q' I6 |4 S
, _$ Z# K7 l% J% G, }
} ;
0 P2 Z$ c/ ~8 V: c7 s7 Z/ e i" Q% q/ c9 K3 p
uint crc16(uchar *puchMsg,uchar usDataLen) // puchMsg message to calculate CRC upon T2 k4 w! v+ y
7 F8 n- z, k! T8 L8 {; r3 L{ // usDataLen quantity of bytes in message- D, ~' A0 J, z# P
& {- f& r) @% f, R2 D1 B9 ]
uchar uchCRCHi = 0xFF ; // high byte of CRC initialized
! U2 @, s5 z- t2 S8 L& ^2 J; @2 w0 |/ c) P7 C
uchar uchCRCLo = 0xFF ; // low byte of CRC initialized
4 F) E0 N% \* g( U, \( D0 K' I: P# t: v9 ^/ ?
uint uIndex ; // will index into CRC lookup table
# w& ]0 G! C% K$ f1 e+ |- O( R. i+ I P
while (usDataLen--) // Pass through message buffer
" h$ G2 [3 V& o$ D( |6 N
3 I* U" W% m( W2 K{# j. [$ y. K. t7 Y/ j
& \! ^# B7 m1 e
uIndex = uchCRCHi ^ *puchMsg++ ; // calculate the CRC2 h2 W3 |$ x- J7 b* Y
, F6 a3 q) \5 y4 I. Q! V
uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ;" p/ W) ?, p. ^! l" X
) a. {4 S J' _3 J- BuchCRCLo = auchCRCLo[uIndex] ;
( x6 m% W% P9 D: D( h0 I0 g6 V1 V1 K5 z
}( y) K. g& |; f* X
j' }% P+ R/ [+ U7 l
return (((uint)(uchCRCLo) << 8) | uchCRCHi) ;; k; N( y7 U. z9 h: P# y/ s* Q
3 e2 b3 l+ P4 r% j}; h2 C2 W, R/ g
5 `5 _& e! J' O' r' j. I/*------------- init code is following ----------------*/# B! f Q4 ?9 P9 z
9 l, e" r+ X, _void initSFR(void)
' K" _* d. ~; h& ]1 v( J- \0 O& w8 z9 Y7 o8 D# o9 [
{
0 H6 ^: ^ k) U2 }. M. k' I& b0 ^1 t0 _
1 E& }! I1 Q& o3 e( @/ a8 r9 \TH1=0xfa;/ Q9 l% C% v% I7 {/ [' o9 ~
. M+ b C- p2 i, m7 {! @% b
TL1=0xfa; // botelv set 9600 bps/s9 K. `6 Z2 u+ F
* ]+ j1 h5 q5 |) ~- bTMOD=0x21; // T1 8bit timer for uart band rate, T0 16bit timer1 \! @! P/ k$ ~/ S+ U. W; [0 d
$ O) A" s% p6 E/ UPCON=PCON | 0x80; // band rate is 2 times
' k& L& f( }+ b4 }& h* c8 \: R
6 J4 e+ \. a' b! YSCON=0x50; // uart mode is 01,start bit + 8 bit data +stop bit : peer to peer communication
$ i! J* y$ ]: ]# E8 \+ P. B6 { @# e0 f# G* W( a8 j: O
PS=1; // uart intrrupt is hightest0 q/ h2 N- N h$ y t7 U
- e; h3 T: Z0 N$ c) M4 g
TR1=1; // start T1
- S7 ^9 p# `' j) a& i* M/ Q3 P" m3 d/ R8 D. @5 c3 h! w+ @4 C
ES=1; // serially interrupt allow
+ t8 Q% b' r: M' [2 D" E. B* A, {1 X4 v4 M+ a8 b* O
EA=1; // chief interrupt allow! H' k/ \' L1 m) \
6 o: W+ }/ k8 z; a9 v}
, a- q6 F5 t' B, x4 L2 I
4 i5 U; P k. k; L A+ A, @void initvar(void)
6 H5 _9 D# `. U* x% i; y9 ?. G0 J& r& Z h0 ^$ Q+ ]
{" r6 `: f( n b; V6 w" y- a
2 ^7 G! J5 T6 A9 }, t, ?uchar i;
/ V5 [; R7 s8 d5 V4 f- [+ r' C* V) W9 g s5 z# B( C
for (i=0;i<=250;i++)' v# Y& r8 g, _# g7 ~- C: _+ _
! M+ C8 b. k9 J! U+ s% l7 S) ~
_nop_();& g+ P1 y0 D4 a. N
1 `2 g! q! t- g% I6 r9 w" q) oT0=RECIEVE;, C! {! u8 b7 ^8 c7 H" |' p. H$ M* G
6 z* h) U" F' ^6 C/ Z$ @RecFinishF=0;8 f- ]: }6 m6 a
4 ^: c5 b7 ~3 {3 pCommIndex=0;. I" K% B( F, ^. \
9 a* n1 s* Q" G* p- N* U- }CommIndexEnd=0xff; // First enlarge recieve lenght
2 v" ?: z1 J4 i% O9 \! z: |3 h" K* M4 Y
for (i=0;i<MaxRegLen;i++)- s9 m' E K/ T5 ]* ]% m# p
- q3 H) j1 f1 v6 N3 j( ? X
SlaveOutputBuf=SlaveAdr;' m. Z" D: \/ g% i% A% g, b
9 ?( j& Y: Y4 @% K8 C7 K
}
0 Z% V( t* w1 d0 Y$ f; q- J1 S$ P7 ?1 w2 k9 w N$ E- X$ D
void init(void)
! M8 y D& h. _+ R
! z3 v1 A* ?: `& ^' r{% h! f* E) m( o, _ j
* a9 K5 x, G: q0 I( minitSFR();8 }& }4 O* x- l0 ]2 x
( e; ]2 b- @7 L3 l, g2 \3 Binitvar();
7 g( S( n) Z' z
4 f7 h" D. {$ c+ w}; M* o) w) F3 e7 Y) W
3 Z2 @, U6 V! {* Z1 h
void AnalyzeRecieve(void)
) v- _% f8 d) O) c' O- N
& F$ F4 [$ @7 M( G6 X8 I4 u{
& c- U9 T3 p F/ Y3 t" S, `& ^3 X0 h# ^5 n' v" Z. S
uint crc16tem;
6 P$ k$ {7 N8 g( S- t! o5 H
# G& D3 n* R x# h8 d3 Kuchar i,j;
% d/ L8 o1 E0 H0 F4 M* v" N1 p0 ]# }& @; h" W2 t3 P
if (CommBuf[CommIndexSlaveID]==SlaveID) // The slave ID is matched
" I |' y; E: y: `7 d% ]5 a8 p5 _$ n8 X8 w
{9 g9 R2 B* Y9 @ P/ K' [5 S: j
% }7 ]8 T+ K7 ?
crc16tem=crc16(CommBuf,CommIndex-1); // calculate CRC check, erase two CRC byte
5 _' @9 O7 r0 c6 K. H% M, a% a- l. R* [" s* s- C
if (crc16tem==(((uint)(CommBuf[CommIndexEnd]) << 8) | CommBuf[CommIndexEnd-1]))7 I# ^: W5 ^" ^! A* [' g2 q3 C6 C3 @
+ ]2 R2 p/ F$ i: E. H3 {7 e/ Q
{ // crc16 check is OK
" o# j# F) Z4 g+ r1 l
1 t* }3 \+ S* u8 j/ p* g ~switch (CommBuf[CommIndexFunction])
) s) z$ k/ |* Y! \ T# V/ Q3 a
* n1 c* N* }3 U- l{% }6 J2 c/ n, `9 @' _, W: }
8 F8 W- O, z& M4 k! _7 M- z) m; Kcase ReadCoilSta:
# }1 ]% Z3 h/ g; h: ]
0 o7 e7 t- v3 s' ~( q0 v1 C HCommBuf[CommIndexSlaveID]=SlaveID; // 0
5 \' o, d1 I# y$ s' q7 V
$ {# U0 t8 g2 F: d/ X* h0 X6 x! YCommBuf[CommIndexFunction]=ReadCoilSta; // 1
$ q7 P& x" A2 f+ }
, L7 u2 ~1 Z: I; H* a7 C: [; a6 kCommBuf[2]=CommBuf[CommIndexNoPointLo] / 0x08; // 0x16 bit* d' S( S. C/ b; B
: i+ R4 V! e) z: G* R9 I
for (i=0;i<MaxRegLen;i++) // sim inputval for test
5 t% a4 W$ V8 k6 U1 Q+ D6 q
9 W5 O* ~" X6 x- kSlaveOutputBuf=forceval; // send data of master force coil val6 D1 _4 x( k+ x1 d
4 {" q: f" m7 p4 c$ X) r. j# W
i=CommBuf[2]+3;
/ ~* e) p8 X/ W6 |1 X$ n$ P o% M. m2 V* a/ v9 M5 o# f+ q
for(CommIndex=3;CommIndex<i;CommIndex++) // send data Reg to Master9 k- _" _8 K1 N, i! U! n2 Y: |
X9 Q/ K) I( e2 ~$ }
CommBuf[CommIndex]=SlaveOutputBuf[CommIndex-3]; // hight 8 bit is first send
" ^, s. z7 g: Q' X4 e! J- s0 f; R! X
crc16tem=crc16(CommBuf,CommIndex); // then send low 8 bit data
% n e) Y" S# M* K9 V" x
. s3 l/ r- ]# S/ a1 A, ~6 r/ z9 JCommBuf[CommIndex++]=(uchar)(crc16tem & 0x00ff); // send crccheck low 8 bit is front7 Y8 n) G7 D4 m& g$ F& ^
5 ?, T2 C) m% n# Q0 X- Z
CommBuf[CommIndex]=(uchar)(crc16tem>>8); // then send hight 8 bit
1 P& C$ Q$ ^4 {4 K9 q
- _ n. t( ^4 Y `+ jCommIndexEnd=CommIndex;5 e; x" @/ k8 u1 [; c* |5 ]# U
; x' C/ j/ y; V/ s
CommIndex=0;& H( @+ c# A& G# [/ X# X' Z9 _
F6 J/ D u& G9 N5 \# |
SBUF=CommBuf[CommIndex++];2 [9 B( w! \ E! q) \1 @, G' L
9 L/ x8 Z |! {) D# |
break;- F* S4 d0 ]7 j4 Z8 O1 A
+ o7 t9 ?: g4 t+ O
case ForceSingleCoil:
* Y9 p# g; H8 o9 `: ]3 U
% |7 l1 r) G- c* A, [// SlaveInputBuf[0]=CommBuf[4]; // get data 0x00 or 0xff
/ @4 p5 ?: h2 J$ y/ x
1 N6 G' n0 _$ {: fif (CommBuf[4]==0xff). I0 T- K! h6 Y9 y1 Z
6 g2 K9 E' r( B4 ^+ m
LED0=0;
7 g5 I# w$ Q0 @' j$ A8 r0 x5 j! W) B# L6 ~
else4 m! h( {- k$ c+ G: b) _ \0 z* B
( G |, i, I3 z; h3 y( ~LED0=1;/ `* k% T3 ?6 C l1 X" s
: N9 w4 M1 f4 a+ P9 a7 a
// LED0=!LED0;
' q& Z: R! Q6 O: R! R" F
+ ~5 s4 `5 x1 p: }6 o) ^ ]ForceCoilBuf[count]=CommBuf[4];
: I" O, q9 M7 Y( Z* e6 H# }# W- w$ i1 D6 Y2 p: A ~7 O2 {: \0 T
forceval=CommBuf[4];; B w6 |4 U- t) c7 x4 N. x5 _
L0 d* B9 e K- x! j* ccount++;; }1 E+ G- h! p. _4 ]/ M' D
$ I1 r/ f5 N0 J% ]. C6 QCommBuf[CommIndexSlaveID]=SlaveID; // 0 H5 o& P0 L0 Y# P2 A1 Z" R: P
, O: z$ A M: H4 O) s
CommBuf[CommIndexFunction]=ForceSingleCoil; // 1' L: N% D) a: B: o8 g
, @2 ]% N5 D2 z) C n, d" Y% ^
CommIndex=2;
& E6 K6 G; h+ T+ E' i5 ]1 e
5 g- U& ]2 Q9 X4 q( y4 A" f// CommBuf[CommIndex++]=0x00;: ]# @$ L1 {2 x% ?
' g$ ?3 E, S2 S+ r4 s
// CommBuf[CommIndex++]=0x01;7 E3 M+ i; R- z6 e) O' F
' G, ~3 A! b4 C! h// CommBuf[CommIndex++]=0x00;! j3 \. y8 h I9 e/ T7 D( K
# W; t8 o) J4 d
// CommBuf[CommIndex++]=0xff;1 b5 I7 x, G0 q8 u+ D
( v/ s/ O8 T& Q- e0 C// forcesendF=1;
7 H7 H! o5 c' M6 c. Z$ O K1 y# Z$ E! y4 I7 q& c L/ Y. v7 Y
CommBuf[CommIndex++]=CommBuf[CommIndexStartAdrHi]; // 2
* D a) i* W4 E1 G) z
: r! H8 T9 l; d3 d9 ^6 {- V9 SCommBuf[CommIndex++]=CommBuf[CommIndexStartAdrLo]; // 3
1 T. w- J$ j6 B2 N. O' K0 w: i3 L
CommBuf[CommIndex++]=CommBuf[CommIndexNoPointHi]; // 4
* Q7 y6 T1 K( M1 `0 S, x0 w$ r5 K: L
CommBuf[CommIndex++]=CommBuf[CommIndexNoPointLo]; // 5
+ X9 [1 m I* e
3 u/ w" v" A- {. @& N; ~" Xcrc16tem=crc16(CommBuf,CommIndex); // then send low 8 bit data, M7 D7 G9 ?" R4 d: J4 p# t
7 {5 B0 T D8 k4 W
CommBuf[CommIndex++]=(uchar)(crc16tem & 0x00ff); // send crccheck low 8 bit is front
- x" Z9 M% r' X# Z
& z2 K2 z: b2 E1 N4 aCommBuf[CommIndex]=(uchar)(crc16tem>>8); // then send hight 8 bit
% X: s0 ~1 m( X9 r6 Q
1 Q6 q0 ^9 B: l0 G4 fCommIndexEnd=CommIndex;. ^- g4 N z, x/ m
2 P; R3 r. D. a# c. p# j2 dCommIndex=0;
( G. _; [3 N- W& s
% G+ w! V8 G" ]: c" CSBUF=CommBuf[CommIndex++]; P1 a; d8 V6 f i( I$ Z
* w7 p) q8 C# H8 ^- G9 ~* p9 L( P. q- u
break;
+ Q5 I8 I' A6 {$ H8 N0 C
( |0 k' g4 _! i$ {* j0 F& i9 Ocase ReadHoldReg:
7 l+ x/ i- _8 c/ R( s- b6 p
2 G) K' R. Q9 F+ Y A( h, MCommBuf[CommIndexSlaveID]=SlaveID; // 0
2 }* C! B* i5 w! \
" ^+ C2 {: o+ sCommBuf[CommIndexFunction]=ReadHoldReg; // 1
& T1 n N, Y$ R' Y; a1 F4 _( j: Z6 |: I; I
CommBuf[2]=CommBuf[CommIndexNoPointLo]*2; // 2 Byte Count
! l& e) P& K" v) \9 Z9 W
: p1 S3 d/ A Qfor (i=0;i<MaxRegLen;i++) // sim inputval for test
$ ^$ ?$ R: F2 [2 w2 g6 r4 M o( x; k3 q7 F U
SlaveOutputBuf=SlaveAdr;3 X+ w! P8 J7 P7 J* C
' V3 q% D0 z' L- Ei=CommBuf[2]+3;
% ~( |8 p& @! p7 u4 D% R s$ ~
" |* {3 W2 x" E9 A6 M" Xfor(CommIndex=3;CommIndex<i;CommIndex++) // send data Reg to Master
# M2 S) s5 c3 f' \/ a/ p( `4 x5 o" F8 j1 b0 m
CommBuf[CommIndex]=SlaveOutputBuf[CommIndex-3]; // hight 8 bit is first send' ?/ x Y" `. C( z# j
& [0 a8 v, m6 k* u
crc16tem=crc16(CommBuf,CommIndex); // then send low 8 bit data) V! N9 g( k$ f. T; j' H8 h
0 @ [6 m* k9 }! Y( ~9 p4 f! cCommBuf[CommIndex++]=(uchar)(crc16tem & 0x00ff); // send crccheck low 8 bit is front8 W( H* M7 l3 L, X7 U
9 A* T3 b1 L5 d3 Z# s6 x
CommBuf[CommIndex]=(uchar)(crc16tem>>8); // then send hight 8 bit3 W- s" {$ m5 W W9 r8 U, [+ n
2 N- s; w' |# K6 g5 J& L6 ~- V9 @CommIndexEnd=CommIndex;) C1 r, q5 f& u6 q8 O4 ?3 v
* t% A% I) A0 Y( H# g
CommIndex=0;" V8 r1 [' e6 X* t
* l) N' [ q; E8 m+ a: A$ oSBUF=CommBuf[CommIndex++];
* s6 E: j" ^, J9 q, h( z. B2 b
r$ F) A1 ?; q: Xbreak;
* p6 S* X$ o* ~5 s; a6 C& @) C6 h" n6 C4 z( w: f1 L* r
case PresetMulReg:# |3 z2 Z' ]9 E! T; C3 M! E p
9 \3 g) Y" J4 I/ D7 W9 uj=CommBuf[CommIndexNoPointLo]*2;- M( i8 f: }8 n: ]: w
8 F9 T# ~4 E" R* wfor (i=0;i<j;i++)
0 s- r. G# ~" C X1 i- n, n" d- s# d3 x
SlaveOutputBuf[0]=CommBuf[i+7]; // get data that master send start 7th byte9 \* Y" f% ]( W; i0 f+ l
6 U' l; R; C1 X# _
C2 R' w9 r2 m% d( p
* ]1 @* K" o" q4 J; J9 B
ommBuf[CommIndexSlaveID]=SlaveID; // 0$ \; f- L1 u6 K8 h5 b5 ?7 r
( Z( D3 r) W( _# QCommBuf[CommIndexFunction]=PresetMulReg; // 10 `' J6 Z- C- Z* ?2 x. g& Y
$ B' I3 h3 p3 i. {* mCommIndex=2;, x9 V2 y- Z$ |- `, M1 g
* Z2 s# G$ e' V! O5 _CommBuf[CommIndex++]=CommBuf[CommIndexStartAdrHi]; // 2! X5 ~ k* X0 x2 L/ d
$ K* u, y( L' z8 a
CommBuf[CommIndex++]=CommBuf[CommIndexStartAdrLo]; // 3% J7 ]0 D: Q6 C
8 i& C3 l: Y8 K$ z6 _4 m$ y `CommBuf[CommIndex++]=CommBuf[CommIndexNoPointHi]; // 4; D. Y0 h9 W7 w V$ z% P
5 x, e3 r* D. H( C2 }9 F! F: xCommBuf[CommIndex++]=CommBuf[CommIndexNoPointLo]; // 54 d( X* o( B2 P) ?
8 j, G8 y" `* L3 G3 F4 |
crc16tem=crc16(CommBuf,CommIndex); // then send low 8 bit data
: n, F( h) @ X2 f5 M
+ t; R/ ~# l% g( R2 Y( {CommBuf[CommIndex++]=(uchar)(crc16tem & 0x00ff); // send crccheck low 8 bit is front
* E' {: v* {8 @& K8 \. ]
0 N; Y; P1 ]5 h+ W; n# G1 X6 aCommBuf[CommIndex]=(uchar)(crc16tem>>8); // then send hight 8 bit# E& w I: K$ [6 p f5 ~
j7 I7 \% {2 x) s
CommIndexEnd=CommIndex;/ j9 o1 w% O% g5 O7 ]7 J
7 F* ]9 x" W2 XCommIndex=0;
& V2 t D$ W* H1 q% o$ c
: F6 @5 l) |7 `! }3 |SBUF=CommBuf[CommIndex++];
) d1 h7 J' U% `' F, h1 h0 S3 W# o+ e) \8 o9 `% w. A
break;% [% g' h# W& A2 d& o
5 K: [2 T1 a K- h# e6 p9 K2 U
default:
) Q3 c# A: I8 e# c1 y& t5 X
- }6 n3 R4 ~0 ^4 l5 Jfor (i=0;i<=80;i++) // delay // error recieve again
' f) q$ |2 a7 f$ O- ^
/ u9 [5 f' R# `" P! f& f# I& |_nop_();- G. ~2 ^, |1 t" K
4 y% S/ T0 ~ }
CommIndex=0;
) x- i( g- J7 y0 X# b" ~3 ]: m/ D( ? i
T0=RECIEVE;$ k- ?2 I8 L# C. \5 H S9 h0 d
! j6 R" {. [/ y) r0 t* ebreak;5 ^3 H5 F# e9 [& {, h+ v! w
4 H# g8 e& x( Z4 Y7 P
}' j" l7 ^1 a- r1 {& j4 @
9 Z' ?; ]" T7 T* J}
- t Y2 x& N$ N
# @! c; [1 `8 l6 Ielse1 }( E8 O$ Z: F4 R& M: y( E& x
+ n+ [0 g& _' R5 D) y
{1 l: A5 g5 A, b, ^
* X5 U' G# S, u, d7 Y4 m: S$ c3 s
for (i=0;i<=80;i++) // delay
! k# `7 O) v; N- o4 G' U2 S3 n! o3 |% [1 x- M
_nop_();
1 O! ~4 i, P" g$ I/ h2 j. o1 M! r
. u4 U% N0 Q" c# [CommIndex=0;
7 P& U8 G% ~8 I+ g+ @& ~7 ~* c3 H* k- s: b: B4 U3 _; |% e
T0=RECIEVE;
/ B4 E! y1 S! }: {" L3 I! V
: k" J4 V f+ U- L7 v% x}
" E- [! ?% B9 L3 \0 {: T; h9 e2 U# |1 }5 S5 K6 H/ i8 p3 O
}4 Q7 i2 n" \( i( h# C9 N
- x5 ^7 a9 {# }' v$ n8 U
}
' g* k7 o: B5 ?7 Z5 y0 Z5 R0 E" W( z% m4 l( g" m. ^+ v/ Q$ U& F
/*------------- intr code is following ----------------*/1 \- u1 ^! r6 C& I
% q7 ?: G, b7 c1 a3 s; ~. g
void slavecomm(void) interrupt 4 using 2& ^+ J5 c( D6 O [
) p3 l! u8 P7 _% h7 E
{) `5 S `% b* C2 b/ @" c% b E/ }
1 T. {+ j- T* h: b- E3 huint i;
4 |4 p; B$ z" I' z$ G' p: u" {" U: z# y' n8 D
ES=0;1 ~; l+ ]0 H- j- Z9 r# e
1 N5 K/ ~& F: h
if(TI)
; s* B; ?' o% h/ m* b/ |4 S
; r) M; U. _& ~2 h{
) H. `% k4 }- e: R5 [# p6 S# z" w0 Z/ R6 }" O0 S0 @' t
TI=0;
! _( v f' w9 W6 `6 l( s, c( {$ g2 v" V; @& m3 z
if (CommIndex<=CommIndexEnd)$ d4 \5 ~! R# M8 p! k! ^
3 \5 r9 X9 g$ D2 [
{( P9 h7 o; W) m' P
8 _3 g, N0 w6 {% R7 J; t% U
SBUF=CommBuf[CommIndex++];
; @( Q1 A& l- a. H0 {) q% u: f: e4 @5 g: a
}
! Y5 I$ N/ j" ~0 i7 b
4 v/ s9 ?2 M3 \6 J" c, `0 Relse1 Y5 C1 k) m$ q* {5 `; V5 H5 ?
8 z5 g! g& M) B% w3 o4 j, u0 a. ]
{( E9 d2 P/ j8 |7 H0 C7 t. A
1 V1 i& |/ o6 D% k: j; v// if (forcesendF)6 a; Y2 Z* {5 _& e
" N9 [" I3 J; G) Q: d& |; p2 {// _nop_();
2 r) X- E* V4 u7 S
5 @, I7 r; q+ h( W: R9 A$ }for (i=0;i<=SendRecieveDelay;i++) // delay
8 \6 U" r- t9 ~1 p
3 |7 R0 M5 c6 `9 i" S) u_nop_();! f$ V- K, ?( s4 c+ X A: Y5 b
' c- z2 M" Y& i! @8 TCommIndex=0;
' ]& {# @0 t( a& @; \; o! E- n
3 G& K5 w* z6 n' V+ @; K0 PT0=RECIEVE;
5 y% T, m* N: m1 {: C% Z/ a2 e* D
}6 u4 K# {4 S$ t" I# b
1 t! T( F9 d3 c/ Y}
) T7 G% a% }! I5 i8 [: }* t+ l' T* k7 i/ C2 k" B1 d$ R* X
if(RI)
3 O W5 K7 z0 u V G+ N/ p9 q- ], N8 q, ]1 S U% V5 \
{6 A) ^0 `# T p0 f9 u
9 F' D- T6 r( h% A& j* g- ZRI=0;* f( f2 T( G8 v+ w
! c% \6 I/ t6 c$ E. R! |( K
if (CommIndex<CommIndexEnd) // CommIndex less than recieve lenght- a2 s7 \& G% F! R( y& H, ~0 U
% X" D ~( w% h% q8 B) ]9 ~1 \7 W' V{
- W3 \% h# ~$ b# o& q g
( Z% T9 m. ?5 ACommBuf[CommIndex]=SBUF;
3 o; J. [4 Y' d/ r# e: f( @& } J) F4 P. t$ h. Z$ O5 I
if (CommIndex==CommIndexFunction)
! R3 Z5 f/ M0 r1 ]. _! B
9 g+ ]9 S+ c& f* F{
3 _, T8 |: j7 c. @ x1 H1 y$ p& x6 m% c% T
switch (CommBuf[CommIndexFunction])
5 f- \6 Z/ \6 t- k6 v1 `. A2 w& l. @4 u+ N3 U* G: [
{) }% s& B. Z; Q
% C( k/ ^+ K( `+ w9 b
case ReadCoilSta:) u/ r7 ?) r- V- W+ b
" [; U0 _3 g! V" H8 I4 W# j2 [9 w
CommIndexEnd=ReadCoilStaIndexEnd;
: X8 O- B7 r. W2 C) n: U. E: I4 R
break;: W# j8 T& R6 g
9 ?; k* X/ W; n& G+ a- g
case ForceSingleCoil:
2 @ g" _: s1 l9 n/ q; y
X! }3 ]' J m0 ~1 xCommIndexEnd=ForceSingleCoilIndexEnd;
/ r9 |/ O0 A" y( y2 u- d0 i1 ^8 R% a5 s+ z" B; R
break;
/ \! ^' d% f2 e3 J- f8 X% t7 {' Y t; d* n
case ReadHoldReg:
2 U3 |6 ]( l: W. {% g3 u! n: {+ H) b5 _
CommIndexEnd=ReadHoldRegIndexEnd;4 C( w* j" o1 Y4 m
7 D1 R0 D4 f: w7 J; {break;
, \% C/ Q2 ]* K+ m7 m) ]
4 m5 d8 ]: k( s/ m6 U% ]9 Zcase PresetMulReg:
9 p8 I0 ]' K5 n6 C
+ f) k7 @4 A8 Q: g( T* eCommIndexEnd=6+CommBuf[CommIndexNoPointLo]*2+2;+ x, {# E6 l2 C7 u- k5 B, R
: x" x' O1 }1 U* e# d+ Fbreak;
: K3 Y8 L# C, h# W) I4 B) p3 E8 Y
4 Q7 j7 `: j5 f+ vdefault:
) G) X5 k! l+ O, F8 L. V" d9 V! J" u5 G$ q! y$ L
break;* w) r3 L' c2 s
0 W3 F' V' _1 R7 D6 O1 ~$ |) H* r
}
; \2 _- ^" ^9 h+ [* i5 j; E6 r: W" L* E- c! L
}$ q5 I) I% F2 n6 }8 C: y
( S# l( {/ }2 r4 `* b
CommIndex++;
_9 G: Y# l E) y7 R$ B: s# n- ?+ z2 e" {1 }
}+ j4 V; d- d. q" O7 S8 C' R
3 p. G- q" Q$ V) D+ Jelse // recieve finished CommIndex==CommIndexEnd( Y% a g# _! a3 P* K+ S
" C; K9 {1 z+ p) `4 d2 n{7 ?. [( J. |6 m! H8 Q/ `! v+ S
% S0 W4 _9 s3 v6 m! dCommBuf[CommIndexEnd]=SBUF;
* p4 ^/ G, S: J* V( ?& q
' O- U. |+ ?: A u6 H& PRecFinishF=1;
* ]7 ?& \; i! R0 c% q- S# F% t
- e0 b0 G4 b/ v7 D4 zfor (i=0;i<=Sen6 i) C6 F( @$ \- n: `
H/ V8 [$ Q: ]+ B/ z+ ^" B1 ^& ?dRecieveDelay;i++) // delay
4 g3 p; q* \8 K$ a
) q9 ^; \& M7 ?_nop_();
6 i$ [, \& C1 p- Y- a1 `. b/ W! v7 d7 n3 z
T0=SEND;. d% L( r; \9 z; ^+ j% s9 K2 u
. t# U6 z; n- z# C
}* F, W5 L$ @% h, _2 i2 a, s+ P$ d" P$ k
( @1 T: s( e' n' Y}" O. o: {6 q& }& t; ~7 R
- u4 J; c$ k; T1 K, ~
ES=1;
0 X- C9 a0 t8 H3 C" M) F# o! Y E' {, q- r* D _% _
}
1 h, R, }8 g) F! T2 z$ R& n5 H3 i1 U
/*------------------ main code following -----------------*/( C4 L& U+ |1 B q
7 E7 `( m- s3 s8 n2 N7 _! Y2 B! ]7 v( zvoid main(void)
: t! i# O+ b, P
% f }0 \/ \7 Y5 H: X5 f3 T1 }" y4 o{/ Y8 D/ _1 H1 K$ |( u2 A( A
1 i* ^- N' Y4 U. S, P
uint data i;" _6 A' g$ w9 b9 A; H+ d
( H" \) `3 C* c5 O( l2 Winit();, V+ \# }; P9 C
X- l5 e" v# P+ i7 qwhile(1)" N I5 n0 ?) D0 h) z* }& m% l
9 R- p. l& E: h/ `3 o. ]0 i
{
& M2 E# E8 \" v% z0 R8 i2 o
% J0 X% R" X3 g/ |// LED0=!LED0;
0 c& g3 V. M0 ^+ d9 \
! h% A* Q% w G4 h' N7 Ifor(i=0;i<=9;i++)- b) G5 ] R+ C- v N( O
- W% c1 G1 E1 c5 T3 g- I6 E$ s
_nop_();/ c/ k$ Y6 O) [: a; [9 g
* e: y% n9 S5 |: }$ |
if (RecFinishF)
b2 f# e8 ?3 D& z7 J1 r% d$ \5 Y& F: A! S" v3 t
{
4 H% l0 R5 P4 _2 }2 x5 ]" [" h4 J5 W$ O% m
AnalyzeRecieve();1 M1 @% q# S( ~$ J* f6 k' H, |
: X4 }' e0 O5 E! cRecFinishF=0;
: @+ B# D/ ~# E3 F# t1 i( L! X' P+ ~6 g0 o4 A5 s
}
/ W! g+ j- w5 C4 }
4 a+ c) X% | Q7 H. l. ^, k}
7 m5 U$ [/ x& `0 @8 A
$ x! X5 l! E( W. F& I}% \8 P4 T w/ S' N+ F% B
/ D* X3 Y2 i7 `. ?3 [; o8 _* F |
|