|
From: Gernot F. <g....@gm...> - 2005-06-22 16:15:48
|
On Wed, 22 Jun 2005, Jean-Paul wrote:
> >
> > Or a bit expansive use a PCF8574 IIC-Portexpander. This use 2 pins.
> > You get 8 bidirektional portpins. One or 2 of them are free after =20
> > connecting the
> > Display.
> >
>=20
> You get for the same price an interrupt capability on all eight pins!
> Use that only if you really need in/out pins. The I2C overhead could be=
=20
> too big for the 2 or 4K flash (89C4051).
You can have basic iic in 129 Bytes
extern bit writeok;
void iic_delay(void)
{
=09_asm nop _endasm;
=09_asm nop _endasm;
=09_asm nop _endasm;
=09_asm nop _endasm;
}
void iic_start(void)
{
=09_asm setb scl _endasm;
=09iic_delay();
=09_asm clr sda _endasm;
iic_delay();
}
void iic_stop(void)
{
=09_asm clr sda _endasm;
iic_delay();
=09_asm setb scl _endasm;
iic_delay();
=09_asm setb sda _endasm;
iic_delay();
}
void iic_putc(unsigned char c)
{
=09c=3Dc;
=09_asm=20
=09mov a,dpl
=09mov dpl,#8
=09$00021:
=09=09clr scl
=09=09lcall _iic_delay
=09=09rlc a
=09=09mov sda,c
=09lcall _iic_delay
=09=09setb scl
=09lcall _iic_delay
=09djnz dpl,$00021
=09clr scl
lcall _iic_delay
=09setb sda
lcall _iic_delay
=09mov c,sda
=09cpl c
=09mov _writeok,c
=09setb scl
lcall _iic_delay
=09clr scl
lcall _iic_delay
=09_endasm;
}
unsigned char iic_getc(bit last)
{
=09last&=3D255;
=09_asm=09
=09push dpl
=09mov dpl,#8
=09$00022:=09
=09=09mov c,sda
=09=09rlc a=09
=09=09setb scl
=09 =09 lcall _iic_delay
=09=09clr scl
=09lcall _iic_delay
=09djnz dpl,$00022
=09mov b,a
=09pop acc
=09mov c,acc.0
=09mov sda,c
=09lcall _iic_delay
=09setb scl
=09lcall _iic_delay
=09clr scl
=09lcall _iic_delay
=09setb sda
=09lcall _iic_delay
=09_endasm;
=09return B;
}
--=20
MFG Gernot
|