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
| #include <16F1789.h>
#fuses NOWDT, NOBROWNOUT, NOMCLR
#use delay(internal=8MHz, clock=8MHz)
#include <PIC16F1789_registers.h>
#use rs232(baud=9600,parity=N,xmit=PIN_B6,rcv=PIN_B7,bits=8,stream=PORT1)
#use spi(MASTER, CLK = PIN_C3, DI = PIN_C4, DO = PIN_C5, BAUD = 9600, BITS = 16, STREAM = PORT2, MODE = 2 )
void main()
{
TRISC2 = 0;
while(True)
{
RC2 = 0;
////////////////////////////////////////////
spi_write(PORT2, 0xAB);
spi_write(PORT2, 0x30);
RC2 = 1;
delay_us(5);
RC2 = 0;
spi_write(PORT2, 0x00);
spi_write(PORT2, 0x00);
delay_us(5);
int16 vol_X = spi_xfer(PORT2);
/////////////////////////////////////////////
RC2 = 1;
fputc(vol_X, PORT1);
delay_ms(500);
}
} |