Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
Soft_I2C_Break
355
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6
Prototype
procedure Soft_I2C_Break();
Returns
Nothing.
Description
All Software I
2
C Library functions can block the program flow (see note at the
top of this page). Call this routine from interrupt to unblock the program execu-
tion. This mechanism is similar to WDT.
Note: Interrupts should be disabled before using Software I
2
C routins again
(see note at the top of this page).
Requires
Nothing. 
Example
// Soft_I2C pinout definition
var Soft_I2C_Scl_Output        : sbit at PORTC.B0;     
var Soft_I2C_Sda_Output        : sbit at PORTC.B1;      
var Soft_I2C_Scl_Input         : sbit at PINC.B0;        
var Soft_I2C_Sda_Input         : sbit at PINC.B1;        
var Soft_I2C_Scl_Pin_Direction : sbit at DDRC.B0;
var Soft_I2C_Sda_Pin_Direction : sbit at DDRC.B1;
// End of Soft_I2C pinout definition
var counter : byte;
procedure Timer0Overflow_ISR(); org 0x12;
begin
counter := 0;
if (counter >= 20)
begin
Soft_I2C_Break();
counter := 0;                // reset counter
end
else
Inc(counter);                  // increment counter
end;
begin 
TOIE0_bit  := 1;           // Timer0 overflow interrupt enable
TCCR0_bit  := 5;           // Start timer with 1024 prescaler
SREG_I_bit := 0;                   // Interrupt disable
...
// try Soft_I2C_Init with blocking prevention mechanism
SREG_I_bit := 1;                   // Interrupt enable
Soft_I2C_Init();
SREG_I_bit := 0;                   // Interrupt disable
...
end.