Big Thank You Mister E.
You and MELABs staff helped me to find mistake. I insert in my code two lines and now program works great. These are two lines:
DEFINE I2C_HOLD 1
DEFINE I2C_SLOW 1
Maybe, someone will have the same problems in future, so I decided to post all my code. It works flawless.
Thanks again
Vladimir
'PIC16f872
'---------------- Definitions---------------------------------------------
define OSC 20
'------------- Define LCD registers and bits------------------------------
DEFINE I2C_HOLD 1
define I2C_SLOW 1
Define LCD_DREG PORTB 'Set LCD data port
Define LCD_DBIT 0 'Set starting data bit
Define LCD_RSREG PORTB 'Set LCD register select port
Define LCD_RSBIT 4 'Set LCD register select bit
Define LCD_EREG PORTB 'Set LCD enable port
Define LCD_EBIT 5 'Set LCD enable bit
define DEBUG_REG PORTC 'Set DEBUD port
DEFINE DEBUG_BIT 1 'Set DEBUG pin
DEFINE DEBUG_BAUD 2400 'Set DEBUG baud rate
DEFINE DEBUG_MODE 0 'Set DEBUG mode
DPIN var PORTc.4 ' I2C data pin
CPIN var PORTc.3 ' I2C clock pin
bearing var word ' word size bearing value 0 - 359
bearing1 var byte ' byte size bearing value 0 - 255
I will try to give you answers.
1) what is the purpose and function of this line :
DEBUG " Compass Bearing ", # bearing,13,10
This is optional line, for development purposes only. It is sends “bearing” value serially to a terminal. In my program this command sends serial string to PORT_C, pin No1, baud rate 2400.
2) Why is the address be written as %11000000?
This is address designated by Devantech (Devantech is company producing the compass module)
3) WHat is the function of this line:
i2cread dpin,cpin,%11000000,2,[bearing.Highbyte,bearing.lowbyte]
Function of this line is reading "bearing" value through I2C bus, as WORD size variable.
4) and what this DEC sign means, i have checked the help section, it is no command. Then why it is written there :
1) Which type of LCD screen have u used. Can i use an LCD screen with three terminals (+5V, GND, control) using Serout command? What lcd u have used?
2) On each PIC, it is usually written that which is the SDA pin and which is the SLA one. While when i was reading the diagram of PIC16F84A , it was not mentioned. According to you , i can use this I2C on PIC16F84A, is it possible that we can use any two pins for I2C operation? or are there always two fixed pins dedicated for it?
Bookmarks