1 | $regfile = "m16def.DAT"
|
2 | $crystal = 8000000
|
3 | $baud = 9600
|
4 | $loadersize = 512
|
5 | $hwstack = 64
|
6 | $swstack = 48
|
7 | $framesize = 60
|
8 |
|
9 | '--------[Serial Output]----------
|
10 | Sub Send_data(byval Byte1_w As Byte , Byval Byte2_w As Byte , Byval Byte3_w As Byte , Byval Byte4_w As Byte , Byval Byte5_w As Byte , Byval Byte6_w As Byte , Byval Byte7_w As Byte)
|
11 | Linebusy = 1
|
12 | Txcomplete = 0
|
13 | Crcbyte_w = Crc(byte1_w , Byte2_w , Byte3_w , Byte4_w , Byte5_w , Byte6_w , Byte7_w) ' make send Checksum
|
14 | Waitms 2
|
15 | Portc.7 = 1 'set RS485 to Send Mode
|
16 | Waitus 7 'wait for tranceiver switched to send mode
|
17 | Ucsrb.0 = 1 ' mark next Byte in UDR as Adress
|
18 | Udr = Byte1_w ' Set Byte in UDR (Recipient)
|
19 | Ucsrb.0 = 0 ' mark next Byte in UDR as Data
|
20 | Printbin Byte2_w ; Byte3_w ; Byte4_w ; Byte5_w ; Byte6_w ; Byte6_w ; Crcbyte_w ; 'Sending without line feed
|
21 | While Txcomplete = 0
|
22 | nop
|
23 | Wend
|
24 | 'Print #2 , "Sended--->" ; "To:" ; Byte1_w ; " From:" ; Byte2_w ; " Command:" ; Byte3_w ; " D1:" ; Byte4_w ; " D2:" ; Byte5_w ; " D3:" ; Byte6_w ; " D4:" ; Byte7_w ; " CRC:" ; Crcbyte_w 'set RS485 to receive mode
|
25 | 'Linebusy = 0
|
26 | Return
|
27 | End Sub
|
28 | '^^^^^^^^[END of Serial Output]^^^^^^^^^^
|
29 |
|
30 | '--------<<Serial input IRQ>>------------
|
31 | Receive:
|
32 | Linebusy = 1
|
33 | Adressflag = Ucsrb.1 'Read UCSRB Register Bit 1 (RXB8) for determing the 9th Bit
|
34 | Inbyte = Udr 'Read UDR into Byte VAR
|
35 | If Inbyte = Unitid And Rxactive = 0 Then 'compare received Unitid
|
36 | Ucsra.0 = 0 'Reset UCSRA.0 (MPCM) to get Data Frames
|
37 | Ucsrb.1 = 0 'Reset UCSRB.1 (RXB8) to be ready for a other 9th Bit
|
38 | Rxactive = 1 'Set RXactive Flag
|
39 | Broadcast_flag = 0 'Set Broadcast Flag
|
40 | End If
|
41 | 'Determ If Broadcast Is Send
|
42 | If Inbyte = 0 And Rxactive = 0 Then 'compare received Unitid
|
43 | Ucsra.0 = 0 'Reset UCSRA.0 (MPCM) to get Data Frames
|
44 | Ucsrb.1 = 0 'Reset UCSRB.1 (RXB8) to be ready for a other 9th Bit
|
45 | Rxactive = 1 'Set RXactive Flag
|
46 | Broadcast_flag = 1 'Set Broadcast Flag
|
47 | End If
|
48 |
|
49 |
|
50 | If Rxactive = 1 Then
|
51 | Incr Arraycounter 'count up Array
|
52 | Datastring_r(arraycounter) = Inbyte ' Fill Array with received Data
|
53 | End If
|
54 |
|
55 | If Arraycounter = 8 Then
|
56 | Ucsra.0 = 1 ' set Ucsra MPCM Mode on if last Byte is Transmitted
|
57 | Stringcomplete = 1 ' Set Flag for complete transmission
|
58 | Arraycounter = 0 ' Reset Arraycounter
|
59 | Rxactive = 0 ' Reset RXactive
|
60 | Linebusy = 0
|
61 | Adressflag = 0 'Reset Adressflag
|
62 | Crc_check = Crc(datastring_r(1) , Datastring_r(2) , Datastring_r(3) , Datastring_r(4) , Datastring_r(5) , Datastring_r(6) , Datastring_r(7)) ' Make Checksum of Received Data
|
63 | Print #2 , "received-> " ; "From:" ; Datastring_r(2) ; " To:" ; Datastring_r(1) ; " Command:" ; Datastring_r(3) ; " D1:" ; Datastring_r(4) ; " D2:" ; Datastring_r(5) ; " D3:" ; Datastring_r(6) ; " D4:" ; Datastring_r(7) ; " CRC:" ; Datastring_r(8)
|
64 |
|
65 | End If
|
66 | Return
|
67 | '^^^^^^^^[END of serial input]^^^^^^^^^^^^
|
68 |
|
69 | '-------<<IRQ for sending complete>>------
|
70 | Send_complete:
|
71 | Waitus 14
|
72 | Portc.7 = 0
|
73 | Txcomplete = 1
|
74 | Return
|
75 | '^^^^^<<END IRQ sending complete>>^^^^^^^^
|