VERSION0/TPF0TVersionnumberdetails Version 276 PRJFILEHEADER0QTPF0TPrjFileHeaderZpercnt@ZordxZordy Targetfile i2cmuxd.c Targetpath'C:\myfiles\microchip\projects\ai2cmuxd\ Templatefile)C:\WINDOWS\Desktop\picexp\templates\c.txt Targetdevice PIC16F872 TargetMimicDEFAULT Targetclock = PaletteCountSciCount Notes.Strings{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\fswiss\fprq2 Arial;}{\f3\fswiss Arial;}{\f4\fmodern\fprq1 Courier New;}{\f5\fswiss Arial;}{\f6\fswiss\fprq2 System;}}{\colortbl\red0\green0\blue0;}.\deflang2057\pard\plain\f2\fs20\b IntroductionW\par \plain\f2\fs20 This project demonstrates a multiplexed display with I2C interface.\par /\par The sub-circuits used in this project are:\par - 'I2C slave RAM'@\par \pard\li60\plain\f2\fs20 - 'Display 4-dig 7-seg (com anode)\par - '3-bit port'\par \pard\plain\f2\fs20 J\par The target device is a PIC16F872 with crystal clock running at 4.0MHz\par .\par The industry standard I2C bus opens the way for modular design offering cross-platform support and re-usable design. This project can be used as a framework for other I2C slave devices and can also be a sub-circuit in it's own right, an example of which is the 'I2C 4-dig mux display' sub-circuit.\par \par \par \plain\f2\fs20\b Operation \par \plain\f2\fs20 Looking from the outside the I2C interface appears as a 2-byte RAM device. The 4-digit multiplexed display is updated by simply writing data to location 0 of the I2C RAM. When the RAM is written to, it sets a flag indicating the arrival new data, the foreground program (main program loop) detects this event and carries out the required task, in this case updating the display.\par \\par The following operations can be carried out when writing to the 'I2C slave RAM' device.\par \par \plain\f2\fs20\ul Address\plain\f2\fs20 \tab \plain\f2\fs20\ul Data\plain\f2\fs20 \tab \plain\f2\fs20\ul Operation\plain\f2\fs20 #\par 0\tab \tab 0\tab Clear display!\par 0\tab \tab 1\tab Home cursorQ\par 0\tab \tab n\tab Print character to display i.e. '0123456789.-Er'\par ^\par A read may be made from address 0 over the I2C bus as confirmation of a successful write.\par \par The 'I2C slave RAM' can be configured to have more memory at design time and can have any family address and any device address. The '3-bit port' effectively over writes the device address at run time, this facilitates hardwired addressing of the I2C.\par \par The I2C family address has been set at design time to 10 and the device address is set by the '3-bit port' ADD_. Assuming the inputs to 'ADD_' are tied to ground then the I2C address resolves to 0xA0.\par &\par \plain\f2\fs20\b Application code \par \plain\f2\fs20 Below is the application code for this project. To use it, select and copy (ctr-insert) the code below and past it into a text editor and save as a 'C' file in your working directory. You may also need to change the build output path using 'Project | Options'\par \par \plain\f4\fs16 L\par ///////////////////////////////////////////////////////////////////////L\par //// AI2CMUXD.C ////L\par //// ////L\par //// Demo application of simple 4-digit multiplex 7-segment ////L\par //// display with i2c interface. ////L\par //// ////L\par //// Use the i2c interface to write digits to the display. ////L\par //// The i2c interface behaves as a 2 byte i2c slave RAM. ////L\par //// Writing data to address 0 will write a digit to the display. ////L\par //// See also sub-circuit 'I2C 4-Digit mux display' ////L\par //// ////L\par //// This program is an example of how your application code is ////L\par //// is organised. Note the #include "i2cmuxd.c", this include ////L\par //// file was generated by QuickBuilder and contains all ////L\par //// dirver code. ////L\par //// ////L\par //// This demo is intended for a PIC16F872 ////L\par //// Compile using CCS 'C' visit www.quickbuilder.co.uk/qb/ccs ////L\par ///////////////////////////////////////////////////////////////////////\par #include <16f872.H>\par \par ,\par #fuses hs,wdt,noprotect,put,nowrt,nolvp \par #case\par \par #define PORTA 5 \par #define PORTB 6\par #define PORTC 7\par #define TRISA 0x85 \par #define TRISB 0x86\par #define TRISC 0x87\par !\par #define RTCC_ZERO INT_TIMER0\par \par #include "i2cmuxd.c"\par \par \par \par #int_rtcc \par void RTCC_ISR() \par \{*\par MUXD_1DO(); // refresh display \par \}\par \par \par main() \{\par BYTE b; \par \par 7\par // initialise sub-circuits and rtcc interrupts7\par //--------------------------------------------!\par INIT_SUB_CIRCUITS(); 2\par setup_counters(RTCC_INTERNAL,RTCC_DIV_2);&\par enable_interrupts(RTCC_ZERO);#\par enable_interrupts(GLOBAL);\par \par \par "\par // I2C set device address)\par I2CSLRAM_1SETDADD( ADD_READ() );\par \par !\par // power up test display!\par // ---------------------\par I2CSLRAM_1DISABLE();=\par printf(MUXD_1PUTC,"8.8.8.8"); // all on for 1/2secA\par for ( b=250; b!=0 ; b--) \{delay_ms(2); restart_wdt();\}>\par MUXD_1CLEAR(); // all off for 1/2secI\par for ( b=250; b!=0 ; b--) \{delay_ms(2); restart_wdt();\} \par I2CSLRAM_1ENABLE(); \par  \par \par \tab // main loop\par \tab //----------\par while(1) \{\par restart_wdt(); \par '\par // monitor i2c for updates,\par if ( I2CSLRAM_1UPDATE == 2) \{A\par I2CSLRAM_1UPDATE = 0; // clear i2c update flag\par .\par if ( I2CSLRAM_1ADDR == 0 ) \{+\par b = I2CSLRAM_1DATA[0];!\par if (b == 0 )'\par MUXD_1CLEAR();&\par else if (b == 1 ))\par MUXD_1CURHOME();\par else'\par MUXD_1PUTC(b);\par \}\par \} \par \par // poll i2c ram\par I2CSLRAM_1DO(); \par \}\par \}\plain\f5\fs20 \par }TitleI2C slave Multiplexed DisplayKeywordsI2C;slave;4-dig;mux;display AltTemplate SCGENERIC0!TPF0 tScGenericLibName2C:\Program Files\QuickBuilder\\data\c_standard.libcctnameDisplay 4-dig 7-seg (com anode) description>Four digit 7-segment multiplexed decoded common anode display.keywords:Display;4-digit;7-segment;multiplexed;decoded;common anodeScTypeiocountrefnameMUXD_CctAsMetafile.Data \\Xni\ I . EMFX    XX  ``K@0 qiqi  & % '% + GZ % (   % ( l &% % 6 % ( N &% 60 % (  &% 6 % ( N 4&% 6 4% ( 0 R&% 6 % ( 0  &% 6  % (  R&% 6 % ( z &% 6% ( \ &% 6> % ( .&% 6% ( \ 4&% 6 4% ( > R&% 6 % ( >  &% 6  % ( R&% 6 % ( &% 6% ( j&% 6L% ( <&% 6% ( j4&% 64% ( LR&% 6.% ( L &% 6 % ( R&% 6% ( &% 6,% ( x&% 6Z% ( J&% 6,% ( x4&% 64% ( ZR&% 6<% ( Z &% 6 % ( ,R&% 6% (  RL<Arialdt€S`x̍U0pdt4)z4`4S``4 *444p<4̜p0t edpTcHd pKe% T}@UU@ ` LCOMMON ANODE 7-SEGMENT DISPLAY&%,,%& %&% &+ % %  % ( RL<Arial115W(̸ WWp15Xld܈dUT܈ `\qPd kad1$1Pdd܈tܞdUT܈ `d`aPd1$1a% TT3 <@UU@ LPa2.% ( RL<ArialCECAEC[t% TT=F@UU@ LPb% ( RL<Arial% TT ^g@UU@ LPc% ( RL<Arial% TThq@UU@l LPd% ( RL<Arial% TT^g@UU@0 LPe% ( RL<Arial% TT=F@UU@N LPf % ( RL<Arial ` 3% TTPY@UU@ 4LPg% ( RL<Arial% TT v@UU@ $ LPo&% ( RL<Arial% TXr{@UU@  LPdp% ( RL<Arial% TT6v;@UU@ $ LPo&% ( RL<Arial?% TTbvg@UU@$ LPo&% ( RL<Arial% TTv@UU@$ LPo&% (  | & % 6 % (  RL<Arial% TX)2@UU@ ALPdp% (  | & % 6 % (  RL<Arial% TT3<@UU@ }LPg% (  | & % 6 % (  RL<Arial% TT<E@UU@ LPf % (  | 4& % 6 4% (  RL<Arial% TTFO@UU@ LPe% (  | $ & % 6 $ % (  RL<Arial% TTlu@UU@ LPa% (  | & % 6 % (  RL<ArialP`1$1`d`lt+0`d`ltD-]0ܭ`ltd̵x-ܭݭ`lt$ܭ̐ܭܭ``% TTcl@UU@ LPb% (  | & % 6 % (  RL<Arial{{% TTYb@UU@ mLPc% (  | p& % 6 p% (  RL<Arial{{{% TTPY@UU@ 1LPd% (   & % 6 D% (  RL<Arial{{{{% TT  )@UU@ LP1% (   & % 6 D% (  RL<Arial{{{{% TT- 1)@UU@ LP2% (  & % 6D% (  RL<Arial{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{% TT] a)@UU@LP3% (  & % 6D% (  RL<Arialp1$1#`[1W`t”ܭ]`t`#`ܭ1#``t|ݭ̃V0#``t8V:Wݭ|R` haha|ݭPE% TT )@UU@LP4% ( RLZArial  XX  ``K@0 qiqi & % '% TX(@UU@ LPD1+&% (    & % 'z% V,N Vl  8N V% (  % (    & % '% +/ H % (  % (  N & % % 6 % (    & % 6~ &% (    t& % 60 t% (    (& % 6 % (    & % 6 % (  RLZArial% 6 % ( >  &% 6  % ( R&% 6 % ( % TX@UU@ LPQ12&% (    & % '% +s % (  % (  (& % % 6p(% (  RL<Arial6 % ( &% 6% ( & 6,% ( x% TT^b@UU@ LPA% ( RL<Arial% 64% ( ZR&% 6<% ( Z % 6 % % TTLO@UU@LP1% (  d& % 6pd% (  RL<ArialedpTcHdpKe% T}@UU@ LCOMMON ANODE 7% TT^b@UU@ELPB% ( RL<ArialArial115W(̸ WWp15Xld܈dUT܈ `\qPd kad1$1PddtܞdUT܈ `d`a% TTLO@UU@%LP2% (  & % 6p% (  RL<Arial TT=F@UU@ L% TT^c@UU@LPC&% ( RL<Arial TT ^g@UU@ L% TTLO@UU@aLP3% (  T& % 6pT% (  RL<Arial% TThq@UU@l LPd% ( L<Arial% TX^f@UU@5LPE1% ( RL<Arial% TT^g@UU@0 LPe% ( R<Arial% TTLO@UU@LP6% (    & % '% *Ml% (  % (  & % % 6L% (  RL<Arial ` 3 TTPY@UU@ 4L% TX^f@UU@qLPE2% ( RL<Arial%TT v@UU@ $ L% TTLO @UU@QLP4% (    & % '% *Ml% (  % (  & % % 6L% (  RL<ArialArial% TX^f@UU@LPE3% ( RL<ArialArial?% TTL O@UU@LP5% (    & % '% *  3% (  % (  P (& % % 6 (% (  RL<Arial@UU@$ LPo&% (  | & % 6 %(  RL<% TX@UU@ LPY0% ( RL<Arial% TX)2@UU@ ALPdp% (  | &% TX@UU@ LP15% (    & % '% * S r% (  % (  P d& % % 6 d% (  RL<Arial | & % 6 % (  RL<Arial% TX@UU@ ELPY1% ( RL<Arial TT<E@UU@ LPf % (  | 4& % 6 4% (  RLr% TX@UU@ %LP14% (    & % '% *  % (  % (  P & % % 6 % (  RL<Arial(  RL<Arial% TX@UU@ LPY2% ( RL<Arial (  | & % 6 % (  RL<rialP`1$1`d`lt% TX@UU@ aLP13% (    & % '% *  % (  % (  P & % % 6 % (  RL<Arial{{% TX@UU@ LPY3% ( RL<Arial p% (  RL<Arial{{{% TX@UU@ LP12% (    & % '% *  '% (  % (  P & % % 6 % (  RL<Arial{{% T  )@UU@ L% TX@UU@ LPY4% ( RL<Arial{{{{% TX@UU@ LP11% (    & % '% * @ _% (  % (  P T& % % 6 T% (  RL<Arial{{{{{{{{{{{{{{{{{% TT] a)@UU@LP3% ( & % TX@UU@ 5LPY5% ( RL<Arialt|ݭ̃V0#``t8V:Wݭ|R` haha|ݭPE% TT )@UU@% TX@UU@ LP10% (    & % '% *  % (  % (  P & % % 6 % (  RL<Arial``K@0 qqi & % '%TX(@UU@ L% TX@UU@ qLPY6% ( RL<Arial% (  % (   & % '% +H % (  % % TT @UU@ QLP9% (    & % '% *  % (  % (  P & % % 6 % (  RL<Arial % 6  (  RLZArial% 6 % ( >  &%% TX@UU@ LPY7% ( RL<Arial@UU@ LP12&% (    & % '% +s % ( % TT @UU@ LP7% ( RLZArialArial6 % ( &% 6% ( & 6,% ( % TXYe@UU@lLPU1+&% ( RL<ArialArial% 6% ( ZR&% 6<% ( Z % 6% TxY!u*@UU@l L\74LS138% (    & % '% + z % (  % (   & % % 6 % (    & % 6| % (     & % '% + z % (  % (   & % % 6| % (    & % 6 % (     & % '% + Lz x% (  % (   d& % % 6| d% (    d& % 6 d% (     & % '% + z :% (  % (   (& % % 6| (% (    (& % 6 (% (     & % 'z% V,(> V\ z 8> V% (  % (    & % '% +# < % (  % (  > & % % 6 % (    & % 6n &% (    t& % 6 t% (    (& % 6 % (    & % 6 % (  RLZArialArial% TTLO@UU@LP6% (    & % TX"@UU@ LPQ22&% (    & % 'z% V,NXjV8jV% (  % (    & % '% +Oh% (  % (  j& % % 6% (   & % 6&% (   t& % 6Lt% (   (& % 6% (   & % 6% (  RLZArial% '% Ml% (  % (  &% % 6L% % TXER@UU@2LPQ32&% (    & % 'z% V,u~ZVx8ZV% (  % (    & % '% +<U% (  % (  Z& % % 6% (   & % 6&% (   t& % 6<t% (   (& % 6% (   & % 6% (  RLZArial(  RL<Arial@UU@$ LPo&% (  | & % 6% TXly@UU@"LPQ42&% (   H& % 6 % (    & % 6 % (  RL<ArialPdp% ( | &% TX@UU@ LP15% ( % T`nw@UU@ LTVCC%&% (    & % '0% *x% (  % (    & % '% * x % (  % (    & % '% * x % (  % (    & % '% + f % (  % (   & % % 6 % (    & % 6 % (     & % '% +  % (  % (   & % % 6 % (    & % 6 % (     & % '% +  G% (  % (   4& % % 6 4% (    4& % 6 4% (     & % '% +  % (  % (   & % % 6 % (    & % 6 % (     & % '% + Z % (  % (   p& % % 6 p% (    p& % 6 p% (     & % '% +  % (  % (   & % % 6 % (    & % 6 % (     & % '% +  % (  % (   & % % 6 % (    & % 6 % (     & % '% +  4 % (  % (   $ & % % 6 $ % (    $ & % 6 $ % (     & % 'z% V,TTT% (  % (  T& % % 6% (   T& % 6% (  RL<Arial@UU@ LP11% (    & % '% * @ _% % T@UU@q L`T1 ______ % (    & % 'z% V,&-T\T,DT\% (  % (  T\& % % 6D% (   T,& % 6D% (  RL<Arial:Wݭ|R` haha|ݭPE% TT @UU@% T$@UU@ L`T2 ______ % (    & % 'z% V,9ATTT% (  % (  T& % % 6% (   T& % 6% (  RL<Arial% TX@UU@ qLPY6% ( RL<Arial% (  %% T.7@UU@a L`T3 ______ % (    & % 'z% V,LTTLT4TL% (  % (  TL& % % 64% (   T& % 64% (  RL<ArialArial %   (  RLZArial% 6% ( >  &% TAJ@UU@ L`T4 ______7 % (    & % 'z% V,_gTTT% (  % (  T& % % 6% (   T& % 6% (  RL<Arial( &% 6% ( & 6, ( % @% TU^@UU@Q L`T5 ______ % (    & % 'z% V,szT< T $ T< % (  % (  T< & % % 6$ % (   T & % 6$ % (  RL<Arial z % (  (   & % % 6 % (    &% Thq@UU@ L`T6 ______ % (    & % 'z% V,T T  T % (  % (  T & % % 6 % (   T & % 6 % (  RL<Arial  d& % % 6| d% (    d&% 6 d% ( % T{@UU@A L`T7 ______ % (    & % 'z% V,T, T  T, % (  % (  T, & % % 6 % (   T & % 6 % (  RL<Arial % ' +# < % (  % (  > & % % 6 % T@UU@ L`T8 ______ % (    & % 'z% V,TT\tT% (  % (  T& % % 6t% (   T\& % 6t% (  RL<Arial% (   & % TX"@UU@ LPQ22&% ( % T@UU@ L`T9 ______ % (    & % 'z% V,TTT% (  % (  T& % % 6% (   T& % 6% (  RL<Arial% 6Lt% (   (& % 6% (   & %% T@UU@ L`T10 ______ % (  T &$% 6 % (     & % 'z% V,T T r T % (  % ( % RL<Arialz% V,u~Z8ZV% (  % (    & % '% +% T N@UU@ LlTARGET ________ %& % (  4 & % 64 % (    & % 6p % (    & % 6R % (   . & % 6: % (     & % '0% *% (  % ( % RL<Arial% Xly@UU@"LPQ42&% (   H& % 6 % T|%.@UU@ &L\8 X 470R  &% ( RL<Arial( | &% TX@UU@ LP15 ( % Tx@UU@ L\4 X 1K2  % ( RL<Arial*x% ( % (    & % '% * x % ( % T@UU@  L`4 X 2N3906  &% (  h&& % 6&% (   hJ& % 6J% (   J& % 6t% (   && % 6% (   & % 6% (   & % 6t% (  RLZArial(    & % 6 % (     & % '% TX@UU@LPC1+&% ( RL<Arial    4& % 6 4% (     & % '%% Tl@UU@RLX100nF% (  & % 6(% (   h(& % 6(% (   F& % 6F% (   d& % 6d% (     & % '0% *x% (  % (    & % '% * x % (  % (    & % '% *% (  % (  &$% % W$8% (   &$% W$% (   &$% W$}`  % (   &$% W(   % (   &$% W$j` % (   &$% W$Wpp% (   &$% W$C]p% (   &$% W$0I% (   &$% W$6% (   &$% W$ #% (   & % W$  (% (   & % W$P  % (   & % W$P  % (   & % W$P d d% (   & % W( t t (% (   & % W$P ( (% (   & % W( d d t% (   & % W$--  (% (   & % W(@ t% (   & % W$]](% (   & % W(f t% (   & % W$(% (   & % W$]]% (   & % W$-] % (   & % W$--  % (   & % W$-  % (   & % W$  % (   & % W$33|  % (   & % W$==|  % (   & % W$PP| 4 4% (   & % W$FF|  % (   & % W$ZZ| p p% (   & % W$cc|  % (   & % W$mm|  % (   & % W$vv| $ $ % (   & % W0F(D(Dtt8% (   & % W0 3 % (   & % W0 = DDDD% (   & % W03F % (   & % W(FP 44% (   & % W0Zc ppp% (   & % W0cv DD$ $ % (   & % W0m   ` % (   & % W0v $ $    % (   & % W0Fdd% (   & % W$=F% (   & % W,=P4 4DD% (   & % W$% (   & % W$% (   & % W$]% (   & % W(% (   & % W$  % (   & % W$  H% (   & % W,3TT % (   & % W$= F % (   & % W$= =% (   & % W(=F % (   SwModuleAsStrings.Strings//
//
:// Cursor is auto incremented to the next digit except in // the case of decimal point.:// CR (0x0D) cariage return moves cursor to home position.;// None-printable characters are shown as 3 horizontal bars// (segments a,g,d).//-// Example - the following will print "12.34"// MUXD_CURHOME();#// printf(MUXD_PUTC, "12.34");//2// MUXD_CURHOME() : Move cursor to home position#define P__ PORT_P_#define TRISP__ TRIS_P_#define P1__ PORT_P1_, _A_#define TRISP1__ TRIS_P1_, _A_#define P2__ PORT_P2_, _B_#define TRISP2__ TRIS_P2_, _B_static BYTE digit__[4];static BYTE cursor__= 0;'//*************************************BYTE const MUXD_TAB__[10]={// abcdefg. 0b11111100, // 0 0b01100000, // 1 0b11011010, // 2 0b11110010, // 3 0b01100110, // 4 0b10110110, // 5 0b10111110, // 6 0b11100000, // 7 0b11111110, // 8 0b11110110, // 9};'//*************************************void MUXD_DO(void) { static int robin=0; / *P__ = 0xff; // extinguish digit  // select next digit/ bit_clear(*P1__); // address select 0 if (bit_test(robin, 0)) bit_set(*P1__); / bit_clear(*P2__); // address select 1 if (bit_test(robin, 1)) bit_set(*P2__);: *P__ = digit__[robin]; // output next segment pattern1 robin--; // inc and wrap robin robin &= 0x3; }'//*************************************void MUXD_CURHOME() { cursor__ = 0;}'//*************************************// set dig with c"void MUXD_DIGIT(int dig, char c) { BYTE ptn;  if (c == '.') digit__[dig] &= 0xfe; else { if (c==' ')6 ptn =0; // space turns off digit else if (c=='-')" ptn = 0b00000010; // - else if (c=='E')" ptn = 0b10011110; // E else if (c=='r')" ptn = 0b00001010; // r else { c = c-'0'; if (c <10)$ ptn = MUXD_TAB__[c]; else9 ptn = 0b10010010; // non printable char } digit__[dig] = ~ptn; } }'//*************************************void MUXD_PUTC(char c) { int dig;" // cariage return homes cursor if (c == 0x0D) {  cursor__ = 0; return; }  dig = cursor__; if (c == '.') { dig--; dig &= 0x3; } else {2 cursor__++; // inc and wrap cursor cursor__ &= 0x3; } MUXD_DIGIT(dig,c);}'//*************************************void MUXD_CLEAR() { cursor__ = 0; digit__[0] = 0xff; digit__[1] = 0xff; digit__[2] = 0xff; digit__[3] = 0xff; *P__ = 0xff;}'//************************************* MUXD_INIT() {  *TRISP__ = 0; bit_clear(*TRISP1__); bit_clear(*TRISP2__); MUXD_CLEAR();} ///section>//
PartCountPreScale? SCGENERIC0.TPF0 tScGenericLibName2C:\Program Files\QuickBuilder\\data\c_standard.libcctname I2C slave RAM description#I2C Slave mode RAM using SSP modulekeywordsI2C;slave;ssp;ramScTypeiocountrefname I2CSLRAM_CctAsMetafile.Data xxX2$rw+q84& EMFt   XX  ``K@0 qiqi  & % '% *  % (   % (  & % % 6l % (  RL<ArialG_RA3_RA2_REFADC_OFFADC_CLOCK_DIV_2ADC_CLOCK_DIV_8ADC_CLOCK_DIV_32ADC_CLOCK_INTERNALL_TO_HH_TO_L% T`8$A@UU@ LTSDA&% (    & % '0G% *  G% (  % (   4& % % 6l 4% (  RL<Arialisalphaisdigitisspaceisxdigitiscntrlisprintisgraph% T`K#T@UU@ LTSCL&% (    & % 'z% V,9A    % (  % (   & % % 6 % (    & % 6 % (  RL<ArialSTDERRSSTDOUT RS232_1IN RS232_1OUTRS232_1INCOMING% T2;@UU@ y L`T1 ______ % (    & % 'z% V,LT  L 4 % (  % (   & % % 6 4% (    L& % 6 4% (  RL<ArialrDS1820_1WRITTEdatadiDS1820_1RE_BYTEDS1820_1READ_TEMPERATUREbNI% TEN@UU@  L`T2 ______ % (  P &$% 6P % (    &$% 6P % (     & % 'z% V,hr     % (  % ( % RL<ArialENABLE I2CHW_READ I2CHW_WRITE I2CHW_ISR i2c_bytesi2c_statI2CHW_DO I2CHW_SETDADD% Thq@UU@  LdTARGET _____ %& % (   & % 6 % (   P & % 6 % (    4& % 6 4% (    4& % 6P % (  RLTArial% TZf@UU@ p LhI2C SLAVE RAM%,,%,,+,,8% (  & % W$==l  % (   & % W$PPl 4 4% (   SwModuleAsStrings.Strings//
//
// I2CSLRAM_DO() : mandatory - call at regular intervals// to clear error conditions.:// I2CSLRAM_UPDATE : 1=read occurred,2=write occured. // cleared by user.// // Example:$// if ( I2CSLRAM_UPDATE == 2) {6// I2CSLRAM_UPDATE = 0; // clear update flag// ...// your code here// ... // }// // Rev1.0://********************************************************'// (C) Copyright 2002 mTECH 2// This source code may only be used by Licensees 7// of QuickBuilder as specified in the End User License8// Agreement ("EULA")located at www.quickbuilder.co.uk. ;// No other use, reproduction or distribution is permitted 3// without specific written permission from mTECH. 7// Derivative programmes created using this software in'// object code form are not restricted.://*******************************************************>*#define RAMSIZE__ _SIZE_ // power of 2@#use i2c(slave,sda=PIN_C4,scl=PIN_C3,address=0xa0,force_hw,fast)3#define I2CADDR__ ((_FAMADDR_<<4) | (_DEVADDR_<<1))BYTE I2CSLRAM_ADDR=0;BYTE I2CSLRAM_DATA[RAMSIZE__];BYTE I2CSLRAM_UPDATE=0;##define I2CSLRAM_PIR1 0x0c##define I2CSLRAM_SSPCON 0x14$#define I2CSLRAM_SSPBUF *0x13$#define I2CSLRAM_SSPADD *0x93$#define I2CSLRAM_SSPSTAT *0x94I#define I2CSLRAM_SSPIF *I2CSLRAM_PIR1,3 // interrupt/event flagB#define I2CSLRAM_SSPOV *I2CSLRAM_SSPCON,6 // overflow flag<#define I2CSLRAM_DISABLE() bit_clear(*I2CSLRAM_SSPCON,5):#define I2CSLRAM_ENABLE() bit_set(*I2CSLRAM_SSPCON,5)*#define I2CSLRAM_READ(x) i2c_read(x)+#define I2CSLRAM_WRITE(x) i2c_write(x)'//*************************************#int_ssp noclearvoid I2CSLRAM_ISR() { static BYTE i2c_bytes=0; BYTE i2c_stat,b;  3 bit_clear(I2CSLRAM_SSPIF); // clear event flag  // determine state i2c_stat = I2CSLRAM_SSPSTAT;+ i2c_stat &= 0x25; // ignore S bit_set(i2c_stat,3); switch( i2c_stat ) {A case 0x09: // state1: master write. last byte was addressC b = I2CSLRAM_READ(1); // dummy read clears bf flag i2c_bytes = 0; break;> case 0x29: // state2: master write. last byte was data2 b = I2CSLRAM_READ(1); // get data ! if (i2c_bytes == 0) {$ I2CSLRAM_ADDR = b-1; }% else if ( i2c_bytes > 0 ) { I2CSLRAM_ADDR++;/ I2CSLRAM_ADDR &= (RAMSIZE__-1);1 I2CSLRAM_DATA[I2CSLRAM_ADDR] = b;; I2CSLRAM_UPDATE = 2; // flag data written } i2c_bytes++; break;@ case 0x0c: // state3: master read. last byte was address= case 0x2c: // state4: master read. last byte was data I2CSLRAM_ADDR++;+ I2CSLRAM_ADDR &= (RAMSIZE__-1);; I2CSLRAM_WRITE( I2CSLRAM_DATA[I2CSLRAM_ADDR] );4 I2CSLRAM_UPDATE = 1; // flag data read break;( case 0x28: // state5 master nack // no action taken break; default:6 reset_cpu(); // forbidden state, reset cpu }}'//*************************************void I2CSLRAM_DO() { BYTE b;( // check for i2c overflow condition% if (bit_test(I2CSLRAM_SSPOV) ) { " bit_clear(I2CSLRAM_SSPOV); b = I2CSLRAM_SSPBUF;" bit_clear(I2CSLRAM_SSPIF); }}'//*************************************"void I2CSLRAM_SETDADD(BYTE addr) { I2CSLRAM_SSPADD &= 0xf0;' I2CSLRAM_SSPADD |= (addr&0x7) << 1;}'//*************************************void I2CSLRAM_INIT() { I2CSLRAM_SSPADD = I2CADDR__; enable_interrupts(INT_SSP);} ///section>//
PartCountPreScale? SCGENERIC0 (TPF0 tScGenericLibName2C:\Program Files\QuickBuilder\\data\c_standard.libcctname 3-bit port description*3-bit port built from individual port bitskeywords3-bit;port;bitsScTypeiocountrefname PORT3BIT_CctAsMetafile.Data X1)~57) EMF/   XX  ``K@0 qiqi  & % '% *  G% (   % (  4& % % 6l 4% (  RL<Arial{{% TTKT@UU@ LP1% (    & % '0G% *  % (  % (   & % % 6l % (  RL<Arial{{{% TT^g@UU@ LP2% (    & % '0G% *  % (  % (   & % % 6l % (  RL<Arial/DC:\WINDOWS\Desktopexp\libsource\frag port\3-bitport.emfO :i+00#C:\1))~Windows1) DesktoDESKTOP1,ppicexpPICEXP!1,plibsourceLIGP% TT8A@UU@ LP0% (    & % 'z% V,9AP P  P % (  % (  P & % % 6 % (   P & % 6 % (  RL<Arial% T1:@UU@ s L`T1 ______ % (    & % 'z% V,LTP P L 4P % (  % (  P & % % 6 4% (   P L& % 6 4% (  RL<Arial% TEN@UU@  L`T2 ______ % (    & % 'z% V,_gP P  P % (  % (  P & % % 6 % (   P & % 6 % (  RL<Arial% TXa@UU@ i L`T3 ______ % (   &$% 6 % (     & % 'z% V,  ~ 2  % (  % ( % RL<Arial% T@UU@P } LhTARGET ______ %& % (   &$% 6 % (    & % 6 % (    4& % 6 % (    & % 6 p% (    & % 6 % (    4& % 6 4% (    & % 6 % (  RLTArial% Tmy@UU@  L`3-BIT PORT&+,+2,,% (  & % W$==l  % (   & % W$PPl 4 4% (   & % W$ccl  % (   SwModuleAsStrings.Strings//
//
#define P0__ PORT_P0_, _0_#define TRISP0__ TRIS_P0_, _0_#define P1__ PORT_P1_, _1_#define TRISP1__ TRIS_P1_, _1_#define P2__ PORT_P2_, _2_#define TRISP2__ TRIS_P2_, _2_BYTE PORT3BIT_READ() { BYTE r; r=0;  bit_set(*TRISP0__); bit_set(*TRISP1__); bit_set(*TRISP2__);  if (bit_test(*P0__)) bit_set(r,0); if (bit_test(*P1__)) bit_set(r,1); if (bit_test(*P2__)) bit_set(r,2); return r;}void PORT3BIT_WRITE(BYTE r) {  bit_clear(*TRISP0__); bit_clear(*TRISP1__); bit_clear(*TRISP2__);  if (bit_test(r,0)) bit_set(*P0__); if (bit_test(r,1)) bit_set(*P1__); if (bit_test(r,2)) bit_set(*P2__);} ///section> PartCountPreScale? CCTOBJ0QTPF0tcctobjscaleʀ?qordxXqordyIoSelectArray.Strings-111-1-1-1-1-1 headertext I2CSLRAM_1parentfrmmain.pnSheettopleftcctname I2C slave RAMrefname I2CSLRAM_1 Annotated swincluded ScGeneric.OwnerIDEnabled Select SheetNumPropertyValue.Strings-1-1-1-1-10-1-1 CCTOBJ0DTPF0tcctobjscaleʀ?qordxsqordyIoSelectArray.Strings-1151617-1-1-1-1 headertextADD_parentfrmmain.pnSheettopleft-cctname 3-bit portrefnameADD_ Annotated swincluded ScGeneric.OwnerIDEnabled SelectSheetNumPropertyValue.Strings-1-1-1-1-1-1-1-1 CCTOBJ0ZTPF0tcctobjscaleʀ?qordx_qordy9IoSelectArray.Strings-1112-1-1-1-1 headertextMUXD_1parentfrmmain.pnSheettop left#cctnameDisplay 4-dig 7-seg (com anode)refnameMUXD_1 Annotated swincluded ScGeneric.OwnerIDEnabled SelectSheetNumPropertyValue.Strings-1-1-1-1-1-1-1-1