Line 4... |
Line 4... |
4 |
#define RAM_Access 0x00 // RAM access command |
4 |
#define RAM_Access 0x00 // RAM access command |
5 |
#define RAM_Tobj1 0x07 // To1 address in the RAM |
5 |
#define RAM_Tobj1 0x07 // To1 address in the RAM |
6 |
#define RAM_Tamb 0x06 // Ta address in the RAM |
6 |
#define RAM_Tamb 0x06 // Ta address in the RAM |
7 |
|
7 |
|
8 |
|
8 |
|
9 |
//*High and Low level of clock |
9 |
// High and Low level of clock |
10 |
#define HIGHLEV 40 // max. 50us |
10 |
#define HIGHLEV 40 // max. 50us |
11 |
#define LOWLEV 100 // max. 30ms |
11 |
#define LOWLEV 100 // max. 30ms |
12 |
#define TBUF 20 |
12 |
#define TBUF 20 |
13 |
|
13 |
|
14 |
//SMBus control signals |
14 |
// SMBus control signals |
15 |
#define SCL PIN_B0 |
15 |
#define SCL PIN_B0 |
16 |
#define SDA PIN_B1 |
16 |
#define SDA PIN_B1 |
17 |
|
17 |
|
18 |
#define mSDA_HIGH() output_float(SDA); // SDA float |
18 |
#define mSDA_HIGH() output_float(SDA); // SDA float |
19 |
#define mSDA_LOW() output_low(SDA); // SDA low |
19 |
#define mSDA_LOW() output_low(SDA); // SDA low |
20 |
#define mSCL_HIGH() output_float(SCL); //output_high(SCL); // SCL high |
20 |
#define mSCL_HIGH() output_float(SCL); // SCL float |
21 |
#define mSCL_LOW() output_low(SCL); // SCL low |
21 |
#define mSCL_LOW() output_low(SCL); // SCL low |
22 |
|
22 |
|
23 |
#define ACK 0 |
23 |
#define ACK 0 |
24 |
#define NACK 1 |
24 |
#define NACK 1 |
25 |
|
25 |
|
26 |
//********************************************************************************************** |
26 |
//********************************************************************************************** |
Line 35... |
Line 35... |
35 |
//********************************************************************************************** |
35 |
//********************************************************************************************** |
36 |
void SMB_START_bit(void) |
36 |
void SMB_START_bit(void) |
37 |
{ |
37 |
{ |
38 |
// disable_interrupts(GLOBAL); |
38 |
// disable_interrupts(GLOBAL); |
39 |
mSDA_HIGH(); // Set SDA line |
39 |
mSDA_HIGH(); // Set SDA line |
40 |
delay_us( TBUF ); // Wait a few microseconds |
40 |
delay_us( TBUF ); // Wait a few microseconds |
41 |
mSCL_HIGH(); // Set SCL line |
41 |
mSCL_HIGH(); // Set SCL line |
42 |
delay_us( TBUF ); // Generate bus free time between Stop |
42 |
delay_us( TBUF ); // Generate bus free time between Stop |
43 |
// and Start condition (Tbuf=4.7us min) |
43 |
// and Start condition (Tbuf=4.7us min) |
44 |
mSDA_LOW(); // Clear SDA line |
44 |
mSDA_LOW(); // Clear SDA line |
45 |
delay_us( TBUF ); // Hold time after (Repeated) Start |
45 |
delay_us( TBUF ); // Hold time after (Repeated) Start Condition. |
46 |
// Condition. After this period, the first clock is generated. |
46 |
// After this period, the first clock is generated. |
47 |
//(Thd:sta=4.0us min) |
47 |
// (Thd:sta=4.0us min) |
48 |
mSCL_LOW(); // Clear SCL line |
48 |
mSCL_LOW(); // Clear SCL line |
49 |
// enable_interrupts(GLOBAL); |
49 |
// enable_interrupts(GLOBAL); |
50 |
delay_us( TBUF ); // Wait a few microseconds |
50 |
delay_us( TBUF ); // Wait a few microseconds |
51 |
} |
51 |
} |
- |
|
52 |
|
52 |
//********************************************************************************************* |
53 |
//********************************************************************************************* |
53 |
// STOP CONDITION ON SMBus |
54 |
// STOP CONDITION ON SMBus |
54 |
//********************************************************************************************* |
55 |
//********************************************************************************************* |
55 |
//Name: STOPbit |
56 |
//Name: STOPbit |
56 |
//Function: Generate STOP condition on SMBus |
57 |
//Function: Generate STOP condition on SMBus |
Line 61... |
Line 62... |
61 |
//********************************************************************************************* |
62 |
//********************************************************************************************* |
62 |
void SMB_STOP_bit(void) |
63 |
void SMB_STOP_bit(void) |
63 |
{ |
64 |
{ |
64 |
// disable_interrupts(GLOBAL); |
65 |
// disable_interrupts(GLOBAL); |
65 |
mSDA_HIGH(); |
66 |
mSDA_HIGH(); |
66 |
mSCL_LOW(); // Clear SCL line |
67 |
mSCL_LOW(); // Clear SCL line |
67 |
delay_us( TBUF ); // Wait a few microseconds |
68 |
delay_us( TBUF ); // Wait a few microseconds |
68 |
mSDA_LOW(); // Clear SDA line |
69 |
mSDA_LOW(); // Clear SDA line |
69 |
delay_us( TBUF ); // Wait a few microseconds |
70 |
delay_us( TBUF ); // Wait a few microseconds |
70 |
mSCL_HIGH(); // Set SCL line |
71 |
mSCL_HIGH(); // Set SCL line |
71 |
delay_us( TBUF ); // Stop condition setup time(Tsu:sto=4.0us min) |
72 |
delay_us( TBUF ); // Stop condition setup time(Tsu:sto=4.0us min) |
72 |
mSDA_HIGH(); // Set SDA line |
73 |
mSDA_HIGH(); // Set SDA line |
73 |
// enable_interrupts(GLOBAL); |
74 |
// enable_interrupts(GLOBAL); |
74 |
} |
75 |
} |
75 |
|
76 |
|
76 |
|
77 |
|
Line 97... |
Line 98... |
97 |
unsigned char SMB_Receive_bit(void) |
98 |
unsigned char SMB_Receive_bit(void) |
98 |
{ |
99 |
{ |
99 |
unsigned char Ack_bit; |
100 |
unsigned char Ack_bit; |
100 |
|
101 |
|
101 |
// disable_interrupts(GLOBAL); |
102 |
// disable_interrupts(GLOBAL); |
102 |
mSDA_HIGH(); //_SDA_IO=1; // SDA-input |
103 |
mSDA_HIGH(); //_SDA_IO=1; // SDA-input |
103 |
mSCL_HIGH(); // Set SCL line |
104 |
mSCL_HIGH(); // Set SCL line |
104 |
delay_us( HIGHLEV ); // High Level of Clock Pulse |
105 |
delay_us( HIGHLEV ); // High Level of Clock Pulse |
105 |
if(input(SDA)) Ack_bit=1; // \ Read acknowledgment bit, save it in Ack_bit |
106 |
if(input(SDA)) Ack_bit=1; // \ Read acknowledgment bit, save it in Ack_bit |
106 |
else Ack_bit=0; // / |
107 |
else Ack_bit=0; // / |
107 |
mSCL_LOW(); // Clear SCL line |
108 |
mSCL_LOW(); // Clear SCL line |
108 |
|
109 |
|
109 |
toggle_dome(); |
110 |
toggle_dome(); |
110 |
|
111 |
|
Line 132... |
Line 133... |
132 |
unsigned char bit_out; |
133 |
unsigned char bit_out; |
133 |
|
134 |
|
134 |
for(Bit_counter=8; Bit_counter; Bit_counter--) |
135 |
for(Bit_counter=8; Bit_counter; Bit_counter--) |
135 |
{ |
136 |
{ |
136 |
if(Tx_buffer&0x80) bit_out=1; // If the current bit of Tx_buffer is 1 set bit_out |
137 |
if(Tx_buffer&0x80) bit_out=1; // If the current bit of Tx_buffer is 1 set bit_out |
137 |
else bit_out=0; // else clear bit_out |
138 |
else bit_out=0; // else clear bit_out |
138 |
|
139 |
|
139 |
SMB_send_bit(bit_out); // Send the current bit on SDA |
140 |
SMB_send_bit(bit_out); // Send the current bit on SDA |
140 |
Tx_buffer<<=1; // Get next bit for checking |
141 |
Tx_buffer<<=1; // Get next bit for checking |
141 |
} |
142 |
} |
142 |
|
143 |
|
143 |
Ack_bit=SMB_Receive_bit(); // Get acknowledgment bit |
144 |
Ack_bit=SMB_Receive_bit(); // Get acknowledgment bit |
144 |
|
145 |
|
145 |
return Ack_bit; |
146 |
return Ack_bit; |
146 |
} |
147 |
} |
147 |
|
148 |
|
148 |
//********************************************************************************************* |
149 |
//********************************************************************************************* |
Line 159... |
Line 160... |
159 |
unsigned char RX_buffer; |
160 |
unsigned char RX_buffer; |
160 |
unsigned char Bit_Counter; |
161 |
unsigned char Bit_Counter; |
161 |
|
162 |
|
162 |
for(Bit_Counter=8; Bit_Counter; Bit_Counter--) |
163 |
for(Bit_Counter=8; Bit_Counter; Bit_Counter--) |
163 |
{ |
164 |
{ |
164 |
if(SMB_Receive_bit()) // Get a bit from the SDA line |
165 |
if(SMB_Receive_bit()) // Get a bit from the SDA line |
165 |
{ |
166 |
{ |
166 |
RX_buffer <<= 1; // If the bit is HIGH save 1 in RX_buffer |
167 |
RX_buffer <<= 1; // If the bit is HIGH save 1 in RX_buffer |
167 |
RX_buffer |=0b00000001; |
168 |
RX_buffer |=0b00000001; |
168 |
} |
169 |
} |
169 |
else |
170 |
else |
Line 171... |
Line 172... |
171 |
RX_buffer <<= 1; // If the bit is LOW save 0 in RX_buffer |
172 |
RX_buffer <<= 1; // If the bit is LOW save 0 in RX_buffer |
172 |
RX_buffer &=0b11111110; |
173 |
RX_buffer &=0b11111110; |
173 |
} |
174 |
} |
174 |
} |
175 |
} |
175 |
|
176 |
|
176 |
SMB_send_bit(ack_nack); // Sends acknowledgment bit |
177 |
SMB_send_bit(ack_nack); // Sends acknowledgment bit |
177 |
|
178 |
|
178 |
return RX_buffer; |
179 |
return RX_buffer; |
179 |
} |
180 |
} |
180 |
|
181 |
|
181 |
|
182 |
|
Line 194... |
Line 195... |
194 |
crc[4]=0; |
195 |
crc[4]=0; |
195 |
crc[3]=0; |
196 |
crc[3]=0; |
196 |
crc[2]=0; |
197 |
crc[2]=0; |
197 |
crc[1]=0x01; |
198 |
crc[1]=0x01; |
198 |
crc[0]=0x07; |
199 |
crc[0]=0x07; |
199 |
BitPosition=47; /* Set maximum bit position at 47 */ |
200 |
BitPosition=47; /* Set maximum bit position at 47 */ |
200 |
shift=0; |
201 |
shift=0; |
201 |
|
202 |
|
202 |
//Find first 1 in the transmited message |
203 |
//Find first 1 in the transmited message |
203 |
i=5; /* Set highest index */ |
204 |
i=5; /* Set highest index */ |
204 |
j=0; |
205 |
j=0; |
205 |
while((pec[i]&(0x80>>j))==0 && i>0) |
206 |
while((pec[i]&(0x80>>j))==0 && i>0) |
206 |
{ |
207 |
{ |
207 |
BitPosition--; |
208 |
BitPosition--; |
208 |
if(j<7) |
209 |
if(j<7) |