<root>
<document schema='101' license='1,bernoulli,Z5R7KK' title='' description='' target='PIC16.24F.24FJ64GB002' >
	<config data='!0,ffdf!10,fcff!20,ab9e!30,2f3f%0,f%4,1%5,0%6,1%7,1%8,ff%10,3f%16,3%18,0%1a,3%1c,1%1d,1%1e,1%1f,1%20,2%22,1%23,1%24,1%25,0%26,2%28,3%2b,1%2c,2%2f,1%30,f%34,1%35,1%36,0%37,0%38,3%3a,1%3b,1%3c,0%3d,1%3e,0%3f,0' clkspd='8000000' simspd='1' usewdt='0' constif='0' />
	<plugins >
		<dll_dbg_icd enabled='0' >
			<data name='debug' value='1' />
			<data name='userpins' value='0' />
			<data name='speed' value='0' />
			<data name='usev9' value='0' />
			<data name='breaks' value='8' />
			<data name='stacks' value='8' />
			<data name='clkport' value='1' />
			<data name='clkbit' value='6' />
			<data name='dataport' value='1' />
			<data name='databit' value='7' />
			<data name='ghostype' value='0' />
			<data name='monitor' value='1' />
			<data name='ictloop' value='0' />
			<data name='ictrate' value='20000' />
			<data name='ictmask' value='0' />
			<data name='anlpres' value='255' />
			<data name='digmask1' value='-1' />
			<data name='digmask2' value='-1' />
		</dll_dbg_icd>
		<dll_models enabled='1' />
		<dll_upgrader enabled='1' />
		<dll_webhelp enabled='1' />
	</plugins>
	<supplement use='0' head='#ifndef LCDI2C4Bit_h
#define LCDI2C4Bit_h

// #include &lt;inttypes.h&gt;

// IMPORTANT! Wire. must have a begin() before calling init()

class LCDI2C4Bit {
public:
  LCDI2C4Bit(int devI2CAddress, int num_lines, int lcdwidth);
  void commandWrite(int command);
  void init();
  void print(int value);
  void printIn(char value[]);
  void clear();
  void backLight( bool turnOn );

  //non-core---------------
  void cursorTo(int line_num, int x);
  //void leftScroll(int chars, int delay_time);
  //end of non-core--------

  //4bit only, therefore ideally private but may be needed by user
  //void commandWriteNibble(int nibble);

private:
  //void pulseEnablePin();
  //void pushNibble(int nibble);
  //void pushByte(int value);

  int myNumLines;
  int myWidth;
  int myAddress;
};
#endif


' body='#include &quot;LCDI2C4Bit.h&quot;
#include &lt;Wire.h&gt;

extern &quot;C&quot; {
  #include &lt;stdio.h&gt;  //not needed yet
  #include &lt;string.h&gt; //needed for strlen()
  #include &lt;inttypes.h&gt;
  #include &quot;WConstants.h&quot;  //all things wiring / arduino
}

//command bytes for LCD
#define CMD_CLR 0x01
#define CMD_RIGHT 0x1C
#define CMD_LEFT 0x18
#define CMD_HOME 0x02

//stuff the library user might call---------------------------------

//constructor.  num_lines must be 1 or 2, currently.

byte dataPlusMask = 0; // TODO!!!

LCDI2C4Bit::LCDI2C4Bit( int devI2CAddress, int num_lines, int lcdwidth) {
  myNumLines = num_lines;
  myWidth = lcdwidth;
  myAddress = devI2CAddress;
}

void SetMCPReg( byte deviceAddr, byte reg, byte val ) {
  Wire.beginTransmission(deviceAddr);
  Wire.send(reg);
  Wire.send(val);
  Wire.endTransmission();
}

void SendToLCD( byte deviceAddr, byte data ) {
  data |= dataPlusMask;
  SetMCPReg(deviceAddr,0x0A,data);
  data ^= 0x80; // E
  delayMicroseconds(1);
  SetMCPReg(deviceAddr,0x0A,data);
  data ^= 0x80; // E
  delayMicroseconds(1);
  SetMCPReg(deviceAddr,0x0A,data);
  delay(1);

}

void WriteLCDByte( byte deviceAddr, byte bdata ) {
  SendToLCD(deviceAddr,bdata &gt;&gt; 4);
  SendToLCD(deviceAddr,bdata &amp; 0x0F);
}

void LCDI2C4Bit::init( void ) {
  dataPlusMask = 0; // initial: 0
  SetMCPReg(myAddress,0x05,0x0C); // set CONFREG (0x05) to 0
  SetMCPReg(myAddress,0x00,0x00); // set IOREG (0x00) to 0
  //
  delay(50);
  SendToLCD(myAddress,0x03); 
  delay(5);
  SendToLCD(myAddress,0x03);
  delayMicroseconds(100);
  SendToLCD(myAddress,0x03);
  delay(5);
  SendToLCD(myAddress,0x02);
  WriteLCDByte(myAddress,0x28);
  WriteLCDByte(myAddress,0x08);
  WriteLCDByte(myAddress,0x0C); // turn on, cursor off, no blinking
  delayMicroseconds(60);
  WriteLCDByte(myAddress,0x01); // clear display
  delay(3);  
}

void LCDI2C4Bit::backLight( bool turnOn ) {
  dataPlusMask |= 0x40; // Lights mask
  if (!turnOn) dataPlusMask ^= 0x40;
  SetMCPReg(myAddress,0x0A,dataPlusMask);  
}




void LCDI2C4Bit::print( int value ) {
  dataPlusMask |= 0x10; // RS
  WriteLCDByte(myAddress,(byte)value);
  dataPlusMask ^= 0x10; // RS
}

void LCDI2C4Bit::printIn( char value[] ) {
  for ( char *p = value; *p != 0; p++ ) 
    print(*p);
}

void LCDI2C4Bit::clear() {
  commandWrite(CMD_CLR);
}

void LCDI2C4Bit::cursorTo(int line_num, int x) {
  commandWrite(CMD_HOME);
  int targetPos = x + line_num * myWidth;
  for ( int i = 0; i &lt; targetPos; i++)
    commandWrite(0x14);
}

void LCDI2C4Bit::commandWrite( int command ) {
  // RS - leave low
  WriteLCDByte(myAddress,command);
  delay(1);
}


' />
	<debug />
	<ghost >
		<FK2 >
			<data name='FK2D0' port='4294967295' pin='4294967295' />
			<data name='FK2D1' port='4294967295' pin='4294967295' />
			<data name='FK2D2' port='4294967295' pin='4294967295' />
			<data name='FK2D3' port='4294967295' pin='4294967295' />
			<data name='FK2D4' port='4294967295' pin='4294967295' />
			<data name='FK2D5' port='4294967295' pin='4294967295' />
			<data name='FK2D6' port='4294967295' pin='4294967295' />
			<data name='FK2D7' port='4294967295' pin='4294967295' />
			<data name='FK2D8' port='4294967295' pin='4294967295' />
			<data name='FK2D9' port='4294967295' pin='4294967295' />
			<data name='FK2D10' port='4294967295' pin='4294967295' />
			<data name='FK2D11' port='4294967295' pin='4294967295' />
			<data name='FK2D12' port='4294967295' pin='4294967295' />
			<data name='FK2D13' port='4294967295' pin='4294967295' />
			<data name='FK2D14' port='4294967295' pin='4294967295' />
			<data name='FK2D15' port='4294967295' pin='4294967295' />
			<data name='FK2A0' port='4294967295' pin='4294967295' />
			<data name='FK2A1' port='4294967295' pin='4294967295' />
			<data name='FK2A2' port='4294967295' pin='4294967295' />
			<data name='FK2A3' port='4294967295' pin='4294967295' />
			<data name='FK2A4' port='4294967295' pin='4294967295' />
			<data name='FK2A5' port='4294967295' pin='4294967295' />
		</FK2>
		<ICD >
			<data name='AnalogPrescaleValue' value='19' />
			<data name='DigitalSampleRate' value='100000' />
			<data name='BreakpointCount' value='8' />
			<data name='CallStackDepthCount' value='8' />
			<data name='ClockPort' value='1' />
			<data name='ClockPin' value='1' />
			<data name='DataPort' value='1' />
			<data name='DataPin' value='0' />
			<data name='UseDefaultPins' value='1' />
			<data name='WrapEnabled' value='1' />
			<data name='CommsDelayOverridden' value='0' />
			<data name='CommsDelay' value='21' />
			<data name='CalculatedCommsDelay' value='21' />
		</ICD>
		<pins >
			<digital A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
			<analog A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
		</pins>
	</ghost>
	<components >
		<settings autoimg='1' center='1' unitscale='0' fixedscale='0' fixedx='1' fixedy='1' fixedz='1' headcode='0' />
		<definition guid='9dfc22ef-9ab9-41ce-9396-069d37453b5d' vstate='40' vmin='0' vmaj='1' srcleaf='' visiblename='' description='' category='' catenable='1' author='' manuname='' manucode='' sysinfo='0' keywords='' dynamic='0' iconpath='' />
		<component class_type='root' codename='panel' x='0' y='0' z='0' xsz='1' ysz='1' zsz='1' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' interactive='1' solid='1' layer='0' poslock='0' >
			<resources />
			<properties />
			<values />
			<events />
			<apis />
			<variables />
			<macros >
				<macro >
					<flowline name='OSCILLATOR_INITIALIZE' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='native' title='C Code' ccode='{
    // CF=no clock failure; NOSC=PriPLL; SOSCEN=disabled; POSCEN=disabled; CLKLOCK=unlocked; OSWEN=Switch is Complete; IOLOCK=not-active; 
    OSCCONL = 0x0300;
    //
    // CPDIV=1:4; PLLEN=enabled; RCDIV=FRC/1; DOZE=1:1; DOZEN=disabled; ROI=disabled; 
    CLKDIV = 0x00A0;
    //
    // TUN=Center frequency; 
    OSCTUN = 0x0000;
    //
    // ROEN=disabled; ROSEL=disabled; RODIV=Base clock value; ROSSLP=disabled; 
    REFOCON = 0x0000;
    //
    // WDTO=disabled; TRAPR=disabled; SLEEP=disabled; BOR=disabled; DPSLP=disabled; CM=disabled; SWR=disabled; SWDTEN=disabled; EXTR=disabled; POR=disabled; IDLE=disabled; IOPUWR=disabled; VREGS=disabled; 
    RCON = 0x0000;
}' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
					</flowline>
				</macro>
				<macro >
					<flowline name='INT1_CALLED' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='native' title='Clear Interrupt Flag for this routine' ccode='/*
  Enter C code below this comment
*/
{
IFS1bits.INT1IF = 0;  // Clear INT1 Interrupt Flag
}' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
						<command class_type='interrupt' title='Interrupt' cmdcolor='3610239' cmdcolor_sec='3610239' enable='0' name='INT1' >
							<settings timer='0' prescale='-1' postscale='-1' rollover='-1' bitcount='-1' trigger='1' maskhi='--------------------------------------------------------------------------------------------------------------------------------------------------------------------------8' masklo='--------------------------------------------------------------------------------------------------------------------------------------------------------------------------8' >
								<option value='0' />
								<option value='0' />
								<option value='0' />
								<option value='0' />
							</settings>
						</command>
						<command class_type='output' title='Output' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='32' exp='0' />
						<command class_type='delay' title='Delay to get past the repetitive signals' cmdcolor='7895044' cmdcolor_sec='7895044' exp='200' type='1' />
						<command class_type='native' title='Clear Interrupt Flag for this routine' ccode='/*
  Enter C code below this comment
*/
{
IFS1bits.INT1IF = 0;  // Clear INT1 Interrupt Flag
}' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
						<command class_type='interrupt' title='Interrupt' cmdcolor='3610239' cmdcolor_sec='3610239' enable='1' name='INT1' call='INT1_CALLED' >
							<settings timer='0' prescale='-1' postscale='-1' rollover='-1' bitcount='-1' trigger='2' maskhi='--------------------------------------------------------------------------------------------------------------------------------------------------------------------------8' masklo='--------------------------------------------------------------------------------------------------------------------------------------------------------------------------8' >
								<option value='1' />
								<option value='1' />
								<option value='0' />
								<option value='-1' />
							</settings>
						</command>
						<command class_type='native' title='Clear Interrupt Flag for this routine' disable='1' ccode='/*
  Enter C code below this comment
*/
{
RPINR0 = 0x0100;  // Assign RP1 to INT1
}' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
					</flowline>
				</macro>
				<macro >
					<flowline name='Main' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='call' title='Call Macro' cmdcolor='1975743' cmdcolor_sec='1975743' macro='CPU_INITIALIZE' />
						<command class_type='interrupt' title='Interrupt' cmdcolor='3610239' cmdcolor_sec='3610239' enable='1' name='INT1' call='INT1_CALLED' >
							<settings timer='0' prescale='-1' postscale='-1' rollover='-1' bitcount='-1' trigger='2' maskhi='--------------------------------------------------------------------------------------------------------------------------------------------------------------------------8' masklo='--------------------------------------------------------------------------------------------------------------------------------------------------------------------------8' >
								<option value='1' />
								<option value='1' />
								<option value='0' />
								<option value='-1' />
							</settings>
						</command>
						<command class_type='native' title='Clear Interrupt Flag for this routine' disable='1' ccode='/*
  Enter C code below this comment
*/
{
RPINR0 = 0x0100;  // Assign RP1 to INT1
}' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
						<command class_type='output' title='Output' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='32' exp='1' />
					</flowline>
				</macro>
				<macro >
					<flowline name='CPU_INITIALIZE' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='call' title='Call Macro' cmdcolor='1975743' cmdcolor_sec='1975743' macro='OSCILLATOR_INITIALIZE' />
						<command class_type='delay' title='Delay' cmdcolor='7895044' cmdcolor_sec='7895044' exp='5' type='2' />
					</flowline>
				</macro>
			</macros>
			<component class_type='ref' guid='248e0a81-43e3-4ff7-b87d-69c04add1fb9' vmin='1' vmaj='0' codename='led_shape2' x='-2' y='0' z='1.25' xsz='1' ysz='1' zsz='1' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' interactive='1' solid='1' layer='1' poslock='0' >
				<resources />
				<properties />
				<values >
					<value target='pin' data='$PORTA.0' />
					<value target='polarity' data='001' />
					<value target='on_color' data='65280' />
					<value target='Shape' data='000' />
					<value target='width' data='10.000000' />
					<value target='height' data='10.000000' />
					<value target='depth' data='2.500000' />
					<value target='show_label' data='002' />
					<value target='label_property' data='pin' />
					<value target='label_color' data='16777215' />
					<value target='label_scale' data='5.000000' />
					<value target='label_auto_scale' data='1' />
					<value target='label_position' data='003' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
		</component>
	</components>
	<keymap />
	<panel2d shadows='0' lighting='0' brightness='256' perspective='0' >
		<background rgb='16777215' img='' style='0' />
		<camera xe='29.3654' ye='-24.6696' ze='338.883' xt='29.3654' yt='-24.6696' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
	</panel2d>
	<panel3d shadows='0' lighting='2' brightness='0' perspective='0' >
		<background rgb='8409120' img='' style='0' />
		<table rgb='7360576' img='' style='0' size='25' />
		<camera xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey0 xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey1 xe='-3.67394e-14' ye='0' ze='-300' xt='0' yt='0' zt='0' xquat='0' yquat='1' zquat='0' wquat='6.12323e-17' />
		<camerakey2 xe='0' ye='-300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.707107' yquat='0' zquat='0' wquat='0.707107' />
		<camerakey3 xe='-3.67394e-14' ye='300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-4.32978e-17' yquat='0.707107' zquat='0.707107' wquat='4.32978e-17' />
		<camerakey4 xe='-300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='0.5' zquat='0.5' wquat='0.5' />
		<camerakey5 xe='300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='-0.5' zquat='-0.5' wquat='0.5' />
		<camerakey6 xe='-173.205' ye='-173.205' ze='173.205' xt='0' yt='0' zt='0' xquat='-0.424708' yquat='0.17592' zquat='0.339851' wquat='0.820473' />
	</panel3d>
	<layout >
		<view type='0' name='Main' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAYAAAAVwQAAFUCAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='INT1_CALLED' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAYAAAAVwQAAFUCAAA' zoom='75' scrollx='0' scrolly='278' flags='0' />
		<view type='0' name='CPU_INITIALIZE' mode='0' placement='LAAAAAAAAAABAAAA----------8AAAAAFAAAAAUAAAAYAAAAVwQAAFUCAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='OSCILLATOR_INITIALIZE' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAYAAAAVwQAAFUCAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
	</layout>
</document>
</root>
