Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MY_SECOND_TIMER SEGMENT CODE
- CSEG AT 0
- JMP startC
- RSEG MY_SECOND_TIMER
- startA:
- MOV R3, #0h
- MOV R0, #20
- DELAY:
- MOV TMOD,#00000001B // Sets Timer 0 to MODE1 (16 bit timer)
- MOV TH0,#76 // Loads TH0 register with 76
- MOV TL0,#01 // LOads TL0 register with 01
- SETB TR0 // Starts the Timer 0
- HERE:
- JNB TF0,HERE // Loops here until TF0 is set (ie;until roll over)
- CLR TR0 // Stops Timer 0
- CLR TF0 // Clears TF0 flag
- DJNZ R0,DELAY
- INC R3
- MOV P2,R3
- SJMP startA
- //Frequency 11.0592MHz=12 pules
- //1 clock pulse =11.0592MHz/12
- //F =0.921 MHz
- //Time delay=1/F
- //T=1/0.92MHz
- //T=1.080506 us (for ‘1’ cycle)
- //1000us=1MS
- //1000ms=1sec
- // 1 second delay = 1000000/1.080806 ~= 925235 cycles
- // but timer can count 65535 cycles max :(
- // so grab 50ms and iterate it 20 times
- //
- startB:
- MOV R3, #0
- MOV R0, #2
- MOV P2, #00h
- wait:
- MOV A,P1
- CJNE A,#11111110B,wait
- //CJNE - Compare and Jump if not Equal
- //JNZ wait // Loops here until P1.0 is set
- //JZ - Jump if Accumulator Zero
- //JNZ - Jump if Accumulator not Zero
- DELAYB:
- MOV TMOD,#00000001B // Sets Timer 0 to MODE1 (16 bit timer)
- MOV TH0,#76 // Loads TH0 register with 76
- MOV TL0,#01 // LOads TL0 register with 01
- SETB TR0 // Starts the Timer 0
- HEREB:
- JNB TF0,HEREB // Loops here until TF0 is set (ie;until roll over)
- CLR TR0 // Stops Timer 0
- CLR TF0 // Clears TF0 flag
- DJNZ R0,DELAYB
- INC R3
- MOV A,P1
- CJNE A,#11111110B,startB
- // JNZ startB // if button is clicked continue set diod if not, start again
- MOV P2,R3
- SJMP DELAYB
- startC:
- MOV R3, #0
- MOV R0, #2
- MOV P2, #00h
- checkButtonBeforeStart:
- MOV A,P1
- CJNE A,#11111110B,checkButtonBeforeStart
- //CJNE - Compare and Jump if not Equal
- //JNZ wait // Loops here until P1.0 is set
- //JZ - Jump if Accumulator Zero
- //JNZ - Jump if Accumulator not Zero
- DELAYC:
- MOV TMOD,#00001001B // Sets Timer 0 to MODE1 (16 bit timer)
- MOV TH0,#76 // Loads TH0 register with 76
- MOV TL0,#01 // LOads TL0 register with 01
- SETB TR0 // Starts the Timer 0
- HEREC:
- MOV A,P1
- CJNE A,#11111111B,settimeron
- JMP settimeroff
- settimeron:
- MOV P3, #00000100B
- JMP go
- settimeroff:
- MOV P3, #00000000B
- go:
- JNB TF0,HEREC // Loops here until TF0 is set (ie;until roll over)
- CLR TR0 // Stops Timer 0
- CLR TF0 // Clears TF0 flag
- DJNZ R0,DELAYC
- INC R3
- MOV P2, R3
- JMP checkButtonBeforeStart
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement