eleckits
Junior Member
Offline
Posts: 54
Thank You
-Given: 36
-Receive: 18
|
|
« on: April 07, 2009, 11:18:21 11:18 » |
|
I have this code but don't know how to compile it, because I don't know the name of the compiler that was written with, would you please give me the name of this compiler? ;Filename: IRCLD501.SRC
DEVICE PIC16F84,HS_OSC,WDT_OFF,PWRT_ON,PROTECT_OFF ID 'IR51'
LEDDUTY = 8 ;SETS NUMBER OF FAST LOOPS OUT OF 256 THAT LED ; GLOWS AS NIGHTLIGHT. PULSEWIDTH = 1 ;SETS NUMBER OF LOOPS WHICH TRIAC PULSE COVERS BLINKWIDTHL = 12 ;SETS NUMBER OF CYCLES WHICH LED BLINKS COVER BLINKWIDTHS = 1 ;SETS NUMBER OF CYCLES WHICH LED BLINKS COVER ONOFFADR = 0 ;SETS ADDRESS OF ONOFF COMMAND LOCATION IN MEM BRITEADR = 8 ;SETS ADDRESS OF BRITE COMMAND LOCATION IN MEM DIMADR = 16 ;SETS ADDRESS OF DIM COMMAND LOCATION IN MEM PHASEADR = 63 ;SETS ADDRESS OF PHASE VALUE STORED IN MEM LASTONADR = 62 ;SETS ADDRESS OF LAST ON/OFF STATUS IN MEM DEBOUNCE = 20 ;SETS KEY DEBOUNCE TIME LENGTH AUTOSAVE = 100 ;SETS TIME TO WAIT AFTER COMPLETING DIM OR BRITE ; ACTIVITY TO AUTOSAVE PHASEANGLE STOREMAXH = 3 ;SETS MAX TIME TO WAIT FOR INCOMING CODE TO STORE STOREMAXL = 88 ;SETS MAX TIME TO WAIT FOR INCOMING CODE TO STORE ; TIME=(((STOREMAXH-1)*256)+STOREMAXL))/120 ;RAMPRATEF = 3 ;ALLOWS 1 TICK OF PHASEANGLE ADJUST PER ; ; COUNT OF RAMPRATEF HALFCYCLES. ;RAMPRATES = 5 ;ALLOWS 1 TICK OF PHASEANGLE ADJUST PER ; ; COUNT OF RAMPRATES HALFCYCLES. ;RAMPTHRESHOLD = 80 ;SETS PHASEANGLE LEVEL AT WHICH RAMPRATE CHANGES OFF = 184 ;CONSTANT FOR "LAMP OFF" PHASEANGLE
MINTURNON = 150 ;SETS MIN BRIGHTNESS FOR TURN ON MINHOLDTIME = 21 ;SETS MIN PERIOD BETWEEN IR INPUTS TO OCCUR ; BEFORE DECODE REQUIRED AGAIN BITWIDTH = 24 ;24 LOOPS AT 24kHz = 1000us (1760>1000>680) SPACEWIDTH = 100 ;100 LOOPS AT 24kHz = 4166us (4166>3360) ; where 3360= actual space-bitwidth+normal space ; = 3680-1000+680 =
ZDIN = RA.2 SERIN = RB.7 TRIAC = RB.2 SW1 = RB.1 SW2 = RB.4 SW3 = RB.3 SW4 = RB.5 LED = RB.6
BRITE = SW1 ONOFF = SW2 STORE = SW3 DIM = SW4
CLOCKOUT = RA.1 ;PUTS OUT CLOCK = 1/2 LOOP FREQ TIMERVALUE = 207 ;SETS TASK1 LOOP FREQ TO 12kHz;152=12000 ;TIMERVALUE = 255 - ((XTAL/4) / (LOOPFREQ X PRESCALER)) ;208=24000 ; = 255 - (2500000 / (24000 X 2)) ; = 255 - 52.08333333 ; = 202.9166667 ;USING 203: ERROR=0.0410509% ;---------------------------------------------------------------------------- ;EEPROM INITIALIZATION EEORG PHASEADR EEDATA 64H ;initial turn-on value EEORG LASTONADR EEDATA 0H ;CODES FOR RCA CABLE BOX ;(G.E.Universal remote set cable mode to RCA box "047") EEORG ONOFFADR EEDATA 028H,073H,000H,000H,000H,000H,000H,000H EEORG BRITEADR EEDATA 038H,073H,000H,000H,000H,000H,000H,000H EEORG DIMADR EEDATA 018H,073H,000H,000H,000H,000H,000H,000H ;---------------------------------------------------------------------------- ;VARIABLE STORAGE ORG 0CH ;SET TO START OF GENERAL PURPOSE RAM
BITTIMER DS 1 ;COUNTS LOOPS UNTIL TIME TO SAMPLE BIT SPACETIMER DS 1 ;USED TO SET LIMIT TO SPACES BETWEEN SERIAL BITS BITCOUNTER DS 1 ;USED TO COLLECT CORRECT NUMBER OF BITS PHASEANGLE DS 1 ;VALUE SETS THE PHASE ANGLE PHASECOUNTER DS 1 ;COUNTS LOOPS UNTIL = PHASE TO PULSE TRIAC PULSECOUNTER DS 1 ;USED TO END TRIAC PULSE BY COUNTING LOOPS ZEROCOUNTER DS 1 ;COUNTS ZERO DETECTIONS BOUNCECOUNTER DS 1 ;COUNTS ZERO DETECTIONS TO DEBOUNCE KEYS RAMPCOUNTER DS 1 ;COUNTS MULTIPLES OF ZERO DETECTIONS ; TO SET PHASE ANGLE RAMP RATE. KEY1COUNTER DS 1 ;DETECTS ACTION ON DIM & BRIGHT TO TRIGGER ; AUTOMATIC STORAGE OF LAST PHASEANGLE SET BLINKCOUNTER DS 1 ;COUNTS ZERO DETECTIONS TO CONTROL LED ONTIME STORECOUNTERH DS 1 ;USED TO LIMIT HOW LONG SYSTEM WAITS FOR ; A NEW IR CODE TO COME FOR STORAGE STORECOUNTERL DS 1 ;USED TO LIMIT HOW LONG SYSTEM WAITS FOR ; A NEW IR CODE TO COME FOR STORAGE ZDLOG DS 1 ;USED TO RECORD PREVIOUS & PRESENT STATES OF ZDIN SERINLOG DS 1 ;USED TO RECORD PREVIOUS & PRESENT STATES OF SERIN SERDATA0 DS 1 ;BYTE 0 OF 64-BIT SERIAL DATA WORD RECEIVED SERDATA1 DS 1 ;BYTE 1 OF 64-BIT SERIAL DATA WORD RECEIVED SERDATA2 DS 1 ;BYTE 2 OF 64-BIT SERIAL DATA WORD RECEIVED SERDATA3 DS 1 ;BYTE 3 OF 64-BIT SERIAL DATA WORD RECEIVED SERDATA4 DS 1 ;BYTE 4 OF 64-BIT SERIAL DATA WORD RECEIVED SERDATA5 DS 1 ;BYTE 5 OF 64-BIT SERIAL DATA WORD RECEIVED SERDATA6 DS 1 ;BYTE 6 OF 64-BIT SERIAL DATA WORD RECEIVED SERDATA7 DS 1 ;BYTE 7 OF 64-BIT SERIAL DATA WORD RECEIVED MEMDATA0 DS 1 ;BYTE 0 OF STORED 64-BIT DATA WORD MEMDATA1 DS 1 ;BYTE 1 OF STORED 64-BIT DATA WORD MEMDATA2 DS 1 ;BYTE 2 OF STORED 64-BIT DATA WORD MEMDATA3 DS 1 ;BYTE 3 OF STORED 64-BIT DATA WORD MEMDATA4 DS 1 ;BYTE 4 OF STORED 64-BIT DATA WORD MEMDATA5 DS 1 ;BYTE 5 OF STORED 64-BIT DATA WORD MEMDATA6 DS 1 ;BYTE 6 OF STORED 64-BIT DATA WORD MEMDATA7 DS 1 ;BYTE 7 OF STORED 64-BIT DATA WORD STATS DS 1 ;USED TO STORE TEMPORARY PROGRAM STATISTICS STOREHIT = STATS.0 ;IF=1 THEN STORE KEY WAS HIT ONOFFHIT = STATS.1 ;IF=1 THEN ONOFF KEY WAS HIT BRITEHIT = STATS.2 ;IF=1 THEN BRITE KEY WAS HIT DIMHIT = STATS.3 ;IF=1 THEN DIM KEY WAS HIT BUFFERFULL = STATS.4 ;IF=1 THEN 64-BIT WORD IS WAITING TO BE DECODED WORDSTART = STATS.5 ;IF=1 THEN START BIT EDGE DETECTED KEYBOUNCE = STATS.6 ;IF=1 THEN KEY IS IN DEBOUNCE DELAY ZEROHIT = STATS.7 ;IF=1 THEN ZEROPOINT WAS PASSED STATS2 DS 1 ;USED TO STORE TEMPORARY PROGRAM STATISTICS PULSESTART = STATS2.0;SAYS THE TRIAC TRIGGER PULSE IS RUNNING PULSEDONE = STATS2.1;SAYS TRIGGER FOR CYCLE IS COMPLETE LAMPON = STATS2.2;SAYS IF LAMP IS SWITCHED ON BLINK = STATS2.3;SAYS BLINKER ROUTINE IS TO START A LED FLASH ALLOWKEY1 = STATS2.4;SET BY ZD TO CONTROL PHASEANGLE RAMP RATE ALLOWKEY2 = STATS2.5;SET BY ZD TO CONTROL ONOFF & STORE DEBOUNCE BITDONE = STATS2.6;SAYS BIT HAS BEEN CAPTURED STOREMODE = STATS2.7;SAYS STORE MODE IS ENABLED STATS3 DS 1 ;USED TO STORE TEMPORARY PROGRAM STATISTICS ONOFFCODEVALID = STATS3.0;SAYS A VALID ONOFF CODE WAS RECIEVED BRITECODEVALID = STATS3.1;SAYS A VALID BRITE CODE WAS RECEIVED DIMCODEVALID = STATS3.2;SAYS A VALID DIM CODE WAS RECEIVED IRTOGGLEDONE = STATS3.3;SAYS ON/OFF TOGGLE CALLED BY IR CODE IS COMPLETE GLOW = STATS3.4;SAYS LED NIGHTLIGHT GLOWING IS ENABLED DATAADR DS 1 ;VALUES POINT TO BYTE OF EEPROM DATA DATABOX DS 1 ;HOLDS DATA BYTE READ FROM MEM OR ; HOLDS DATA TO WRITE TO MEM. HOLDCOUNTER DS 1 DELAYCOUNTERA DS 1 ;USED ONLY IN DELAYCOUNTER DELAYCOUNTERB DS 1 ;USED ONLY IN DELAYCOUNTER LEDGLOW DS 1 ;USED TO COUNT FAST LOOPS TO CONTROL THE ;BRIGHTNESS OF THE LED'S NIGHTLIGHT GLOW. ;---------------------------------------------------------------------------- ORG 0 ;SET TO START OF GENERAL PURPOSE RAM ;---------------------------------------------------------------------------- ;INITIALIZE VARIABLES INITIALIZE CLR RA ;CLEAR ALL OUTPUTS CLR RB ;MOV ADCON0,#11001000B ;TURN OFF A2D CONVERTER & SET CLKRATE ;& SET TO CHANNEL 1 <0:3> SETB RP0 ;SET RP0 TO UPPER REGISTER BANK ;MOV ADCON1,#00000011B;SET PORT1 INPUTS AS DIGITAL MOV RA,#00000100B ;SET PORT RA DATA DIRECTIONS MOV RB,#10111011B ;SET PORT RB DATA DIRECTIONS CLR OPTION ;SET OPTION REG. RB-PULL-UPS ON ; AND SET PRESCALER TO TIMER ; AND PRESCALER 1:2 CLRB RP0 ;SET RP0 TO LOWER REGISTER ;SETB RTIE ;SET TIMER INTERUPT ENABLE ;CLRB INTF ;CLEAR RB0/INT FLAG ;SETB INTE ;SET RB0/INT ENABLE ;SETB GIE ;SET GLOBAL INTERUPT ENABLE CLR STATS CLR STATS2 CLR STATS3 CLR SERINLOG MOV PHASEANGLE,#OFF MOV DATAADR,#LASTONADR ;READ LAST "ON/OFF" STATUS CALL READDATA TEST DATABOX
;LEAVE LAMP OFF IF LAST STATE WAS "OFF"... JZ :CONTINUE
;TURN LAMP ON TO LAST LEVEL IF LAST STATE WAS "ON"... MOV DATAADR,#PHASEADR ;READ LAST "ON" LEVEL CALL READDATA MOV PHASEANGLE,DATABOX ;LOAD "ON" LEVEL :CONTINUE ;MOV RAMPCOUNTER,#RAMPRATES MOV RAMPCOUNTER,#8 CLR KEY1COUNTER MOV BOUNCECOUNTER,#DEBOUNCE MOV TMR0,#TIMERVALUE;RESET TIMER CLRB T0IF ;CLEAR TIMER OVERFLOW FLAG CALL LEDPLAY ;---------------------------------------------------------------------------- ;MAIN: MAIN PROGRAM LOOP MAIN ;GENERATE 1/2 LOOP FREQ O/P WAVE RUNCLOCK JB CLOCKOUT,CLEARCLOCK SETCLOCK SETB CLOCKOUT JMP MAINA CLEARCLOCK CLRB CLOCKOUT
;DETECT AND READ IR SERIAL I/P MAINA RL SERINLOG AND SERINLOG,#00000010B SNB SERIN SETB SERINLOG.0 JB BUFFERFULL,RECEIVEDONE ;SHOULD NOT NEED THIS LINE CJE SERINLOG,#00000001B,BITBEGIN JB WORDSTART,MAINB JMP RECEIVEDONE
BITBEGIN MOV BITTIMER,#BITWIDTH CLRB BITDONE JB WORDSTART,MAINB WORDBEGIN SETB WORDSTART MOV BITCOUNTER,#17 ;SET NUMBER OF BITS TO RECEIVE JMP RECEIVEDONE
MAINB JB BITDONE,SPACEDOG DJNZ BITTIMER,RECEIVEDONE SETB BITDONE MOV SPACETIMER,#SPACEWIDTH KEEPBIT RL SERDATA0 ;SHIFT ALL BITS UP RL SERDATA1 ;RL SERDATA2 ;RL SERDATA3 ;RL SERDATA4 ;RL SERDATA5 ;RL SERDATA6 ;RL SERDATA7 CLRB SERDATA0.0 SNB SERINLOG.0 ;CHECK STATE OF SERIAL INPUT SETB SERDATA0.0 ;SAVE STATE OF SERIAL INPUT DJNZ BITCOUNTER,RECEIVEDONE SETB BUFFERFULL JMP WORDDONE
;THIS IS A WATCHDOG TIMER FOR SPACES BETWEEN IR SIGNALS. IF SPACE IS TOO BIG, ; THE SCANNING OF IR DATA WILL BE RESET. SPACEDOG DJNZ SPACETIMER,RECEIVEDONE CLR SERDATA0 ;CLEAR BUFFER CLR SERDATA1 CLR SERDATA2 CLR SERDATA3 CLR SERDATA4 CLR SERDATA5 CLR SERDATA6 CLR SERDATA7 WORDDONE CLRB WORDSTART CLRB BITDONE
RECEIVEDONE ;---------------------------------------------------------------------------- ;SCAN FOR PUSHBUTTON KEYPAD I/P AND EXECUTE FUNCTION FOR EACH KEYHIT ; AND ALSO EXECUTE FUNCTIONS FOR WHICH A VALID IR CODE WAS RECEIVED. SCANKEYS JB ONOFFCODEVALID,RUNONOFF JB BRITECODEVALID,RUNBRITE JB DIMCODEVALID,RUNDIM
JNB STORE,RUNSTORE JNB BRITE,RUNBRITE JNB DIM,RUNDIM JB ONOFF,KEYSDONE
RUNONOFF JB IRTOGGLEDONE,KEYSDONE JNB ALLOWKEY2,KEYSDONE CLRB ALLOWKEY2 SNB ONOFFCODEVALID SETB IRTOGGLEDONE SETB BLINK MOV BOUNCECOUNTER,#DEBOUNCE CLR KEY1COUNTER ;PREVENT AUTOSAVE IF THIS TIMER IS RUNNING JNB STOREMODE,:B SETB ONOFFHIT MOV STORECOUNTERH,#STOREMAXH MOV STORECOUNTERL,#STOREMAXL JMP KEYSDONE
:B JB LAMPON,TURNOFF
TURNON ;READ STORED VALUE OF LAST LEVEL MOV DATAADR,#PHASEADR ;READ LAST "ON" LEVEL CALL READDATA MOV PHASEANGLE,DATABOX ;LOAD "ON" LEVEL CJBE PHASEANGLE,#MINTURNON,:B MOV PHASEANGLE,#MINTURNON :B MOV DATAADR,#LASTONADR ;SAVE "ON" STATUS FOR NEXT POWERUP MOV DATABOX,#1 CALL SAVEDATA JMP KEYSDONE ;FINISHED
TURNOFF ;STORE VALUE OF PHASEANGLE FOR RECALL WHEN TURNING BACK ON ;CJBE PHASEANGLE,#MINTURNON,TURNOFFA ;CHECK IF TOO DIM FOR NEXT TURNON ;MOV PHASEANGLE,#MINTURNON ;SET MIN BRIGHTNESS FOR NEXT TURNON TURNOFFA CLRB LAMPON MOV DATAADR,#PHASEADR ;SAVE LEVEL FOR NEXT TURNON MOV DATABOX,PHASEANGLE CALL SAVEDATA MOV PHASEANGLE,#OFF MOV DATAADR,#LASTONADR ;SAVE "OFF" STATUS FOR NEXT POWERUP MOV DATABOX,#0 CALL SAVEDATA JMP KEYSDONE ;FINISHED
RUNSTORE JNB ALLOWKEY2,KEYSDONE CLRB ALLOWKEY2 JNB STOREMODE,SETSTORE
CLRSTORE SETB BLINK MOV BOUNCECOUNTER,#DEBOUNCE CLR STORECOUNTERH CLR STORECOUNTERL CLRB STOREMODE CLRB ONOFFHIT CLRB BRITEHIT CLRB DIMHIT JMP KEYSDONE
SETSTORE SETB BLINK SETB STOREMODE ;INDICATE STORE MODE ENABLED MOV STORECOUNTERH,#STOREMAXH MOV STORECOUNTERL,#STOREMAXL MOV BOUNCECOUNTER,#DEBOUNCE JMP KEYSDONE ;FINISHED
RUNBRITE JNB ALLOWKEY1,KEYSDONE;CHECK IF TIME TO ADJUST PHASEANGLE CLRB ALLOWKEY1 SETB BLINK JNB STOREMODE,:B SETB BRITEHIT MOV STORECOUNTERH,#STOREMAXH MOV STORECOUNTERL,#STOREMAXL JMP KEYSDONE :B MOV KEY1COUNTER,#AUTOSAVE TEST PHASEANGLE ;CHECK IF PHASEANGLE AT LIMIT JZ KEYSDONE DEC PHASEANGLE ;ADJUST PHASEANGLE TO MAKE LAMP BRIGHTER JMP KEYSDONE ;FINISHED
RUNDIM JNB ALLOWKEY1,KEYSDONE;CHECK IF TIME TO ADJUST PHASEANGLE CLRB ALLOWKEY1 SETB BLINK JNB STOREMODE,:B SETB DIMHIT MOV STORECOUNTERH,#STOREMAXH MOV STORECOUNTERL,#STOREMAXL JMP KEYSDONE :B MOV KEY1COUNTER,#AUTOSAVE CJAE PHASEANGLE,#OFF,KEYSDONE;CHECK IF PHASEANGLE AT LIMIT INC PHASEANGLE ;ADJUST PHASEANGLE TO MAKE LAMP BRIGHTER ;JMP KEYSDONE ;FINISHED KEYSDONE ;---------------------------------------------------------------------------- ;SCAN FOR EDGES ON ZD I/P WHICH INDICATE OCCURANCE OF AC POWER ZERO-CROSSINGS ; AND OPERATE SYSTEM COUNTERS THAT ARE SYNCHRONIZED TO ZERO-CROSSINGS. DETECTZERO RL ZDLOG ;SAVE PREVIOUS STATE OF ZDIN IN BIT 1 AND ZDLOG,#00000010B ;GET PRESENT STATE OF ZDIN & MASK SNB ZDIN SETB ZDLOG.0 CJE ZDLOG,#3,DETECTZERODONE ;NO EDGE ON ZDIN FOR THIS VALUE CJE ZDLOG,#0,DETECTZERODONE ;NO EDGE ON ZDIN FOR THIS VALUE ;SETB ZEROHIT INC ZEROCOUNTER MOV PHASECOUNTER,PHASEANGLE ;RESET PHASE COUNTER CLRB TRIAC ;TURN OFF TRIAC TRIGGER OUTPUT CLRB PULSEDONE
;THIS COUNTER SETS DURATION OF LED BLINKS TO MULTIPLES OF ZERO-CROSSINGS. TEST BLINKCOUNTER SZ DEC BLINKCOUNTER
;THIS COUNTER CONTROLS THE RATE AT WHICH BRITE & DIM RAMP UP OR DOWN. ; THIS COUNTER IS ALSO A DEBOUNCE TIMER FOR THE DIM & BRITE KEYS. ;THE RAMP RATE IS ALSO DECREASED AS THE PHASEANGLE INCREASES TO PROVIDE ; BETTER CONTROL OF DIMMER SETTINGS. DJNZ RAMPCOUNTER,:B SETB ALLOWKEY1
;NOTE: UNCOMMENT ONLY RAMPRATE ROUTINE #1, #2, OR #3
;RAMPRATE ADJUST ROUTINE #1 ;MOV RAMPCOUNTER,#RAMPRATEF ;SET TO SLOW RAMPRATE ;CJB PHASEANGLE,#RAMPTHRESHOLD,:B ;TEST FOR WHICH RAMPRATE ;MOV RAMPCOUNTER,#RAMPRATES ;SET TO FAST RAMP RATE
;RAMPRATE ADJUST ROUTINE #2 ;MOV RAMPCOUNTER,PHASEANGLE ;CALC RAMPRATE AS ;RR RAMPCOUNTER ; FUNCTION OF PHASEANGLE ;RR RAMPCOUNTER ;DIVIDE VALUE BY 16 ;RR RAMPCOUNTER ;RR RAMPCOUNTER ;AND RAMPCOUNTER,#00001111B ;TEST RAMPCOUNTER ;CHECK FOR 0 ;JNZ :B ;MOV RAMPCOUNTER,#2 ;LIMIT MIN RAMPRATE
;RAMPRATE ADJUST ROUTINE #3 MOV RAMPCOUNTER,#7 ;SET MAX RAMPRATE CJAE PHASEANGLE,#112,:B ;CHECK PHASEANGLE RANGE DEC RAMPCOUNTER ; AND ADJUST RAMPRATE CJAE PHASEANGLE,#80,:B DEC RAMPCOUNTER CJAE PHASEANGLE,#48,:B DEC RAMPCOUNTER
;THIS COUNTER IS THE DEBOUNCE TIMER FOR THE STORE & ONOFF KEYS. ; THIS COUNTER LIMITS ACTION OF THESE KEYS TO 1 TOGGLE PER KEY-PRESS. :B ;JNB STORE,DETECTZERODONE ;JNB ONOFF,DETECTZERODONE
JNB ONOFF,:C ;CHECK IF ONOFF KEY IS PRESSED JNB STORE,:C ;CHECK IF STORE KEY IS PRESSED JMP :H :C MOV BOUNCECOUNTER,#DEBOUNCE ;RESTART COUNTER IF KEY IS PRESSED
:H TEST BOUNCECOUNTER JZ :D DJNZ BOUNCECOUNTER,:D SETB ALLOWKEY2 ;ENABLE ONOFF KEY
;THIS COUNTER SAVES PHASEANGLE TO EEPROM FOR NEXT POWERUP AFTER BRITE OR ; DIM FUNCTIONS WERE USED. THIS TIMER PREVENTS PHASEANGLE DATA FROM BEING ; WRITTEN TO THE EEPROM REPEATEDLY DURING THE ACTUAL USE OF BRITE OR DIM. :D TEST KEY1COUNTER ;CHECK IF TIME TO SAVE PHASEANGLE JZ :F DJNZ KEY1COUNTER,:F MOV DATAADR,#LASTONADR CALL READDATA CJB PHASEANGLE,#OFF,:G ;IS LAMP ON OR OFF?
TEST DATABOX JZ :E ;DON'T SAVE LASTON STATUS IN NVRAM IF ALREADY CLR ;MOV DATAADR,#LASTONADR MOV DATABOX,#0 CALL SAVEDATA ;SAVE "OFF" STATUS FOR NEXT POWERUP JMP :E
:G TEST DATABOX JNZ :E ;DON'T SAVE LASTON STATUS IN NVRAM IF ALREADY SET ;MOV DATAADR,#LASTONADR MOV DATABOX,#1 CALL SAVEDATA ;SAVE "ON" STATUS FOR NEXT POWERUP
:E MOV DATAADR,#PHASEADR MOV DATABOX,PHASEANGLE CALL SAVEDATA ;SAVE PHASEANGLE FOR NEXT TURNON
;THIS COUNTER LIMITS HOW LONG SYSTEM WILL REMAIN IN STORE MODE :F JNB STOREMODE,:I DJNZ STORECOUNTERL,:I DJNZ STORECOUNTERH,:I CLRB STOREMODE SETB BLINK
;THIS COUNTER RESETS CODEVALID FLAGS IF NO IR SIGNALS ARE RECEIVED WITHIN ; A CERTAIN AMOUNT OF TIME. :I TEST HOLDCOUNTER JZ DETECTZERODONE DJNZ HOLDCOUNTER,DETECTZERODONE CLRB ONOFFCODEVALID CLRB BRITECODEVALID CLRB DIMCODEVALID CLRB IRTOGGLEDONE DETECTZERODONE ;---------------------------------------------------------------------------- ;DECODE RECEIVED IR CODES AND ENABLE FUNCTION IF VALID CODE DETECTED. ; ALSO STORE NEW IR CODES IF SYSTEM IS IN "STORE" MODE. DECODESERIN JNB BUFFERFULL,DECODEDONE SETB BLINK CLRB BUFFERFULL JNB STOREMODE,DECODE JB ONOFFHIT,STOREONOFF JB BRITEHIT,STOREBRITE JB DIMHIT,STOREDIM JMP DECODEDONE
STOREONOFF CLRB ONOFFHIT CLRB STOREMODE CLR STORECOUNTERH CLR STORECOUNTERL MOV DATAADR,#ONOFFADR CALL SAVECODE JMP DECODEDONE
STOREBRITE CLRB BRITEHIT CLRB STOREMODE CLR STORECOUNTERH CLR STORECOUNTERL MOV DATAADR,#BRITEADR CALL SAVECODE JMP DECODEDONE
STOREDIM CLRB DIMHIT CLRB STOREMODE CLR STORECOUNTERH CLR STORECOUNTERL MOV DATAADR,#DIMADR CALL SAVECODE JMP DECODEDONE
DECODE CHECKONOFF JB ONOFFCODEVALID,GOONOFF MOV DATAADR,#ONOFFADR CALL READCODE CJNE SERDATA0,MEMDATA0,CHECKBRITE CJNE SERDATA1,MEMDATA1,CHECKBRITE ;CJNE SERDATA2,MEMDATA2,CHECKBRITE ;CJNE SERDATA3,MEMDATA3,CHECKBRITE ;CJNE SERDATA4,MEMDATA4,CHECKBRITE ;CJNE SERDATA5,MEMDATA5,CHECKBRITE ;CJNE SERDATA6,MEMDATA6,CHECKBRITE ;CJNE SERDATA7,MEMDATA7,CHECKBRITE SETB ONOFFCODEVALID GOONOFF MOV HOLDCOUNTER,#MINHOLDTIME JMP DECODEDONE
CHECKBRITE JB BRITECODEVALID,GOBRITE MOV DATAADR,#BRITEADR CALL READCODE CJNE SERDATA0,MEMDATA0,CHECKDIM CJNE SERDATA1,MEMDATA1,CHECKDIM ;CJNE SERDATA2,MEMDATA2,CHECKDIM ;CJNE SERDATA3,MEMDATA3,CHECKDIM ;CJNE SERDATA4,MEMDATA4,CHECKDIM ;CJNE SERDATA5,MEMDATA5,CHECKDIM ;CJNE SERDATA6,MEMDATA6,CHECKDIM ;CJNE SERDATA7,MEMDATA7,CHECKDIM SETB BRITECODEVALID GOBRITE MOV HOLDCOUNTER,#MINHOLDTIME JMP DECODEDONE
CHECKDIM JB DIMCODEVALID,GODIM MOV DATAADR,#DIMADR CALL READCODE CJNE SERDATA0,MEMDATA0,DECODEDONE CJNE SERDATA1,MEMDATA1,DECODEDONE ;CJNE SERDATA2,MEMDATA2,DECODEDONE ;CJNE SERDATA3,MEMDATA3,DECODEDONE ;CJNE SERDATA4,MEMDATA4,DECODEDONE ;CJNE SERDATA5,MEMDATA5,DECODEDONE ;CJNE SERDATA6,MEMDATA6,DECODEDONE ;CJNE SERDATA7,MEMDATA7,DECODEDONE SETB DIMCODEVALID GODIM MOV HOLDCOUNTER,#MINHOLDTIME JMP DECODEDONE DECODEDONE ;---------------------------------------------------------------------------- ;UPDATE LED STATUS RUNLED JB BLINK,STARTBLINK ;CHECK IF BLINK SHOULD BEGIN JNB GLOW,RUNBLINK ;CHECK IF NIGHTLIGHT IS ON
NIGHTLIGHT DEC LEDGLOW CJA LEDGLOW,#LEDDUTY,:B :A SETB LED JMP RUNLEDDONE :B CLRB LED JMP RUNLEDDONE
STARTBLINK CLRB BLINK ;INIT BLINK TIMER AND TURN LED ON CLRB GLOW SETB LED MOV BLINKCOUNTER,#BLINKWIDTHL ;INIT FOR LONG BLINK JB ONOFFCODEVALID,RUNLEDDONE ;TEST IF CODE VALID JB BRITECODEVALID,RUNLEDDONE JB DIMCODEVALID,RUNLEDDONE JNB DIM,RUNLEDDONE JNB BRITE,RUNLEDDONE JNB ONOFF,RUNLEDDONE JNB STORE,RUNLEDDONE MOV BLINKCOUNTER,#BLINKWIDTHS ;INIT FOR SHORT BLINK JMP RUNLEDDONE
RUNBLINK TEST BLINKCOUNTER ;CHECK IF TIME TO TURN LED OFF JNZ RUNLEDDONE CLRB LED SETB GLOW RUNLEDDONE ;---------------------------------------------------------------------------- ;PRODUCE TRIGGER PULSES FOR TRIAC DRIVING AC LOAD RUNTRIAC JB PULSEDONE,RUNTRIACDONE CJE PHASEANGLE,#OFF,RUNTRIACDONE ;VALUE MEANS LAMP OFF JNB PULSESTART,RUNCOUNTER RUNPULSE DJNZ PULSECOUNTER,RUNTRIACDONE CLRB TRIAC CLRB PULSESTART SETB PULSEDONE JMP RUNTRIACDONE RUNCOUNTER TEST PHASECOUNTER JZ RUNTRIGGER DEC PHASECOUNTER JMP RUNTRIACDONE RUNTRIGGER SETB TRIAC SETB LAMPON SETB PULSESTART MOV PULSECOUNTER,#PULSEWIDTH RUNTRIACDONE ;---------------------------------------------------------------------------- ;REGULATE PROGRAM MAIN LOOP FREQUENCY WAITER JB T0IF,:DONE ;WAIT UNTIL TIMER OVERFLOWS JB T0IF,:DONE ;THIS METHOD INCREASES THE ACCURACY JB T0IF,:DONE ;WITH WHICH THE TIMER OVERFLOW JB T0IF,:DONE ;IS DETECTED. JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JB T0IF,:DONE JMP WAITER ;JNB T0IF,$ ;USUAL TIMER CHECK METHOD USES ; ONLY THIS LINE BUT IS SLIGHTLY ; LESS ACCURATE. :DONE MOV TMR0,#TIMERVALUE CLRB T0IF JMP MAIN ;---------------------------------------------------------------------------- ;SUBROUTINES FOLLOW ;---------------------------------------------------------------------------- ;READDATA:READS DATA BYTE FROM EEPROM READDATA MOV EEADR,DATAADR ;LOAD ADDRESS OF DATA TO READ SETB RP0 SETB RD ;START READ CYCLE CLRB RP0 MOV DATABOX,EEDATA ;READ DATA RET ;---------------------------------------------------------------------------- ;SAVEDATA:SAVES DATA BYTE TO EEPROM (TAKES ABOUT 10ms TO COMPLETE AFTER ; THIS ROUTINE RUNS. CAN CHECK WR BIT TO SEE IF DONE) SAVEDATA SETB RP0 JB WR,$ ;WAIT IF EEPROM IS BUSY CLRB RP0 MOV EEADR,DATAADR ;LOAD ADDRESS OF LOCATION TO SAVE TO MOV EEDATA,DATABOX ;LOAD DATA TO SAVE SETB RP0 SETB WREN ;SET WRITE ENABLE BIT MOV EECON2,#055H ;WRITE SPECIAL BYTE #1 MOV EECON2,#0AAH ;WRITE SPECIAL BYTE #2 SETB WR ;START WRITE CYCLE CLRB WREN ;CLR WRITE ENABLE BIT CLRB RP0 RET ;---------------------------------------------------------------------------- ;LEDPLAY:BLINK LED FOR BILL'S FUN AND AMUSEMENT! (INDICATES MICRO IS RUNNING) LEDPLAY MOV BLINKCOUNTER,#10 :LOOP SETB LED CALL DELAY50MS CLRB LED CALL DELAY50MS DJNZ BLINKCOUNTER,:LOOP SETB GLOW RET ;---------------------------------------------------------------------------- ;DELAY50MS: TIME DELAY OF 50ms WITH 10MHz CLOCK DELAY50MS MOV DELAYCOUNTERB,#163 MOV DELAYCOUNTERA,#84 :LOOP DJNZ DELAYCOUNTERA,$ DJNZ DELAYCOUNTERB,:LOOP RET ;---------------------------------------------------------------------------- ;SAVECODE:SAVES UP TO 8 BYTES OF COMMAND CODE FROM RAM TO EEPROM SAVECODE MOV DATABOX,SERDATA0 CALL SAVEDATA INC DATAADR MOV DATABOX,SERDATA1 CALL SAVEDATA ;INC DATAADR ;MOV DATABOX,SERDATA2 ;CALL SAVEDATA ;INC DATAADR ;MOV DATABOX,SERDATA3 ;CALL SAVEDATA ;INC DATAADR ;MOV DATABOX,SERDATA4 ;CALL SAVEDATA ;INC DATAADR ;MOV DATABOX,SERDATA5 ;CALL SAVEDATA ;INC DATAADR ;MOV DATABOX,SERDATA6 ;CALL SAVEDATA ;INC DATAADR ;MOV DATABOX,SERDATA7 ;CALL SAVEDATA RET ;---------------------------------------------------------------------------- ;READCODE:READS UP TO 8 BYTES OF COMMAND CODE FROM EEPROM TO RAM READCODE CALL READDATA MOV MEMDATA0,DATABOX INC DATAADR CALL READDATA MOV MEMDATA1,DATABOX ;INC DATAADR ;CALL READDATA ;MOV MEMDATA2,DATABOX ;INC DATAADR ;CALL READDATA ;MOV MEMDATA3,DATABOX ;INC DATAADR ;CALL READDATA ;MOV MEMDATA4,DATABOX ;INC DATAADR ;CALL READDATA ;MOV MEMDATA5,DATABOX ;INC DATAADR ;CALL READDATA ;MOV MEMDATA6,DATABOX ;INC DATAADR ;CALL READDATA ;MOV MEMDATA7,DATABOX RET ;----------------------------------------------------------------------------
Edit: if you need to post code the use the code function
|