1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| program UDP
' mE ehternet NIC pinout
dim SPI_Ethernet_RST as sbit at RC0_bit
dim SPI_Ethernet_CS as sbit at RC1_bit
dim SPI_Ethernet_RST_Direction as sbit at TRISC0_bit
dim SPI_Ethernet_CS_Direction as sbit at TRISC1_bit
' end mE ehternet NIC pinout
const SPI_Ethernet_HALFDUPLEX = 0
const SPI_Ethernet_FULLDUPLEX = 1
const _SPI_Ethernet_CRC = 0x20
const _SPI_Ethernet_MULTICAST = 0x02
' Declarations section
dim myMacAddr as byte[6] ' my MAC address
myIpAddr as byte[4] ' my IP address
ipMask as byte[4] ' network mask (for example : 255.255.255.0)
gwIpAddr as byte[4] ' gateway (router) IP address
dnsIpAddr as byte[4] ' DNS server IP address
ipServeur as byte[4] ' IP adress serveur
dim msg as string[20]
res_txt as string[5]
res, channel as word
dim txt as string[20]
sub procedure SPI_Ethernet_confNetwork(dim byref ipMask, gwIpAddr, dnsIpAddr as byte[4])
end sub
sub function SPI_Ethernet_UserTCP(dim remoteHost as ^byte, dim remotePort as word, dim localPort as word, dim reqLength as word, dim byref canClose as byte) as word
result = 0
end sub
sub function SPI_Ethernet_UserUDP(dim remoteHost as ^byte, dim remotePort as word, dim destPort as word, dim reqLength as word) as word
result = 0
end sub
sub function SPI_Ethernet_sendUDP(dim byref destIP as byte[4], dim sourcePort, destPort as word, dim pkt as ^byte, dim pktLen as word) as byte
result = 1
end sub
main :
ADCON1 = 6 ' digital
TRISA = 1
TRISC = 0
myMacAddr[0] = 0x00
myMacAddr[1] = 0x14
myMacAddr[2] = 0xA5
myMacAddr[3] = 0x76
myMacAddr[4] = 0x19
myMacAddr[5] = 0x3F
myIpAddr[0] = 192
myIpAddr[1] = 168
myIpAddr[2] = 0
myIpAddr[3] = 2
gwIpAddr[0] = 192
gwIpAddr[1] = 168
gwIpAddr[2] = 0
gwIpAddr[3] = 6
dnsIpAddr[0] = 192
dnsIpAddr[1] = 168
dnsIpAddr[2] = 0
dnsIpAddr[3] = 100
ipMask[0] = 255
ipMask[1] = 255
ipMask[2] = 255
ipMask[3] = 0
Ipserveur[0] = 192
Ipserveur[1] = 168
Ipserveur[2] = 0
Ipserveur[3] = 3
SPI1_init()
SPI_Ethernet_Init(myMacAddr, myIpAddr, SPI_Ethernet_FULLDUPLEX)
SPI_Ethernet_confNetwork(ipMask, gwIpAddr, dnsIpAddr) ' set network configuration parameters
SPI_ethernet_enable(_SPI_Ethernet_CRC or _SPI_Ethernet_MULTICAST)
while True
PORTA.0 = 1
wend
'#######String Concatenating#######'
' Get result of ADC
'res = Adc_Read(channel)
'WordToStr(res, res_txt) 'Create string out of numeric result
''res_txt = "\r"
' Prepare message for output
'msg = "halt"+
'res_txt
txt ="run\r"
SPI_Ethernet_sendUDP(IpServeur, 10001, 3040, @txt,Strlen (txt))' send Hello message to the above IP address, from UDP port 10001 to UDP port 10001
end. |
Partager