Note: Tabs got clobbered in the file transfer from Wayne to Decade Eng., and were subsequently fixed up without rechecking the program for correct compilation or function! (MH) Decade Engineering makes no warranty of any kind with respect to the usefulness or correctness of the information supplied herein. The user must accept all associated risks. Real Time Video Clock using the Decade Engineering BOB-II Module by Wayne Kashinsky   The BOB II SIMM provides a fast and easy way to do video overlay and basic character generation for a wide variety of projects. I have designed a low cost circuit board that uses the Microchip PIC processor to allow the experimenter a base to develop many different applications. The RTVC discussed here is just an example. (insert picture here) Battery backup     RTC chip       Buttons  (4)      PIC 16F84 I/O      VIDEO I/O The BOB II requires only +12 volts and a video line to generate characters. It receives its commands from a serial line at 9600 baud. In order to make a low cost stand-alone device, I chose the PIC 16F84 microcontroller which can process signals on up to 8 binary I/O lines and provide the serial signal needed by the BOB II. The PIC processor can be programmed with a variety of low cost devices in Assembler, C and BASIC. For fast turnaround on projects, my lab uses Microengineering’s PBP Basic compiler. You can write programs in BASIC on a PC and program them into the EEPROM memory of the PIC. This allows an almost interactive development system since the 1024 bytes of program memory in the PIC 16F84 can be erased and reprogrammed in seconds. Because the BASIC language allows for control of I2C bus devices, you can control hundreds of specialized chips via two lines for clock and data. The bus is used for the RTC chip PCF8583 in this example. The RTVC is similar to a TIME / DATE function on many camcorders. The difference is that this one is completely programmable. As an example, you can vary the format of the data, show elapsed time, reset the timer if an event occurs, control the camera for turn ON/OFF at a given time, or display real-time data from external sources like serial devices or TTL / button inputs. The circuit board has the following I/O: I/O PIC BITS VALUE SHOWN Four buttons       B0, B1, B2, B3 1, 2, 4, 8 or combination ON/OFF B4 TTL signal for ON/OFF control Serial IN B5 9600 baud control signals ON/OFF B6 TTL signal for ON/OFF control Serial OUT B7 9600 baud to BOB II I2C lines A0, A1 Port A control of RTC or EEPROM, etc. The RTC chip is addressed with the I2C lines and responds with seconds, minutes, hours, day, month (year, etc), in the format SS, MM, etc. The SS format is Tens of seconds   -   Units of seconds as a single binary coded decimal byte. This is decoded by masking the lower order 4 bits (units) and the upper order 4 bits (tens).  The clock is set by writing to the same internal registers in the BCD format and once set, the battery backup should hold the correct time for months without power. When power is applied, the screen is cleared and RTC is displayed with the prompt: HR for setting the hours digit. Buttons are NEXT, START, +1, +10. Pressing the NEXT button for about 1 second will advance to the MIN prompt or holding it will take you through the time/date set to the START prompt. The RTC will start (elapsed timing) when the START button is pressed. The buttons now are used to display real-time input data on the top right of the screen as 1, 2, 4, 8 or combination numbers from 0-15. (insert schematic here) ' Real time clock program for BOB II and PIC 16F84 ' copyright:  Wayne Kashinsky and Binghamton University- 1/99 ‘ All rights reserved. This program can be ‘ distributed as an example only. It cannot be used as part of a product for sale ‘ without expressed written permission of the author. Preliminary version only, ‘ no warranty is offered or implied ‘ this program takes up 1020 of the 1024 EEPROM bytes on the PIC 16F84 ‘ I suggest testing with 16C84 then enhancing program and using 16C622 with 2048 ‘ bytes (this is UV erased EPROM and makes development take a little longer b5      var     byte b7      var     byte b8      var     word t       var     byte[5] et      var     word elt     var     word cm      var     byte cs      var     byte z       var     byte rloc    var     byte 'location in RTC ram for temp header eltime  var     word '#seconds of elapsed time from start elast   var     word inc     var     byte ret     var     byte skp     var     byte symbol  n9600 = 6 symbol  rtc = %10100010  'i2c rtc address - lower bit=1         trisb = %00001111                 'bit 0-3 as button inputs stup:   pause 1000         serout 7,6,["  {A"]               'reset BOB II (cls)         pause 50         serout 7,6,["{C1000RTC"]         gosub setime         serout 7,6,["{A"]         gosub getime                      'fix start time         eltime = (t[2]*60)+t[1]           'start time '**********************************************'real time loop agn:    peek 6,b5                         'get port b         b5=b5&%00001111                   'mask 4 buttons         gosub getime                      'show time/date         goto agn '*********************************************** 'routine to read the RTC getime: i2cread porta.0,porta.1,$a2,2,[t[1],t[2],t[3],t[4],t[5]]         for b7=1 to 5                     'do for sec,min,hr,day,month         z=t[b7]/16         t[b7]=(z*10)+(t[b7]-(z*16))       'decode into tens and units         next b7 gt1:    et=((t[2]*60)+t[1])               'elapsed time from start         if et< eltime then                 et=et+3600                'fixup for hour change                 endif         elt=et-eltime                     'difference in time from start         cm=elt/60         cs=elt-(cm*60)                    'cm = minutes, cs = second 'position to botton of screen and write out to BOB II         serout 7,6,["{C0010",#t[3],":",#t[2],":",#t[1],"{C1010",#t[5],"/",#t[4],"/99","  {C2010",#cm,":",#cs," {C2600",#b5," "] gret: return '***************************************************************** 'routine to set RTC    mm hh dd momo - button sets +1 or +10 (overflow at 160) '   - so if time is 59 sec, must go to 160 then +1 to recycle to 1 setime: pause 300 hr1:    gosub getime                   'log current time into m,h,mm,dd         serout 7,6,["{C0002 HR"]       'position to line #2 on screen         gosub getinc                   'was button +1, +10 or return         t[3]=t[3]+inc                  'add to RTC byte but must be Tens-Units         gosub wrtime         if ret=0 then hr1 min1:   gosub getime                   'log current time into minutes         serout 7,6,["{C0002 MN"]         gosub getinc         t[2]=t[2]+inc         gosub wrtime         if ret=0 then min1         t[1]=0                          'zero the seconds day1:   gosub getime                    'log current DAY         serout 7,6,["{C0002 DA"]         gosub getinc         t[4]=t[4]+inc         gosub wrtime         if ret=0 then day1 mon1:   gosub getime                    'log current MONTH         serout 7,6,["{C0002 MO"]         gosub getinc         t[5]=t[5]+inc         gosub wrtime         if ret=0 then mon1 retn:   serout 7,6,["{C0002 ST"]       'wait for start button  (#2)         if portb.1 = 0 then retn         return '***************************************************************** 'routine to read setting buttons getinc: inc=0                           'read buttons to set h,m,month,day         ret=0                           'return key hit?? (0)=no         if portb.2=0 then ad10         inc=1                           'add         goto pas ad10:   if portb.3=0 then r         inc=10                          'add 10 (rollover to 0 at 160)         goto pas r:      if portb.0=0 then pas         ret=1                           'done, got to next digit pas:    pause 300         return ' ************************************************* write time to rtc wrtime: for b5 = 2 to 5                 'put binary# back to TENS UNITS         z=t[b5]/10                      'tens         t[b5]=t[b5]-(z*10)              'units         t[b5]=(z*16)+t[b5]         next b5         i2cwrite porta.0,porta.1,$a2,2,[0,t[2],t[3],t[4],t[5]]         return