1045 |
jacho |
1 |
#include "C:\Users\Honza\Documents\pic\I2C_bat_cteni\main.h" |
|
|
2 |
|
|
|
3 |
#define EEPROM_SDA PIN_B0 |
|
|
4 |
#define EEPROM_SCL PIN_B1 |
|
|
5 |
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL) |
|
|
6 |
#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD |
|
|
7 |
|
|
|
8 |
|
|
|
9 |
void main() |
|
|
10 |
{ |
|
|
11 |
|
|
|
12 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
13 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
14 |
setup_spi(SPI_SS_DISABLED); |
|
|
15 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
16 |
setup_timer_1(T1_DISABLED); |
|
|
17 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
18 |
setup_ccp1(CCP_OFF); |
|
|
19 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
|
|
20 |
|
|
|
21 |
printf("Simple Thermomether \r\n",); |
|
|
22 |
unsigned int8 STAV1,STAV2; |
|
|
23 |
|
|
|
24 |
unsigned int16 SOUCET, SOUCET1; |
|
|
25 |
unsigned int8 LSB; |
|
|
26 |
//unsigned int8 |
|
|
27 |
|
|
|
28 |
//while(TRUE) |
|
|
29 |
//{ |
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
i2c_start(); //blockdatacontrol |
|
|
35 |
I2C_Write(0xAA); |
|
|
36 |
I2C_write(0x61); |
|
|
37 |
i2c_start(); |
|
|
38 |
I2C_Write(0xAA); |
|
|
39 |
i2c_write(0x00); |
|
|
40 |
i2c_stop(); |
|
|
41 |
delay_ms (1); |
|
|
42 |
|
|
|
43 |
|
|
|
44 |
i2c_start();//dataflashclass |
|
|
45 |
I2C_Write(0xAA); |
|
|
46 |
I2C_write(0x3e); |
|
|
47 |
|
|
|
48 |
i2c_start(); |
|
|
49 |
I2C_Write(0xAA); |
|
|
50 |
i2c_write(0x40); |
|
|
51 |
i2c_stop(); |
|
|
52 |
delay_ms (1); |
|
|
53 |
|
|
|
54 |
|
|
|
55 |
i2c_start();//dataflashblock |
|
|
56 |
I2C_Write(0xAA); |
|
|
57 |
I2C_write(0x3f); |
|
|
58 |
|
|
|
59 |
i2c_start(); |
|
|
60 |
I2C_Write(0xAA); |
|
|
61 |
I2C_write(0x00); |
|
|
62 |
i2c_stop(); |
|
|
63 |
|
|
|
64 |
delay_ms (1); |
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
int i=64; |
|
|
74 |
SOUCET=0; |
|
|
75 |
for (i=64;i<=96;++i) |
|
|
76 |
{ |
|
|
77 |
printf("%u\r\n",i); |
|
|
78 |
i2c_stop(); |
|
|
79 |
|
|
|
80 |
i2c_start();//blockdata |
|
|
81 |
I2C_Write(0xAA); |
|
|
82 |
I2C_write(i); |
|
|
83 |
|
|
|
84 |
i2c_start(); |
|
|
85 |
I2C_Write(0xAB); |
|
|
86 |
STAV1=I2C_read(0); |
|
|
87 |
i2c_stop(); |
|
|
88 |
|
|
|
89 |
printf("STAV %lX \r\n", STAV1); |
|
|
90 |
SOUCET=SOUCET+STAV1; |
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
} |
|
|
97 |
SOUCET1=SOUCET; |
|
|
98 |
SOUCET1=SOUCET1>>8; |
|
|
99 |
printf("Deleno 256: %lX (procenta)\r\n", SOUCET1); |
|
|
100 |
SOUCET1=SOUCET-SOUCET1; |
|
|
101 |
printf("Soucet - soucet/256: %lX \r\n", SOUCET1); |
|
|
102 |
LSB=(unsigned int8)SOUCET1; |
|
|
103 |
printf("LSB: %lX\r\n", LSB); |
|
|
104 |
//printf("Stav: %X (procenta)\r\n", STAV2); |
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
delay_ms (100); |
|
|
110 |
} |