-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
84 lines (65 loc) · 1.94 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <p30f4013.h>
#include <uart.h>
#include "config.h"
#include "uart.h"
#include "timers.h"
#include "adc.h"
extern unsigned char txBuffer[];
extern unsigned char txPtr;
unsigned char isConnected = 0;
//unsigned char hello[] ="Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!!!!";
unsigned char hello[] ="Hello World!Hello World!Hello W";
extern unsigned int ADC10;
void delay(unsigned int d) {
__delay32(d*10000);
}
int main(void) {
int i;
char flipbit=0;
char senddata=0;
unsigned int adc10;
TRISB = 0;
_TRISB10 = 1;
_LATD2 = 1;
_TRISD2 = 1;
initADC();
initUART();
initTimer4();
startTimer4();
adc10 = ADC10;
while (1) {
if (!flipbit && _RD2==0) {
DELAY_MS(100);
if (_RD2==0) {
senddata=!senddata;
flipbit = 1;
}
}
if (flipbit && _RD2==1) {
DELAY_MS(100);
if (_RD2==1) flipbit = 0;
}
_LATB3 = senddata;
if (isConnected) {
if (adc10!=ADC10) {
adc10 = ADC10;
WriteWebSocket(0x82); //FIN bit high and opcode=2 (binary)
WriteWebSocket(0x02); //payload length
WriteWebSocket(adc10 & 0x00ff);
WriteWebSocket((adc10 & 0xff00)>>7);
Commit();
}
else if (senddata) {
WriteWebSocket(0x81); //FIN bit high and opcode=1
WriteWebSocket(sizeof(hello)); //payload length
for (i=0;i<sizeof(hello);i++)
WriteWebSocket(hello[i]);
Commit();
}
}
DELAY_MS(10);
ReadWebSocket();
}
}