Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Nice I2C asembler routine for PIC16F84A needed

Status
Not open for further replies.

traxonja

Advanced Member level 4
Joined
Apr 6, 2004
Messages
109
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
1,184
i2c pic16f84

Hello,

does anybody have a nice (clean) routine for writing and reading-from an I2C memory device written for MPASM?
I will use PIC16F84A, and 24LC16 (2k) device so 1-byte address will be used, but 2-byte addresses are OK too.

I have this attached routine but it doesn't work :( , so if you have a nice tested one please post it here.

When I programm the device in PicBasic, it works, but with this routine in MPASM it doesn't work :(

All best,
Trax
 

zmanultra

Member level 2
Joined
Mar 20, 2004
Messages
48
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Location
Australia
Activity points
524
pic16f84a i2c

Hi

is what the device that u have a smartcard (gold wafer) caus that cojntains the 2 ICs u talking about.
 

traxonja

Advanced Member level 4
Joined
Apr 6, 2004
Messages
109
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
1,184
i2c pic16f84a

No, it's only my PIC and some eeprom, in my case it is 24c16.

Trax
 

Kripton2035

Advanced Member level 4
Joined
Jul 19, 2001
Messages
1,164
Helped
209
Reputation
422
Reaction score
182
Trophy points
1,353
Location
Western Europe
Activity points
7,870
i2c assembler

be aware that if you look at the details of the picbasic language, the i2c routines works well only with hard i2c chips for example 16f876, but not the 16f84...
they work quite in master mode, but quite not in slave.
 

sam_manchali

Member level 4
Joined
Jun 14, 2003
Messages
69
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,288
Location
sharjah
Activity points
735
16f i2c

hi,
check out the routines provided by microchip itself, they work fine to my knowleded!!
cheers
sam
 

traxonja

Advanced Member level 4
Joined
Apr 6, 2004
Messages
109
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
1,184
pic16f84a+24c01

Thanks for the answers. I found a nice routine at www.piclist.com.

And, I couldn't download a file from this forum because I am stil a new user and I don't have any points :( :)

Best regards,
Trax
 

elektryk

Advanced Member level 4
Joined
Apr 25, 2002
Messages
112
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
POLAND
Activity points
960
pic16f84 i2c

traxonja said:
And, I couldn't download a file from this forum because I am stil a new user and I don't have any points :( :)
You have now ;)
 

mbyka

Full Member level 5
Joined
May 12, 2002
Messages
296
Helped
12
Reputation
24
Reaction score
10
Trophy points
1,298
Location
from istanbul in TURKEY
Activity points
2,058
pic16f84 magnetic card reader

Hi
I can help you with my sample code
maybe :)


Code:
LIST P=16F84
	INCLUDE "P16F84.inc"
	TITLE " 24Cxx Programming with pic"
	
		

EEPROM	EQU 1CH
ADDR		EQU 1DH
DATAI		EQU 1EH
DATAO		EQU 1FH
TXBUF		EQU 20H
RXBUF		EQU 21H
COUNT		EQU 22H
DEL		EQU 23H
SEL 		EQU 24H

DI		EQU 7 
DO		EQU 6
SDA		EQU 1
SCL		EQU 0
;PortA.0--------->Serial Clock----------24Cxx's Pin:6
;PortA.1<-------->Serial Data-----------24Cxx's Pin:5
;PortB LED outs


	__CONFIG _WDT_OFF & _XT_OSC & _CP_OFF


;====================================================
;========= start======================

	ORG 000H
	GOTO START

START
	CALL PORT_INIT
MAIN
	MOVLW 00H			;Eeprom write Adress
	MOVWF ADDR
	MOVLW 23H			;Eeprom  data
	MOVWF DATAO
	CALL WRITE_EEPROM
	MOVLW .100
	CALL DELAY_NMS
	MOVLW 00H			;Eeprom read adress
	MOVWF ADDR
	CALL READ_EEPROM
	MOVF DATAI,W
	MOVWF PORTB			;read from Eeprom transfer data portb 
	MOVLW .100
	CALL DELAY_NMS
DONE
	GOTO DONE



;========================================================
;================= Port Init ============================

PORT_INIT
	CLRF PORTA
	CLRF PORTB
;
	BSF STATUS, RP0		;page1 select
	CLRF TRISA
	CLRF TRISB
	BCF STATUS, RP0		;page0 select
;
	CLRF PORTB
	RETURN


;=============================================================
;======== eeprom cominication=========================

WRITE_EEPROM
	CALL BSTART
;
	MOVLW B'10100000'
	MOVWF TXBUF
	CALL TX
;
	MOVF ADDR,W
	MOVWF TXBUF
	CALL TX
;
	MOVF DATAO,W
	MOVWF TXBUF
	CALL TX
;
	CALL BSTOP
;
	RETURN


READ_EEPROM
	CALL BSTART
;
	MOVLW B'10100000'
	MOVWF TXBUF
	CALL TX
;
	MOVF ADDR,W
	MOVWF TXBUF
	CALL TX
;
	CALL BSTART
;
	MOVLW B'10100001'
	MOVWF TXBUF
	CALL TX
;
	CALL RX
;
	CALL BSTOP
;
	RETURN

BSTART
	BSF PORTA,SDA
	BSF STATUS, RP0		
	MOVLW 00H
	MOVWF TRISA
	BCF STATUS, RP0	
;
	BCF PORTA,SCL
	NOP
	BSF PORTA,SCL
	NOP
	NOP
	NOP
	NOP
	NOP
	BCF PORTA,SDA
	NOP
	NOP
	NOP
	NOP
	NOP
	BCF PORTA,SCL
	NOP	
	NOP
	RETURN
		
BSTOP
	BSF STATUS, RP0		
	MOVLW 00H
	MOVWF TRISA
	BCF STATUS, RP0	
;
	BCF PORTA,SDA
	NOP
	NOP
	NOP
	BSF PORTA,SCL
	NOP
	NOP
	NOP
	BSF PORTA,SDA
	NOP
	NOP
	BCF PORTA,SCL
	NOP
	NOP
	NOP
	RETURN


BITOUT
	BSF STATUS, RP0		
	MOVLW 00H
	MOVWF TRISA
	BCF STATUS, RP0	
;
	BTFSS EEPROM,DO
	GOTO BITLOW
	BSF PORTA,SDA
	GOTO CLK_OUT
BITLOW
	BCF PORTA,SDA
CLK_OUT
	BSF PORTA,SCL
	NOP
	NOP
	NOP
	NOP
	BCF PORTA,SCL
	NOP
	RETURN

BITIN
	BSF EEPROM,DI
;
	BSF STATUS,RP0
	MOVLW 02H
	MOVWF TRISA
	BCF STATUS, RP0	
;
	BSF PORTA,SCL
	NOP
	NOP
	NOP
	NOP
	NOP
	BTFSS PORTA,SDA
	BCF EEPROM,DI
	BCF PORTA,SCL
	RETURN

TX
	MOVLW .8
	MOVWF COUNT
TXLP
	BCF EEPROM,DO
	BTFSC TXBUF,7
	BSF EEPROM,DO
	CALL BITOUT
	RLF TXBUF,F
	DECFSZ COUNT,F
	GOTO TXLP
	CALL BITIN
	RETURN

RX
	CLRF DATAI
	MOVLW .8
	MOVWF COUNT
	BCF STATUS,0
RXLP
	RLF DATAI,F
	CALL BITIN
	BTFSC EEPROM,DI
	BSF DATAI,0
	DECFSZ COUNT,F
	GOTO RXLP
	BSF EEPROM,DO
	CALL BITOUT
	RETURN


DELAY_NMS
	MOVWF DEL
OUTTER_MS
	MOVLW .110
	MOVWF SEL
INNER_MS
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	DECFSZ SEL,F
	GOTO INNER_MS
	DECFSZ DEL,F
	GOTO OUTTER_MS
	RETURN


END
 

elcielo

Full Member level 6
Joined
Jun 13, 2002
Messages
383
Helped
15
Reputation
30
Reaction score
8
Trophy points
1,298
Activity points
3,250

hassan1980

Full Member level 4
Joined
Jan 14, 2005
Messages
204
Helped
9
Reputation
18
Reaction score
6
Trophy points
1,298
Activity points
1,348
tsa5055 pic

I want a clear program for just reading and writing in serial eeprom like 24C64 with 16f84.

I need your help
 

dragosdiaconita

Newbie level 1
Joined
Mar 22, 2007
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,284
pic16f84 i2c slave basic

does anyone have an exe file to comunicate with the 16f84 serial out?
pls?
ty for ure kindnes
 

tonybg

Junior Member level 3
Joined
Mar 17, 2007
Messages
25
Helped
4
Reputation
8
Reaction score
3
Trophy points
1,283
Location
bulgaria
Activity points
1,423
pic16f84 read 24c01 eeprom

Why don't you try Application Maestro.It's a part of MPLAB.Generates many protocols,and explains all the details about hardware and software on the specfic code it generates.Hope it helped:D
 

iman_andeh

Newbie level 6
Joined
Feb 19, 2007
Messages
14
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,283
Activity points
1,377
i2c pic16f

how to communicate (read and write) the gold wafer card using other PIC mcu such as PIC16F877A?

i'm trying to build a portable gold wafer card reader/writer...
 

zmanultra

Member level 2
Joined
Mar 20, 2004
Messages
48
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Location
Australia
Activity points
524
i2c with pic16f84a

its like programming a normal pic processor....the only difference is that u must creat a serial Comm routine...check out picbasic pro...it has some serial routines...thats the easiest way....or u can use microchip compiler....
hope this helps
:)
 

iman_andeh

Newbie level 6
Joined
Feb 19, 2007
Messages
14
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,283
Activity points
1,377
16f84+i2c

is there any sample code that used to write gold wafer card?
 

zmanultra

Member level 2
Joined
Mar 20, 2004
Messages
48
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Location
Australia
Activity points
524
master i2c for pic16f690

dont worry about "gold wafer card" look at it as simply programming a chip....(pic16) have u programed that chip b4....if not, just have a look at the sample code provided (e.g. pic basic is good for beginers)
 

iman_andeh

Newbie level 6
Joined
Feb 19, 2007
Messages
14
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,283
Activity points
1,377
pic16f84a mit i²c

yes, i have programmed PIC before, that is PIC16F877a..

about gold wafer card,
i'm really confused what i should do now.
i tend to use circuit below as my gold wafer card reader and programmer

67_1184026843_thumb.jpg


this circuit was grabbed from Silicon Chip (issue 178 (July 15, 2003), by Peter Smith)

but,
i really have no idea about the code. could you give an example code?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top