ME Labs, Inc.
719-520-5323
 
Home:
  Developer Resources:

Programming Clues
    Sample Programs
   
    PICBASIC PRO™
Compiler Manual
    PICBASIC™ Compiler
Manual
    Serin2/Serout2 Modes
    ASCII Character Set
    Number Conversion
    Floating Point
Routines
    PBP Debug Monitor
    Articles and Tutorials

Hardware Clues
    Parts / Vendor List
    PICPROTO™ Boards
    LAB-X1 Docs
    LAB-X2 Docs
    LAB-X20 Docs
    LAB-X3 Docs
    LAB-X4 Docs
    LAB-XUSB Docs
    LAB-XT Docs
     
 

microEngineering Labs, Inc. | 1-719-520-5323 | Example Program - I2CEE12.pbp

PICBASIC PRO program to demonstate the I2CREAD and I2WRITE commands with internal EEPROM on 12-bit core. Writes to the first 16 locations of internal I2C EEPROM, then reads first 16 locations back and send to serial out repeatedly Tested on 12CE519. Outputs: A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P.
' Name        : I2CEE12.pbp
' Compiler    : PICBASIC PRO Compiler 2.6
' Assembler   : PM or MPASM
' Target PIC  : PIC12CE519 12-bit core with internal I2C EEPROM
' Hardware    : Non specific
' Oscillator  : 4MHz internal
' Keywords    : DEBUG, EEPROM, I2CREAD, I2CWRITE
' Description : PICBASIC PRO program to demonstate the I2CREAD and I2WRITE commands
' with internal EEPROM on 12-bit core. Writes to the first 16 locations of internal
' I2C EEPROM, then reads first 16 locations back and send to serial out repeatedly
' Tested on 12CE519. Outputs: A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P.
'

' Define debug and I2C pins
Define DEBUG_REG    GPIO
Define DEBUG_BIT    1
Define DEBUGIN_BIT  2
Define DEBUG_BAUD   9600
Define DEBUG_MODE   0
Define I2C_INTERNAL 1
Define I2C_SCL GPIO,7
Define I2C_SDA GPIO,6

' Declare variables
B1 VAR BYTE
B2 VAR BYTE
B3 VAR BYTE

' calibrate the internal oscillator
OSCCAL = $c4

mainloop:
   For B3 = 0 to 15	' Loop 16 times for data write
     B1 = B3 + 65	' Add 65 to loop counter to create ASCII alphabet
     I2CWrite GPIO.6,GPIO.7,$A0,B3,[B1]  ' Write data to EEPROM
     Pause 10           ' Delay 10ms after each write
   Next B3	
	
   For B3 = 0 to 15 step 2   ' loop again but step 2 to read 2 locations each loop
     I2CRead GPIO.6,GPIO.7,$A0,B3,[B1,B2]  ' Read 2 locations
     Debug B1,", ",B2,", "   ' Print 2 locations
   Next B3	

   Debug 10,13          ' Print linefeed
   GoTo mainloop

   End

           

Download the program file.