Exact match. Not showing close matches.
'[PIC]: I2C master mode routines for 16F877'
|Hello Achim & PIC.ers,
I've had to bash my own way thru this recently meself...
I cribbed, borrowed and stole whatever I could,
then went back to the 16f87x manual and wound up with
a set of master transmit <> receive routines that are
*working* - perfectly well as far as I can tell.
This app. has two Philips PCF8574 I2C general purpose
byte-wide IO port chips.
One (IO1) is dedicated to inputs only, for switch states, etc.,
while IO2 is output only, to drive a collection of panel
I have used private macros like :-
bank0 ;use ram bank0
bank1 ;use ram bank1
movlf ;load literal to freg
movff ;load freg1 to freg2
etc., these should need no introduction, but if they do, let me know..
Setup the ports by :-
Invoke a IO1 port read by:-
read_switches ;byte-wide result in freg`latest_switch_state'
Invoke a IO2 port write by:-
;put desired byte into freg
;****************** I2C macros begin
start_i2c MACRO ;[S]
bank0 ;bank0 (bank0? names) be sure
bsf SSPCON2,SEN ;send i2c START [S] bit
btfsS PIR1,SSPIF ;start bit cycle complete?
bsf SSPCON2,RCEN ;enable receiving at master 16f877
btfsS PIR1,SSPIF ;sspbuf buffer full byte?
stop_i2c MACRO ;[P]
bsf SSPCON2,PEN ;send i2c STOP [P] bit
btfsS PIR1,SSPIF ;stop bit cycle completed?
btfsS PIR1,SSPIF ;ACK received?
setup_i2c MACRO ;setup mssp for i2c
movlf 00101000b,SSPCON ;=0x028
read_switches MACRO ;io1 is inputs only
movlf 01000011b,SSPBUF ;send out io1 pcf8574 addr
write_leds MACRO ;io2 is output only
movlf 01000100b,SSPBUF ;sned out io2
;***************** I2C macros end
Hope this all makes sense,
best regards, John
e-mail from the desk of John Sanderson, JS Controls.
Snailmail: PO Box 1887, Boksburg 1460, Rep. of South Africa.
Tel/fax: Johannesburg 893 4154
Cellphone no: 082 469 0446
Manufacturer & purveyor of laboratory force testing apparatus, and related
products and services.
More... (looser matching)
- Last day of these posts
- In 2000
, 2001 only
- New search...