The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers.    


Datasheet Search Engine   
 
Part # or Description: • 5V RS232 Driver • 2SC5066* • "Real Time Clock" • "USB connector" • "blue led" 5mm • 10 watt zener diode • 2N3055* motorola
 
Search Tip: Try entering the part number only. Include a wildcard (eg. lm317* or 1n4148*)

 

 

Each week have pairs on/off times light connected output BILTJR. have


Datasheet Thumbnail

  

Download PDF



Top Searches for this datasheet



Electromechanical Switch Replacement Bright Idea Light Timer, Junior
Each week have pairs on/off times light connected output BILTJR. have connected light remain entire day, program 24:00 on-time off-time on-time off-time have light come only time during day, program ontime off-time with desired times, program 24:00 on-time off-time have light come times during day, program desired times on-time off-time ontime off-time Once circuit programmed, while power applied output will follow programmed times. given day, will off/low before on-time on/high after on-time before off-time off/low after offtime before on-time on/high after on-time before off-time off/low after off-time programming on/off times held non-volatile memory (battery-backed RAM) settings lost when main power supply removed. BILTJR circuit described herein resistor testing purposes. real application, resistor would replaced some circuitry switch volt line. Also, power supply circuit would also derived from household line voltage.
APPLICATION OPERATION
Overview
"Bright Idea" Light Timer, (BILTJR) digital version venerable lamp on/off timers that when vacation make look like someone home. these timers (but much longer!) everyday basis, just don't have turn lamps their switches when gets dark turn them when bed. BILTJR advantage over lamp timers: programmed turn lights different times each week. features pairs on/off times days with 10-minute resolution. seventh week shares on/off times with first day. circuit consists PIC12C508 Dallas® DS1202 Serial Timekeeping chip, with very required support components. timer times reprogrammable time using connection PC's parallel port Dallas chip's battery-backed RAM.
Theory Operation
BILTJR prepared programming times various days week, well current time week. This done connecting circuit parallel port programming cable running programming software. times programmed with 10-minute resolution from midnight (0:00) midnight following (24:00). example, on-time p.m. (20:00) off-time 9:40 p.m. (21:40), light output will between those times. light always extinguished rolls over into next, programming either off-time 24:00 will keep light until changes. light kept through midnight programming off-time 24:00 on-time 0:00.
Microchip Technology Incorporated, been granted nonexclusive, worldwide license reproduce, publish distribute submitted materials, either original edited form. author affirmed that this work original, unpublished work that he/she owns rights such work. property rights, such patents, copyrights trademarks remain with author.
1997 Microchip Technology Inc.
DS40160A/2_015-page
Electromechanical Switch Replacement
HARDWARE
BILTJR circuit consists PIC12C508 8-pin microcontroller, DS1202 serial timekeeping chip, output indicator LED, resistor, crystal, battery, some diodes, some decoupling capacitors, cable connection header. light on/off output connected pin, chip select output, clock output, data lines accessing DS1202 connected GP2, GP1, GP0, respectively. no-connect now, future expansion configure light override/toggle switch input. lines access DS1202 also brought connector ease connecting programming cable. Ground PIC's GP3/MCLR input brought this connector well. During programming, PIC12C508 held reset jumper built into programming cable parallel port (hopefully with some buffering!) drive DS1202 lines without interference from PIC. non-volatile storage setup data, volt battery used maintain DS1202's time storage areas. diode prevents battery from providing power PIC12C508 when main circuit supply down diode prevents battery from presenting load main supply when supply 32.768 watch crystal creates accurate timetable timekeeping chip completes DS1202 connections. PIC12C508 configured internal 4MHz oscillator, GP3/MCLR programmed function MCLR input. testing, necessary program on/off times using PIC12C508 itself. Since this circuit meant generic, left logic level. power supply circuit included this circuit same reason; thus, external supply necessary power circuit. test BILTJR PIC16C84-based circuit which will described detail; however, schematic enclosed. '84-based circuit superset PIC12C508 schematic described above. adds RS-232 port debugging purposes. gram below illustrates functionality infinite loop. That well-commented source code make program flow easy follow most part. only obscure parts software storage on/off time data week DS1202. This described below: Byte time Byte time Byte time Byte time Byte time Byte time Byte time time bytes stored DS1202 formatted follows: HHHHHTTT bit) where HHHHH hour number ten-minute blocks. example, 10:40pm stored b'10110100' where b'10110' hour (22) b'100' tenminutes (4). valid range HHHHH b'00000' b'11000' 24). valid range b'000' b'101' 50). week stored clock area DS1202 follows: Sunday Monday Tuesday Wednesday Thursday Friday Saturday Note (Saturday) duplicates time schedule (Sunday). numbering scheme shown above just possible scenario; could have Wednesday (and then would Thursday, etc., which case Tuesday (Day would have same on/off schedule Wednesday (Day
Software
software originally written PIC12C508 PIC16C84 application. ease testing (the inevitable compile-burn-test cycle), PIC16C84 used most testing "Junior". That there ifdef code; either PIC12C508 PIC16C84 version still built. software consists subroutines, some start-up code, infinite loop. utility subroutines reading clock data areas DS1202 timekeeping chip other various things such binaryto-bcd conversions. start-up code gets PIC12C508 running infinite loop does actual light timer output control. loose flow dia-
MICROCHIP HARDWARE DEVELOPMENT TOOLS USED
debugging done using PIC16C84 test circuit.
Assembler/Compiler version
MPLAB 3.22.00 development software with MPASM version 1.50.
DS40160A/2_015-page
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
SOFTWARE OVERVIEW
following loose description what software does once PIC12C508 come reset hardware registers variables initialized. Only logic concerned with application described only most general terms ease understanding. Things like resetting watchdog timer, etc., left clarity.
once minute, following: read present time (hours, minutes, week) from DS1202 subtract from week range week local copy (now ranges week changed since last time through turn output state variable before time calculate index into DS1202 (day week state) read DS1202 location index retrieve next output change time convert next change hours ten-minutes binary coded decimal state after time, present time equal next change time toggle state output shadow advance next state state after time, update real output from output shadow
1997 Microchip Technology Inc.
DS40160A/2_015-page
Electromechanical Switch Replacement
GRAPHICAL HARDWARE REPRESENTATION
BRIGHT IDEA LIGHT TIMER
1N4148 DS1202 1N4148 PARALLEL PORT PROGRAMMING DS1202 BATTERY BACKED (REMOVE NORMAL OPERATION)
CLK1202 DAT1202 CS1202 GP5/OSC1 GP4/OSC2 GP3/MCLR PIC12C508 DATA DS1202 CONNECT DS1202 GROUND, LEAVE UNCONNECTED, CONNECT 0.1uF CAPACITOR BETWEEN PINS CONNECT PIC12C508 +5V, GROUND, PLACE 0.1uF CAPACITOR BETWEEN LIGHT
RESISTOR TESTING PURPOSES
32.768
CONNECT RS-232 PORT THRU NULL MODEM CABLE
.1uF C113 .1uF
PARALLEL PORT PROGRAMMING DS1202 BATTERY BACKED (REMOVE NORMAL OPERATION)
CONNECTOR MALE
.1uF
.1uF
PCRXD PCTXD PCDTR
MAX202E DTR232_ TXD232 RXD232
CONNECT 0.1uF CAPACITOR BETWEEN PINS PIC16C84
BRIGHT IDEA LIGHT TIMER (TEST BED)
DATA DS1202 CONNECT DS1202 GROUND, LEAVE UNCONNECTED, CONNECT 0.1uF CAPACITOR BETWEEN PINS
CLK1202 DAT1202 CS1202
RA4/T0CKI OSC1/CLKIN MCLR/Vpp OSC2/CLKOUT Vss/GND Vdd/+5V RB7/DATA RB6/CLOCK PIC16C84
LIGHT
FUTURE EXPANSION
OVRIDE_
32.768
RESISTOR TESTING PURPOSES
1N4148
1N4148
DS1202
DS40160A/2_015-page
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
APPENDIX SOURCE CODE
;/-\ Assembler directives ;\-/ ;comment other following lines list p=16C84 ;build code 16C84 microcontroller list p=12C508 ;build code 12C508 microcontroller list r=DEC list x=ON errorlevel 1,-302 errorlevel 1,-205 ;default radix decimal ;expand inline macros ;turn msgs caused .inc file ;turn directive found column msgs
;/-\ Assembly control #define ;\-/ ifdef _16C84 #define DEBUG endif
;include debugging code with 16C84 version
;/-\ Processor specific include file ;\-/ ifdef _16C84 #include "p16c84.inc" else #include "p12c508.inc" endif
;_12C508
;/-\ General system information ;\-/ ;assembled using MPASM 1.50 ;time byte data stored DS1202 area follows: ;byte time ;byte time ;byte time ;byte time ;byte time ;byte time ;format time byte: ;HHHHHTTT bit) where HHHHH hour ten-minute blocks ;for example, 10:40pm stored b'10110100' where hour (22) b'100' ten-minutes ;valid range HHHHH b'00000' b'11000' ;use b'11000' time keep output until ;valid range b'000' b'101' ;day ;day ;day ;day ;day ;day ;day sunday monday tuesday wednesday thursday friday saturday
number b'10110' midnight
1997 Microchip Technology Inc.
DS40160A/2_015-page
Electromechanical Switch Replacement
;note: (saturday) duplicates time schedule (sunday) ;note: numbering scheme shown above just possible scenario; could have wednesday (and then would thursday, etc., which case tuesday (day would same wednesday (day
;/-\ System timing information ;\-/ ;clock speed: 4MHz ;instruction clock speed: 4MHz 1MHz ;time non-branching instruction: ;time branching instruction: ITIMENS 1000 ;non-branching instruction time
;/-\ Fuses ;\-/ ifdef _16C84 _config _HS_OSC _WDT_ON _PWRTE_ON _CP_OFF else ;_12C508
_config _MCLRE_ON _CP_OFF _WDT_ON _IntRC_OSC endif
;/-\ Miscellaneous equates, #defines, macro definitions ;\-/ ifdef _16C84 h'0c' h'2f' h'03ff' else h'07' h'1f' h'01fe' endif h'0000' sublw sublw
MINRAM MAXRAM MAXROM MINRAM MAXRAM MAXROM
;first location ;last location ;last program word ;_12C508 ;first location ;last location ;last program word
RESET
;location where jump reset ;fix microchip's mnemonic both upper lower case ;used after subtract instruction, this macro will skip next instruction result subtraction ;used after subtract instruction, this macro will skip next instruction result subtraction
#define subwl #define SUBWL SKPLTZ macro btfsc endm macro btfss endm
STATUS,C
SKPGEZ
STATUS,C
#define INSTRS (((usec*1000)/ITIMENS)-4) DELAYUS macro usec ;this macro forms wrapper around delay subroutine, autocalculating parameters needed that subroutine using argument this macro (the approximate number microseconds delay);
DS40160A/2_015-page
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
INSTRS error "delay time small!" endif INSTRS 65535 error "delay time large!" endif ((INSTRS INSTRS messg "delay will quite exact!" endif movlw INSTRS movwf dlyL movlw high INSTRS movwf dlyH call delay endm
;/-\ Microchip's one-line special instruction mnemonics ;\-/ ;CLRC, SETC, CLRDC, SETDC, CLRZ, SETZ, SKPC, SKPNC, ;SKPDC, SKPNDC, SKPZ, SKPNZ, TSTF, MOVFW ;(can upper lower case)
;/-\ Equates variables page (h'0c' h'2f') ;\-/ cblock MINRAM ;note: sec1202 thru wp1202 must remain order contiguous sec1202 ;seconds read/write from/to DS1202 min1202 ;minutes read/write from/to DS1202 hr1202 ;hours read/write from/to DS1202 day1202 ;days read/write from/to DS1202 mon1202 ;months read/write from/to DS1202 dow1202 ;day week read/write from/to DS1202 yr1202 ;years read/write from/to DS1202 wp1202 ;write enable/disable DS1202 clock ;note: sec1202 thru wp1202 must remain order contiguous addrEe ;PIC12C508 eeprom address read/write dataEe ;PIC12C508 eeprom data write ;loop counter variable ;loop counter variable ;loop variable used clkByte subroutine adr1202 ;address DS1202 read write dat1202 ;data value read from write into DS1202 temp ;temporary storage bitVars ;unrelated one-bit variables prevMin ;last minute value from DS1202 variable state ;on#/off# state variable chgHrs ;hours next state change variable chgMins ;ten minutes next state change variable prevDay ;variable used detect when changes bcdL ;LSB result binary conversion bcdH ;MSB result binary conversion ENDRAM1 ;dummy value used over limit endc ifdef _16C84 cblock ENDRAM1 txData ;RS-232 transmit data value dlyH ;variable used delay subroutine dlyL ;variable used delay subroutine dlyTemp ;variable used delay subroutine ENDRAM2 ;dummy value used over limit
1997 Microchip Technology Inc.
DS40160A/2_015-page
Electromechanical Switch Replacement
endc endif ifdef _16C84 (ENDRAM2 MAXRAM) error "too many variables defined!" endif else ;_12C508
(ENDRAM1 MAXRAM) error "too many variables defined!" endif endif
;/-\ port #defines data direction equates port ;\-/ ifdef _16C84 #define #define #define #define #define PORTAIO RXD232 TXD232 DTR232_ UNUSED1 LIGHT endif PORTA,4 PORTA,3 PORTA,2 PORTA,1 PORTA,0 b'00010100' ;RS-232 receive data (o.c. out./s.t. in.) ;RS-232 transmit data ;RS-232 data terminal ready ;unused ;;solid state relay control power light ;direction bits port MSBs don't care)
;/-\ port #defines data direction equates port ;\-/ ifdef _16C84 #define #define #define #define #define #define #define #define #define UNUSED2 UNUSED3 UNUSED4 OVRIDE_ CS1202 IOPIN DAT1202 CLK1202 UNUSED5 PORTB,7 PORTB,6 PORTB,5 PORTB,4 PORTB,3 PORTB,IOPIN PORTB,1 PORTB,0 b'11110100' ;unused (weak pull-up) ;unused (w.p.u.) ;unused (w.p.u.) ;override toggle pushbutton (w.p.u.) ;chip select DS1202 clock chip ;line that both input output ;serial data line DS1202 clock chip (i/o) ;serial clock line DS1202 clock chip ;unused ;direction bits port
PORTBIO
(PORTBIO b'11000000') error in-circuit programming, must inputs!" endif endif
;/-\ port #defines data direction equates gpio port ;\-/ ifdef _12C508 #define LIGHT GPIO,5 ;solid state relay control power light
DS40160A/2_015-page
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
#define #define #define #define #define UNUSED RESET_ CS1202 DAT1202 CLK1202 GPIO,4 GPIO,3 GPIO,2 GPIO,1 GPIO,0 b'00011010' b'00011000' ;override toggle pushbutton ;reset line PIC12C508 (w.p.u) ;chip select DS1202 clock chip ;serial data line DS1202 clock chip (i/o) ;serial clock line DS1202 clock chip ;direction bits gpio port (DAT1202 input) ;direction bits gpio port (DAT1202 output)
DATAINP DATAOUT endif
;/-\ Equate option register ;\-/ ifdef _12C508 b'11001000' endif
OPTREG
;disable wake-up, diable pull-ups, w-dog
;/-\ DS1202 equates definitions ;\-/ BURSTRD BURSTWR RD1202 RAM1202 SEC1202 CTL1202 WEN1202 WPR1202 b'10111111' b'10111110' b'00000' b'00111' b'00000000' b'10000000' ;burst read clock portion DS1202 ;burst write clock portion DS1202 ;read/not write DS1202 command ;RAM/not clock DS1202 command ;DS1202 seconds register address ;DS1202 control register address ;data allow clock writes DS1202 ;data disallow clock writes DS1202
;/-\ Miscellaneous equates ;\-/ ifdef _16C84 #define #define endif #define #define #define #define #define PREON1 PREOFF1 PREON2 PREOFF2 PSTOFF2
;carriage return ASCII code ;line feed ASCII code
;state ;state ;state ;state ;state
before time after time before time after time before time after time before time after time
;/-\ bitVars definitions ;\-/ #define RAMNCLK bitVars,0 #define LITESHD bitVars,1 ;access DS1202 RAM/not clock indicator ;output on/off shadow
;/-\
1997 Microchip Technology Inc.
DS40160A/2_015-page
Electromechanical Switch Replacement
Setup reset interrupt vectors ;\-/ RESET ;reset sends execution here
ifdef _12C508 movwf OSCCAL endif goto initHW
;trim internal oscillator
;assure jump over hardcoded
;/-\ Routine sending data byte serially 9600 baud. Inputs: data send Outputs: none Calls: none ;\-/ ifdef _16C84 send232 movwf movlw movwf loop232 movlw movwf decf jmpStrt addwf goto FILL jmpEnd goto stop goto goto SKPNC goto goto goto goto txData high jmpStrt PCLATH jay,w ;save data send bits data, start, stop
;get high order bits program counter save adding works
PCL,f ;determine what take same stop amount time matter what (goto rotate),8 start send1L1 txData,f send1L1 send0 send0 ;waste cycles ;sending start (start logic ;equalize inter-bit delays ;output ;waste cycles (includes send1L1) ;sending stop (stop logic ;figure value data send
rotate
start
send1L1 send1 goto send0 goto
TXD232 endLoop TXD232 endLoop
;output ;equalize inter-bit delays ;104 time) (loop time) ;skip next done with data framing bits ;not done, another
endLoop DELAYUS decfsz goto return jay,f loop232
DS40160A/2_015-page 2-10
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
(high jmpStrt high jmpEnd) error "jump table crosses page boundary subroutine send232!" endif endif ;_16C84
;/-\ Routine burst reading clock data from Dallas 1202 Serial Timekeeping chip. Inputs: none Outputs: sec1202 thru wp1202 Calls: none ;\-/ rdClock movlw movwf movlw movwf movlw movwf CS1202 CLK1202 sec1202 BURSTRD sec1202 ;activate chip selecting ;start with clock ;point indirect addressing first byte PIC12C508 fill ;command DS1202 bits long
;burst read clock data command
ifdef _16C84 STATUS,RP0 TRISB,IOPIN STATUS,RP0 else movlw DATAOUT tris GPIO endif rdLoop1 SKPNC decfsz goto CLK1202 DAT1202 sec1202,f DAT1202 CLK1202 jay,f rdLoop1
;make data output temporarily ;_12C508 ;make data output temporarily
;lower clock ;assume command going ;look actual command ;skip next really ;not correct ;command data gets clocked rising edge ;skip next clocked command bits ;continue clocking command bits
ifdef _16C84 STATUS,RP0 TRISB,IOPIN STATUS,RP0 else movlw DATAINP tris GPIO endif movlw movwf rdLoop2 movlw movwf
;done outputting command DS1202 ;revert data back input
;_12C508 ;revert data back input
;we're getting bytes data from DS1202
;each byte bits
1997 Microchip Technology Inc.
DS40160A/2_015-page 2-11
Electromechanical Switch Replacement
rdLoop3 CLRC btfsc SETC decfsz goto incf decfsz goto retlw CLK1202 ;clock data clock falling edge ;assume data going ;skip next actual data ;not correct ;rotate data into current PIC12C508 location ;raise clock preparation next ;skip next done with current data byte ;keep working getting current data byte ;point destination next data byte ;skip next done getting data bytes ;contine getting next data byte ;leave clock ;deselect clock chip
DAT1202 INDF,f CLK1202 kay,f rdLoop3 FSR,f jay,f rdLoop2 CLK1202 CS1202
;/-\ Routine burst writing clock data Dallas 1202 Serial Timekeeping chip. Inputs: sec1202 thru wp1202 Outputs: none Calls: none Note: Need write-enable DS1202 before write-protect after ;\-/ ifdef _16C84 wrClock movlw movwf movlw movwf movlw movwf wrLoop1 SKPNC decfsz goto CS1202 CLK1202 sec1202 BURSTWR STATUS,RP0 TRISB,IOPIN STATUS,RP0 CLK1202 DAT1202 eye,f DAT1202 CLK1202 jay,f wrLoop1 ;activate chip selecting ;start with clock ;point indirect addressing first byte PIC12C508 data from ;command DS1202 bits long
;burst write clock data command
;make data output temporarily
;lower clock ;assume command going ;look actual command ;skip next really ;not correct ;command data gets clocked rising edge ;skip next clocked command bits ;continue clocking command bits
DS40160A/2_015-page 2-12
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
movlw movwf wrLoop2 movlw movwf wrLoop3 SKPNC decfsz goto incf decfsz goto CLK1202 DAT1202 INDF,f DAT1202 CLK1202 kay,f wrLoop3 FSR,f jay,f wrLoop2 ;we're putting bytes data DS1202
;each byte bits
;lower clock ;assume data going ;rotate data from current PIC12C508 location ;skip next really ;not correct ;clock data ;skip next done with current data byte ;keep working getting current data byte ;point destination next data byte ;skip next done getting data bytes ;contine getting next data byte
ifdef _16C84 STATUS,RP0 TRISB,IOPIN STATUS,RP0 else movlw DATAINP tris GPIO endif retlw endif CLK1202 CS1202
;done outputting command DS1202 ;revert data back input ;_12C508 ;revert data back input
;leave clock ;deselect clock chip
;/-\ Routine reading byte data from Dallas 1202 Serial Timekeeping chip. Inputs: adr1202 bitVars RAMNCLK (read from RAM/not clock area DS1202) Outputs: dat1202 Calls: none ;\-/ rd1202 movlw movwf MOVFW movwf btfss CS1202 CLK1202 adr1202 temp temp,f temp,RD1202 temp,7 temp,RAM1202 RAMNCLK ;activate chip selecting ;start with clock ;command DS1202 bits long
;don't destroy DS1202 address ;turn address into valid DS1202 command byte ;set read/not write DS1202 command ;this always valid command ;assume writing area DS1202 ;skip next really writing area
1997 Microchip Technology Inc.
DS40160A/2_015-page 2-13
Electromechanical Switch Replacement
temp,RAM1202 ;really writing clock area DS1202 ifdef _16C84 STATUS,RP0 TRISB,IOPIN STATUS,RP0 else movlw DATAOUT tris GPIO endif r1202lp SKPNC decfsz goto CLK1202 DAT1202 temp,f DAT1202 CLK1202 jay,f r1202lp
;make data output temporarily ;_12C508 ;make data output temporarily
;lower clock ;assume command going ;look actual command ;skip next really ;not correct ;command data gets clocked rising edge ;skip next clocked command bits ;continue clocking command bits
ifdef _16C84 STATUS,RP0 TRISB,IOPIN STATUS,RP0 else movlw DATAINP tris GPIO endif movlw movwf r1202l2 CLRC btfsc SETC decfsz goto retlw CLK1202
;done outputting command DS1202 ;revert data back input ;_12C508 ;revert data back input
;retrieving bits data
;clock data clock falling edge ;assume data going ;skip next actual data ;not correct ;rotate data into current PIC12C508 ;raise clock preparation next ;skip next done retrieving data byte ;keep working getting data byte ;leave clock ;deselect clock chip
DAT1202 dat1202,f CLK1202 jay,f r1202l2 CLK1202 CS1202
;/-\ Routine writing byte data Dallas 1202 Serial Timekeeping chip. Inputs: adr1202 (the address DS1202 write) dat1202 (the data write specified address) bitVars RAMNCLK (write RAM/not clock area DS1202) Outputs: none Calls: none Note: Need write-enable DS1202 before write-protect after
DS40160A/2_015-page 2-14
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
;\-/ ifdef _16C84 wr1202 movlw movwf MOVFW movwf btfss w1202lp SKPNC movlw xorwf SKPZ goto MOVFW movwf w1202ov decfsz goto retlw endif CS1202 CLK1202 adr1202 temp temp,f temp,RD1202 temp,7 temp,RAM1202 RAMNCLK temp,RAM1202 STATUS,RP0 TRISB,IOPIN STATUS,RP0 CLK1202 DAT1202 temp,f DAT1202 CLK1202 jay,w w1202ov dat1202 temp jay,f w1202lp STATUS,RP0 TRISB,IOPIN STATUS,RP0 CLK1202 CS1202 ;activate chip selecting ;start with clock ;command data DS1202 each bits
;don't destroy DS1202 address ;turn address into valid DS1202 command byte ;clear read/not write DS1202 command ;this always valid command ;assume writing area DS1202 ;skip next really writing area ;really writing clock area DS1202
;make data output temporarily
;lower clock ;assume command going ;look actual command ;skip next really ;not correct ;command data gets clocked rising edge ;jay will when we've clocked bits ;skip next done with command ;keep working command bits ;done with command bits, switch data bits
;skip next clocked bits ;continue clocking command bits ;done outputting command DS1202 ;revert data back input
;leave clock ;deselect clock chip
;/-\ Routine converting digit ASCII. Inputs: (the digit (only lower nibble relevant)) Outputs: (the converted ASCII code) Calls: none ;\-/ ifdef _16C84
1997 Microchip Technology Inc.
DS40160A/2_015-page 2-15
Electromechanical Switch Replacement
bcd2asc andlw iorlw return endif h'0f' h'30' ;clear upper nibble ;set bits make valid ASCII code
;_16C84
;/-\ Routine converting 1-byte binary value 2-byte binary-coded decimal value digits) (taken from AN526 "PIC12C508 16C5X/16CXX Math Utility Routines" from Microchip Embedded Control Handbook, page 5-119) Inputs: binary value convert (h'00'-h'63') Outputs: bcdH,bcdL Calls: none ;\-/ bin2bcd clrf movwf gtenth movlw subwf btfss goto movwf incf goto endBcd return bcdH bcdL bcdL,w STATUS,C endBcd bcdL bcdH,f gtenth
;/-\ Routine generating programmable delay (routine written Philip Doucet obtained from Electronics Design August 1994, page 26ES) This "delay" subroutine requires three registers. 16-bit argument dlyH dlyL. Minimum value argument Register dlyTemp needed temporary storage. This routine will delay more instruction cycles. exact accuracy, delay parameter must multiple Inputs: instructions delay dlyL dlyH Outputs: none Calls: none ;\-/ ifdef _16C84 delay movlw subwf SKPC decf CLRC CLRC movf SKPNZ goto movlw movwf goto dlyL,f dlyH,f dlyL,f dlyL,f dlyH,f delay3 dlyTemp delay2 ;nop equalizes timing between paths ;since each dlyH loop needs cycle, times thru inner loop cycles, minus cycle setup, ;add cycle delay ;subtract minimum instructions execute this routine from requested delay ;check borrow decrement high byte there ;divide determine many times execute dlyL loop
;check dlyH skip dlyH loop
delay1
DS40160A/2_015-page 2-16
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
delay2 decfsz goto decfsz goto movf SKPNZ goto decfsz goto return endif ;inner loop dlyH dlyTemp,f delay2 dlyH,f delay1 dlyL,f dlyEnd ;loop dlyL dlyL,f delay4 ;return from subroutine ;_16C84 ;outer loop dlyH
delay3
dlyL skip loop
delay4
dlyEnd
PIC12C508 initialization here, including setting configuring control registers. Timer timer drive application clock ticks second blink LEDs when necessary. ;Clear system interrupt flags, enable interrupts (they disabled reset powerup). Other initialization self-explanatory. initHW ifdef _16C84 clrf clrf MOVFW andlw iorlw movwf movlw movwf else clrf GPIO PORTA PORTB INTCON,GIE EEADR,7 EEADR,6 STATUS,RP0 ;set port output latches known state
;disable interrupt sources ;avoid higher than necessary current drain
;select page (powerup default page
OPTION_REG,NOT_RBPU ;enable weak pullups port OPTION_REG,T0CS ;select external source timer OPTION_REG,T0SE ;select falling edge timer increment OPTION_REG,PSA OPTION_REG,PS2 OPTION_REG,PS1 OPTION_REG,PS0 ;assign prescaler watchdog timer
;1:1 prescale watchdog timer
TRISA b'11100000' PORTAIO;port input/output configuration TRISA (leave most-significant bits alone) PORTBIO TRISB STATUS,RP0 ;port input/output configuration
;set default page back ;_12C508 ;set port output latches known state
1997 Microchip Technology Inc.
DS40160A/2_015-page 2-17
Electromechanical Switch Replacement
movlw option movlw tris endif endHW OPTREG ;disable wake-up, disable pull-ups, w-dog DATAINP GPIO
;gpio port input/output configuration
;Set initial variables define initial conditions here. initSW movlw movwf movwf movlw movwf h'ff' prevDay prevMin CS1202 WPR1202 wp1202 LITESHD LIGHT
;initialize invalid value ;initialize invalid value ;make sure DS1202 deselected ;this variable never changes; needed burst write ;shadow output starts ;make sure light output starts
ifdef _16C84 TXD232 endif endSW
;set RS-232 transmit line marking state
ifdef DEBUG movlw movwf movlw movwf call movlw movwf movlw movwf movlw movwf movlw movwf movlw movwf movlw movwf CTL1202 adr1202 WEN1202 dat1202 RAMNCLK wr1202 h'45' sec1202 h'58' min1202 h'23' hr1202 h'20' day1202 h'11' mon1202 h'1' dow1202 ;hard program DS1202 with instead using PC's parallel port easier debugging
;allow writes DS1202
DS40160A/2_015-page 2-18
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
movlw movwf call movlw movwf movlw movwf call movlw movwf movlw movwf call movlw movwf movlw movwf call movlw movwf movlw movwf call movlw movwf movlw movwf call movlw movwf movlw movwf call movlw movwf movlw movwf call movlw movwf movlw movwf call movlw movwf movlw movwf h'96' yr1202 wrClock adr1202 h'ba' dat1202 RAMNCLK wr1202 adr1202 h'bb' dat1202 RAMNCLK wr1202 adr1202 h'bc' dat1202 RAMNCLK wr1202 adr1202 h'bd' dat1202 RAMNCLK wr1202 adr1202 h'0' dat1202 RAMNCLK wr1202 adr1202 h'1' dat1202 RAMNCLK wr1202 adr1202 h'2' dat1202 RAMNCLK wr1202 adr1202 h'3' dat1202 RAMNCLK wr1202 CTL1202 adr1202 WPR1202 dat1202 ;initialize clock time DS1202
1997 Microchip Technology Inc.
DS40160A/2_015-page 2-19
Electromechanical Switch Replacement
call endif infLoop clrwdt call MOVFW xorwf SKPNZ goto MOVFW movwf rdClock prevMin min1202,w infLoop min1202 prevMin RAMNCLK wr1202 ;disallow writes DS1202 ;DEBUG ;pet keep happy ;get current time info ;retrieve minute data ;compare current minute data ;skip next minute changed ;we're still same minute ;minute changed ;update minute remember next time
ifdef DEBUG MOVFW hr1202 movwf bcdL bcdL,f bcdL,f bcdL,f bcdL,w call bcd2asc call send232 MOVFW hr1202 call bcd2asc call send232 movlw call send232 MOVFW min1202 movwf bcdL bcdL,f bcdL,f bcdL,f bcdL,w call bcd2asc call send232 MOVFW min1202 call bcd2asc call send232 movlw call send232 movlw call send232 endif decf movlw xorwf SKPNZ clrf MOVFW xorwf SKPNZ goto MOVFW movwf movlw movwf dow1202,f dow1202,w dow1202 dow1202 prevDay,w sameDay dow1202 prevDay PREON1 state LITESHD
;output HH:MM RS-232 port
;convert with range ;compare current week with ;skip next ;wrap same ;retrieve week range ;has changed ;skip next
;day changed ;set previous variable same current ;since changed before time ;remember that ;turn output device
DS40160A/2_015-page 2-20
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
rdNxChg MOVFW movwf CLRC CLRC MOVFW addwf movwf call MOVFW movwf andlw call andlw iorwf movwf clrf MOVFW andlw movwf movlw addLoop TSTF SKPNZ goto addwf decf goto addDone MOVFW call andlw iorwf movwf sameDay MOVFW xorlw SKPNZ goto chkTime MOVFW subwf SKPGEZ goto SKPZ goto MOVFW subwf SKPGEZ goto dow1202 temp temp,f temp,f state temp,w adr1202 RAMNCLK rd1202 dat1202 temp temp,f temp,f temp,w b'00011111' bin2bcd bcdH,f bcdH,f bcdH,f bcdH,w b'11110000' bcdL,w chgHrs temp dat1202 b'00000111' addDone temp,f eye,f addLoop temp bin2bcd bcdH,f bcdH,f bcdH,f bcdH,w b'11110000' bcdL,w chgMins state PSTOFF2 infLoop chgHrs hr1202,w updShdw change chgMins min1202,w updShdw ;calculate week ;calculate next output transition time
week state ;store index location read DS1202
;read DS1202 location [day state] ;retrieve HHHHHTTT binary data ;save rotating ;rotate CHHHHHTT ;rotate CCHHHHHT ;rotate CCCHHHHH ;mask 000HHHHH ;convert digits ;rotate digit 000MMMMC ;rotate digit 00MMMMCC ;rotate digit 0MMMMCCC ;rotate digit MMMMCCCC ;mask MMMM0000 ;combine MMMMLLLL hours ;save comparison current hours later ;clear addition accumulator ;retrieve HHHHHTTT binary data ;mask hours 00000TTT number minute blocks ;add accumulated each time thru down yet? ;skip next down have minutes calculated ;sum ;continue adding ;retrieve minutes ;;convert digits ;rotate digit 000MMMMC ;rotate digit 00MMMMCC ;rotate digit 0MMMMCCC ;rotate digit MMMMCCCC ;mask MMMM0000 ;combine MMMMLLLL minutes ;save comparison current minutes later ;retrieve current state current state after time ;skip next ;time after turn time, recycle
current hours next change hours ;skip next current next change update output from shadow ;skip next current equals change toggle shadow output current minutes next change minutes ;skip next current next change update output from shadow
1997 Microchip Technology Inc.
DS40160A/2_015-page 2-21
Electromechanical Switch Replacement
SKPZ goto change btfss goto goto updShdw LITESHD shdwOn LITESHD endChg LITESHD ;skip next current equals next change update output from shadow ;skip next shadow currently ;shadow off, turn ;turn shadow ;done with shadow bit, this section ;turn shadow
shdwOn endChg
incf MOVFW xorlw SKPZ goto
state,f state PSTOFF2 rdNxChg
;advance next state on/off machine
;are after time ;skip next ;haven't turned last time today; need read next time state change ;skip next shadow says output should ;output should make ;turn output ;done with output, this section ;turn output
updShdw btfss goto goto outOff endUpdt goto
LITESHD outOff LIGHT endUpdt LIGHT
infLoop
;repeat nauseum
;/-\ program watchdog fill ;\-/ endProg fill wdReset goto (goto wdReset),(MAXROM MAXROM ;set breakpoints endProg thru wdtRst wdReset ;force watchdog fire
;/-\ assembly ;\-/
DS40160A/2_015-page 2-22
1997 Microchip Technology Inc.
Electromechanical Switch Replacement
NOTES:
1997 Microchip Technology Inc.
DS40160A/2_015-page 2-23
WORLDWIDE SALES SERVICE
AMERICAS
Corporate Office
Microchip Technology Inc. 2355 West Chandler Blvd. Chandler, 85224-6199 Tel: 602-786-7200 Fax: 602-786-7277 Technical Support: 786-7627 Web: http://www.microchip.com
ASIA/PACIFIC
Hong Kong
Microchip Asia Pacific 3801B, Tower Metroplaza Hing Fong Road Kwai Fong, N.T., Hong Kong Tel: 852-2-401-1200 Fax: 852-2-401-3431
EUROPE
United Kingdom
Arizona Microchip Technology Ltd. Unit Courtyard Meadow Bank, Furlong Road Bourne End, Buckinghamshire Tel: 44-1628-851077 Fax: 44-1628-850259
France
Arizona Microchip Technology SARL Zone Industrielle Bonde Buisson Fraises 91300 Massy, France Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79
Atlanta
Microchip Technology Inc. Sugar Mill Road, Suite 200B Atlanta, 30350 Tel: 770-640-0034 Fax: 770-640-0307
India
Microchip Technology Inc. India Liaison Office Legacy, Convent Road Bangalore 025, India Tel: 91-80-229-4036 Fax: 91-80-559-9840
Boston
Microchip Technology Inc. Mount Royal Avenue Marlborough, 01752 Tel: 508-480-9990 Fax: 508-480-8575
Germany
Arizona Microchip Technology GmbH Gustav-Heinemann-Ring D-81739 Germany Tel: 49-89-627-144 Fax: 49-89-627-144-44
Korea
Microchip Technology Korea 168-1, Youngbo Bldg. Floor Samsung-Dong, Kangnam-Ku Seoul, Korea Tel: 82-2-554-7200 Fax: 82-2-558-5934
Chicago
Microchip Technology Inc. Pierce Road, Suite Itasca, 60143 Tel: 630-285-0071 Fax: 630-285-0075
Italy
Arizona Microchip Technology Centro Direzionale Colleoni Palazzo Taurus Colleoni 20041 Agrate Brianza Milan, Italy Tel: 39-39-6899939 Fax: 39-39-6899883
Shanghai
Microchip Technology Shanghai Golden Bridge Bldg. 2077 Yan'an Road West, Hong Qiao District Shanghai, 200335 Tel: 86-21-6275-5700 Fax: 21-6275-5060
Dallas
Microchip Technology Inc. 14651 Dallas Parkway, Suite Dallas, 75240-8809 Tel: 972-991-7177 Fax: 972-991-8588
Singapore
Microchip Technology Taiwan Singapore Branch Middle Road #07-02 Prime Centre Singapore 188980 Tel: 65-334-8870 Fax: 65-334-8850
JAPAN
Microchip Technology Intl. Inc. Benex 3-18-20, Shinyokohama Kohoku-Ku, Yokohama-shi Kanagawa Japan Tel: 81-45-471- 6166 Fax: 81-45-471-6122 8/29/97
Dayton
Microchip Technology Inc. Prestige Place, Suite Miamisburg, 45342 Tel: 937-291-1654 Fax: 937-291-9175
Angeles
Microchip Technology Inc. 18201 Karman, Suite 1090 Irvine, 92612 Tel: 714-263-1888 Fax: 714-263-1338
Taiwan, R.O.C
Microchip Technology Taiwan 10F-1C Tung North Road Taipei, Taiwan, Tel: 2-717-7175 Fax: 886-2-545-0139
York
Microchip Technology Inc. Motor Parkway, Suite Hauppauge, 11788 Tel: 516-273-5305 Fax: 516-273-5335
Jose
Microchip Technology Inc. 2107 North First Street, Suite Jose, 95131 Tel: 408-436-7950 Fax: 408-436-7955
Toronto
Microchip Technology Inc. 5925 Airport Road, Suite Mississauga, Ontario 1W1, Canada Tel: 905-405-6279 Fax: 905-405-6253
rights reserved. 1997, Microchip Technology Incorporated, USA. 9/97
Printed recycled paper.
Information contained this publication regarding device applications like intended suggestion only superseded updates. representation warranty given liability assumed Microchip Technology Incorporated with respect accuracy such information, infringement patents other intellectual property rights arising from such otherwise. Microchip's products critical components life support systems authorized except with express written approval Microchip. licenses conveyed, implicitly otherwise, under intellectual property rights. Microchip logo name registered trademarks Microchip Technology Inc. U.S.A. other countries. rights reserved. other trademarks mentioned herein property their respective companies.
DS40160A/2_015-page 2-24
1997 Microchip Technology Inc.

Other recent searches


WSH136 - WSH136   WSH136 Datasheet
FT1500AU - FT1500AU   FT1500AU Datasheet
TC110 - TC110   TC110 Datasheet
czs-311 - czs-311   czs-311 Datasheet
CZS-311 - CZS-311   CZS-311 Datasheet
AM23SRC-F - AM23SRC-F   AM23SRC-F Datasheet
2SD1619 - 2SD1619   2SD1619 Datasheet

 

Privacy Policy | Disclaimer
© 2012 Datasheet Archive