cpu 8051 include "f:\as\stddef51.inc" ; *********************************************************************** ; Constants ; *********************************************************************** Reset_Adr EQU 0000H ; Programstart after reset INT_T0_Adr EQU 000BH ; Timer0-jumpaddress MainProg_Adr EQU 0073H ; Startingaddress for mainprogram Data_Adr EQU 040H ; Startingaddress for the datamemory LED_out EQU P1.2 ; Clear to switch led on P_out1 EQU P1.3 ; Clear to switch trafo1 on P_out2 EQU P1.4 ; Clear to switch trafo2 on RE1 EQU P1.5 ; Clear to switch relay1 on RE2 EQU P1.6 ; Clear to switch relay2 on RE3 EQU P1.7 ; Clear to switch relay3 on Button EQU P3.2 ; Buttoninput Jumper EQU P3.7 ; Jumperinput ; *********************************************************************** ; Variables ; *********************************************************************** SEGMENT Data ORG Data_Adr Wait_ctr DB ? ; Counter for the wait-routine LED_ctr DB ? ; Counter for the LED-blinking ; *********************************************************************** ; Flags ; *********************************************************************** SEGMENT bitdata Wait DB ? ; Set, when in waitroutine Buttonpressed DB ? ; Set, when the button was pressed Key DB ? ; Set, when the button was pressed LED DB ? ; Set, when the led should blink LED_ON DB ? ; Set, when the led is actually on ; *********************************************************************** ; Macros ; *********************************************************************** ; *********************************************************************** ; Programstart ; *********************************************************************** segment code ORG Reset_Adr ; Startingaddress LJMP Start ; Jump to powerup ORG INT_T0_Adr ; Timer0-interrupt-address LJMP INT_T0 ; Jump to timer0-interruptroutine ; *********************************************************************** ; Powerup ; *********************************************************************** ORG MainProg_Adr Start MOV SP,#50H ; Move stackpointer SETB LED ; LED-blinking on SETB Re1 ; Re1 off SETB Re2 ; Re2 off CLR Buttonpressed ; Button was not pressed CLR Key ; Button was not pressed MOV TMOD,#01H ; Timer0 in 65536us-timer MOV TCON,#010H ; Start timer0 MOV IE,#082H ; Timer0-interrupt MOV LED_ctr,#20 ; Initialize counter JB Jumper,P_on ; If jumper is set, the switch power on ; *********************************************************************** ; Mainprogram ; *********************************************************************** Main JNB Buttonpressed,Main; Wait until Button is pressed CLR Buttonpressed ; Clear Flag JB LED,P_on ; If led is on, the switch power on SETB LED ; Blinking led on SETB RE3 ; Short audio-inputs CLR RE1 ; Switch relay1 on CLR RE2 ; Switch relay2 on SETB P_out1 ; Switch trafo1 off SETB P_out2 ; Switch trafo2 off MOV Wait_ctr,#20 ; Wait approx 1s LCALL Wait_routine ; Wait SETB RE1 ; Switch relay1 off SETB RE2 ; Switch relay2 off SJMP Main P_on CLR LED ; Blinking led off SETB LED_out ; Switch led off CLR RE3 ; Clear audio-inputs CLR RE1 ; Switch relay1 on CLR RE2 ; Switch relay2 on CLR P_out1 ; Switch trafo1 off MOV Wait_ctr,#10 ; Wait approx 0,5s LCALL Wait_routine ; Wait CLR P_out2 ; Switch trafo2 off MOV Wait_ctr,#10 ; Wait approx 0,5s LCALL Wait_routine ; Wait SETB RE1 ; Switch relay1 off SETB RE2 ; Switch relay2 off SJMP Main ; *********************************************************************** ; Waitroutine ; *********************************************************************** Wait_routine SETB Wait ; Enter waitmode MOV A,Wait_ctr ; Copy countervalue JNZ Wait_routine ; If cntr=0 then continue CLR Wait ; Exit waitmode RET ; *********************************************************************** ; Interruptroutine fuer Timer0 ; *********************************************************************** INT_T0 PUSH ACC ; Save ACC JNB Wait,Cont1 ; If not in Waitmode, then continue DEC Wait_ctr ; Decrement waitcounter Cont1 JNB LED,Cont2 ; If not Power off, then continue MOV A,LED_ctr ; Load countervalue JNZ LED1 ; If counter is not 0, then jump JNB LED_on,LED2 ; If LED is on, then jump to LED2 SETB LED_out ; Switch led off CLR LED_on ; Clear led-flag MOV LED_ctr,#20 ; Set counter to startvalue SJMP Cont2 ; Exit LED2 CLR LED_out ; Switch led on SETB LED_on ; Set led-flag SJMP Cont2 ; Exit LED1 DEC LED_ctr ; decrement LED-counter Cont2 JNB Button,Cont3 ; Exit, when button is not pressed JB Key,T0_End ; Exit, when Button is still pressed SETB Buttonpressed ; Set flag SETB Key ; Set Flag SJMP T0_End ; Exit Cont3 CLR Key ; Button is no longer pressed T0_End POP ACC ; Restore ACC RETI