Escolar Documentos
Profissional Documentos
Cultura Documentos
I2C-bus
PNP
NPN
Modes of Operation
NOR gate
NAND gate
Sinking Input
Sourcing Input
Sinking Output
Sourcing Output
TTL Logic
Open Collector Output
A Basic Output
TTL logic
Sinking
Sourcing
11
Tristate Gate
khi ENABLE=0 thi gate ko lam
viec
khi ENABLE=1, phu thuoc vao
input:
voi input= 0: thi Q3,Q4 dan.
voi input=1: Q2 dan
Types of FETs
FET
JFET
n-Channel JFET
p-Channel JFET
MOSFET (IGFET)
Enhancement
MOSFET
n-Channel
EMOSFET
p-Channel
EMOSFET
Depletion
MOSFET
n-Channel
DMOSFET
p-Channel
DMOSFET
0V
VDD
CMOS Inverter
Sinking / Sourcing ???
CMOS Inverter
AND gate
OPEN-DRAIN (OPEN-COLLECTOR)
OUTPUTS
n
khi n ko dan thi lay +V ra Vout
khi n dan thi +V ve dat
TRISTATE OUTPUTS
MOSFET
p
p
n
n
TTL Gate Sinking the Input Current from Two Gate Inputs
Xem chng 1
Interface Solutions
I2C-bus
ve 0
The addresses of most I2C devices are fixed and documented in the respective datasheet. Some I2C devices allow a few bits
out of the 7 or 10 address bits to be configured by hardware values on pins labeled A0, A1, and A2 for example.
thang nhan(slave) co kha nang lam cham toc do truyen cua slave/master
cua master
RC Time Constant
RC
(1
1
) *100% 39.3%
e0.5
I2C PC-interface
http://www.pvv.org/~asgaut/i2c/i2c.html
+5V must be supplied from an external power supply to the VDD line
i2c
pc
12.5V
xung clock vo day
=1 thi dan
24AA256/24LC256/24FC256
I2C functions
I2C SERIAL PORT
I2C START
i2c_start();
I2C WRITE
I2C READ
inbyte = i2c_read();
I2C STOP
i2c_stop();
I2C POLL
i2c_write(outbyte);
sbit = i2c_poll();
#include "16F877A.h"
#use delay(clock=4000000)
#use i2c(MASTER,SCL=PIN_C3,SDA=PIN_C4)
/*
void main()
//Ghi 1 byte
{
int sendbyte, lowadd;
lowadd=0;
port_b_pullups(1);
sendbyte=(input_B());
i2c_start();
// start write cycle
i2c_write(0xA0);
// send control byte
i2c_write(0x00);
// send high address
i2c_write(lowadd); // send low address
i2c_write(sendbyte); // send data
i2c_stop();
delay_ms(5);
// wait for write
while(1)
{
}
}
#include "16F877A.h"
#use delay(clock=4000000)
#use i2c(MASTER,SCL=PIN_C3,SDA=PIN_C4)
void main()
//Ghi 5 bytes
{
int sendbyte, lowadd;
port_b_pullups(1);
sendbyte=(input_B());
for (lowadd=0; lowadd<5; lowadd++ )
{
i2c_start();
// start write cycle
i2c_write(0xA0);
// send control byte
i2c_write(0x00);
// send high address
i2c_write(lowadd); // send low address
i2c_write(sendbyte); // send data
i2c_stop();
delay_ms(5);
// wait for write
}
while(1)
{
}
}
#include "16F877A.h"
#use delay(clock=4000000)
#use i2c(MASTER,SCL=PIN_C3,SDA=PIN_C4)
void main()//Ghi ra 256bytes
{
int sendbyte, lowadd;
lowadd=0;
port_b_pullups(1);
sendbyte=(input_B());
while(1)
{
i2c_start();
// start write cycle
i2c_write(0xA0);
// send control byte
i2c_write(0x00);
// send high address
i2c_write(lowadd); // send low address
i2c_write(sendbyte); // send data
i2c_stop();
delay_ms(5);
lowadd++;
}
}
EEPROM SPEC:
1.Microchip 24LC16B (16K Bits or 2KBytes)
2.8 Internal blocks (256 Bytes for each block)
I2C ADDRESS SPEC:
1. I2C Spec code for EEPROM SELECTION: 1010 must be the highest 4 Bits in the Higher Address
2. 3-bit Block Code (from 000 to 111) follows the EEPROM SELECTION bits
3. R/W bit follows to Complete the 8-bit Higher Address
4. Actual EEPROM address is selected by the 8-bit Lower Address
;subroutine I2CSTART
I2Cstart
banksel SSPCON2
bsf SSPCON2, SEN ;START
banksel PIR1
Swait
btfss PIR1, SSPIF
goto Swait
bcf PIR1, SSPIF
Return
;subroutine i2cblock for write
i2cSend
banksel SSPBUF
movwf SSPBUF
banksel PIR1
cwait
btfss PIR1, SSPIF
goto cwait
bcf PIR1, SSPIF
Return
;SUBROUTINE I2CSTOP
i2cStop
banksel SSPCON2
bsf SSPCON2, PEN
banksel PIR1
Pwait
btfss PIR1, SSPIF
goto Pwait
bcf PIR1, SSPIF
return
ACK???
Delay100us
banksel Kount100us
movlw HA5'
movwf Kount100us
R100us
decfsz Kount100us
goto R100us
return
CBLOCK 0x20
Kount100us
Kount10ms
ENDC
;10ms delay
; call 100 times of 100 us delay (with some time
discrepancy)
Delay10ms
banksel Kount10ms
movlw H'64' ;100
movwf Kount10ms
R10ms
call delay100us
decfsz Kount10ms
goto R10ms
return
;
END