User:Microtony/asdf


 * ELEC254 Fall 2009
 * Group 9
 * tm_cks tm_clh tm_wmh
 * Version 2009-11-30

BUZZER     EQU P3.2 INPUT		EQU	P3.7	; INPUT Port MODE		EQU	P3.5	; Serial input mode ACLK		EQU	P3.6	; ADC Serial input Clock ADR		EQU	P3.3	; RS pin ADW		EQU	P3.4	; WR pin

CLK		EQU	P2.0	; LCD Serial output Clock RS     	EQU	P2.1	; RS Pin RW     	EQU	P2.2	; RW Pin EN    		EQU	P2.3	; Enable Pin OUTPUT 		EQU	P2.4	; Output Port

MEM_DJ		EQU	R0 MEM_SER 	EQU	R3 MEM_SWS 	EQU	R4 MEM_SWV		EQU	R5 MEM_CNT		EQU	R6 MEM_ADC		EQU	R7

STARTUP 	EQU	20H CNT    	EQU	30H OFFSET 	EQU	31H CURPOS 	EQU	32H KEYIN  	EQU	33H

STMP1		EQU	6DH STMP2		EQU	6EH STMP3		EQU	6FH

TEMP		EQU	70H

SHOUROFF	EQU	71H SMINOFF		EQU 	72H SHOURON		EQU	73H SMINON		EQU	74H SON		EQU	75H SOFF		EQU	76H MENU_MODE	EQU	77H SCH_OPTION	EQU	78H AIRCON		EQU	79H UA_READ 	EQU	7AH HOUR		EQU	7BH MIN		EQU	7CH SEC		EQU	7DH MS50		EQU	7EH US250		EQU	7FH

ORG    00H LJMP   MAIN
 * - PROGRAM START -

ORG 	0BH LJMP	TIMER_INT

ORG    23H RETI


 * MAIN PROGRAM ;
 * MAIN PROGRAM ;
 * MAIN PROGRAM ;

MAIN: MOV    SP, #5FH MOV	MEM_SER, #20H MOV	MEM_ADC, #60 MOV	MEM_CNT, #60 MOV	MEM_SWV,#00H MOV	UA_READ, #0

MOV	AIRCON, #0 JNB	P1.4, MAIN_CONT MOV	AIRCON, #1 MAIN_CONT: MOV 	IE, #10010010B	;SET INTERRUPT MOV	TMOD, #20H	;SET TIMER1 MOV	TH1, #243	;SET PRELOAD VALUE SETB	TR1		;SET TIMER 1 ON MOV	SCON, #50H	;SET SERIAL PORT MODE 1 MOV	PCON, #80H	;SET SMOD

ANL	TMOD, #11110010B ORL	TMOD, #00000010B MOV	TH0, #01H MOV	TL0, #06H MOV	HOUR, #0 MOV	MIN, #0 MOV	SEC, #0 MOV	SHOURON, #0 MOV	SMINON, #0 MOV	SHOUROFF, #0 MOV	SMINOFF, #0 MOV	SON, #0 MOV	SOFF, #0 MOV	US250, #0 MOV	MS50, #0 MOV	SCH_OPTION, #0 MOV	MENU_MODE, #0 MOV	STMP1, #0 MOV	STMP2, #0 MOV	STMP3, #0 MOV	P1, #0 SETB	TR0 CLR    BUZZER LCALL  	LCD_INIT	; Subroutine for LCD INITIZATION LCALL		AD

JMP	$
 * LCD FUNCTIONS ;
 * LCD FUNCTIONS ;
 * LCD FUNCTIONS ;

LCD_INIT: MOV    A, #00111000B           ; SET FUNCTION 8 BIT 2 LINE 5*8 LCALL  W_INS MOV    A, #00111000B           ; SET FUNCTION 8 BIT 2 LINE 5*8 LCALL  W_INS MOV    A, #00111000B           ; SET FUNCTION 8 BIT 2 LINE 5*8 LCALL  W_INS MOV    A, #00111000B           ; SET FUNCTION 8 BIT 2 LINE 5*8 LCALL  W_INS MOV    A, #00001000B           ; DISPLAY OFF LCALL  W_INS MOV    A, #00000001B           ; CLEAR DISPLAY LCALL  W_INS MOV    A, #00000110B           ; SET ENTRY MODE LCALL  W_INS MOV    A, #00001111B           ; DISPLAY ON, CURSOR ON, BLINKING LCALL  W_INS RET

W_TEMP: MOV	B, #2 SUBB   A, #16 DIV	AB MOV	R0, B LCALL	W_D2 MOV	A, #00101110B LCALL	W_DATA MOV	A, R0 MOV	B, #5 MUL	AB ORL	A, #00110000B LCALL	W_DATA RET
 * BASIC LCD FUNCTIONS ;
 * BASIC LCD FUNCTIONS ;
 * BASIC LCD FUNCTIONS ;

W_INS: CLR    EN CLR     RS CLR     RW SETB    EN LCALL	LCD_SERIAL_OUT CLR    EN RET
 * LCALL  W_CHECK

W_STR: MOV    OFFSET, #0 W_STRN: MOV    A, OFFSET MOVC   A, @A+DPTR LCALL  W_DATA INC    OFFSET DJNZ   R0, W_STRN RET

W_DATA: CLR    EN SETB    RS CLR     RW SETB    EN LCALL	LCD_SERIAL_OUT CLR    EN RET
 * LCALL  ;W_CHECK

W_CHECK: BUSY: CLR    RS

SETB   RW SETB    EN SETB    P2.2 CLR    EN JB      P2.2, BUSY RET

W_D2: MOV	B, #10 DIV	AB ADD	A,#30H LCALL  W_DATA MOV	A, B ADD	A,#30H LCALL  W_DATA RET W_NULL: MOV	R0, A MOV	DPTR, #NULL LCALL	W_STR RET


 * SERIAL OUT FOR LCD ;
 * SERIAL OUT FOR LCD ;
 * SERIAL OUT FOR LCD ;

LCD_SERIAL_OUT: CLR CLK

SERIAL_OUT: RLC A MOV OUTPUT,C NOP SETB CLK NOP CLR CLK

RLC A MOV OUTPUT,C NOP SETB CLK NOP CLR CLK RLC A MOV OUTPUT,C NOP SETB CLK NOP CLR CLK RLC A MOV OUTPUT,C NOP SETB CLK NOP CLR CLK RLC A MOV OUTPUT,C NOP SETB CLK NOP CLR CLK RLC A MOV OUTPUT,C NOP SETB CLK NOP CLR CLK RLC A MOV OUTPUT,C NOP SETB CLK NOP CLR CLK RLC A MOV OUTPUT,C NOP SETB CLK NOP CLR CLK

RET

SW: SWMENU: MOV 	A, P0 ANL	A, #00100000B JZ	MENU_SELECT MOV	A, MEM_SWS JNZ	MENU_SELECT XRL	MENU_MODE, #1 MENU_SELECT: MOV	A, MENU_MODE JNZ	MENU_SCHEDULE SWAUTO: MOV 	A, P0 ANL	A, #00000001B JZ	SWMOFF MOV	A, MEM_SWS JNZ	SWEND MOV	MEM_SWV, #0 SWMOFF: MOV 	A, P0 ANL	A, #00000010B JZ	SWMON MOV	A, MEM_SWS JNZ	SWEND MOV	MEM_SWV, #1 SWMON: MOV 	A, P0 ANL	A, #00000100B JZ	SWINC MOV	A, MEM_SWS JNZ	SWEND MOV	MEM_SWV, #3 SWINC: MOV 	A, P0 ANL	A, #00001000B JZ	SWDEC MOV	A, MEM_SWS JNZ	SWEND INC	MEM_CNT SWDEC: MOV 	A, P0 ANL	A, #00010000B JZ	SWEND MOV	A,MEM_SWS JNZ	SWEND DEC	MEM_CNT SWEND: MOV	A, P0 ANL	A, #00111111B MOV	MEM_SWS, A RET
 * SWITCH FUNCTIONS ;
 * SWITCH FUNCTIONS ;
 * SWITCH FUNCTIONS ;

MENU_SCHEDULE: SWSOPT: MOV 	A, P0 ANL	A, #00000001B JZ	SWON MOV	A, MEM_SWS JNZ	TO_SWSEND XRL	SCH_OPTION, #1 JMP	SWON TO_SWSEND: JMP	SWSEND SWON: MOV 	A, P0 ANL	A, #00000010B JZ	SWOFF MOV	A, MEM_SWS JNZ	SWSEND MOV	A, SCH_OPTION JZ	SWON_UPPER MOV	SOFF, #1 JMP	SWOFF SWON_UPPER: MOV	SON, #1 SWOFF: MOV 	A, P0 ANL	A, #00000100B JZ	SWMIN MOV	A, MEM_SWS JNZ	SWSEND MOV	A, SCH_OPTION JZ	SWOFF_UPPER MOV	SOFF, #0 JMP	SWMIN SWOFF_UPPER: MOV	SON, #0 SWMIN: MOV 	A, P0 ANL	A, #00001000B JZ	SWHOUR MOV	A, MEM_SWS JNZ	SWSEND MOV	A, SCH_OPTION JZ	SWMIN_UPPER INC	SMINOFF INC	SMINOFF INC	SMINOFF INC	SMINOFF INC	SMINOFF MOV	A, #60 CJNE	A, SMINOFF, SWHOUR MOV	SMINOFF, #0 JMP	SWHOUR SWMIN_UPPER: INC	SMINON INC	SMINON INC	SMINON INC	SMINON INC	SMINON MOV	A, #60 CJNE	A, SMINON, SWHOUR MOV	SMINON, #0 SWHOUR: MOV 	A, P0 ANL	A, #00010000B JZ	SWSEND MOV	A,MEM_SWS JNZ	SWSEND MOV	A, SCH_OPTION JZ	SWHOUR_UPPER INC	SHOUROFF MOV	A, #24 CJNE	A, SHOUROFF, SWSEND MOV	SHOUROFF, #0 JMP	SWSEND SWHOUR_UPPER: INC	SHOURON MOV	A, #24 CJNE	A, SHOURON, SWSEND MOV	SHOURON, #0 SWSEND: MOV	A, P0 ANL	A, #00111111B MOV	MEM_SWS, A

RET

AD: SETB	ADR SETB	ADW CLR	ADW SETB	ADW MOV	MEM_DJ, #200
 * ADC FUNCTIONS ;
 * ADC FUNCTIONS ;
 * ADC FUNCTIONS ;

ADWAIT: DJNZ	MEM_DJ, ADWAIT

CLR	ADR NOP NOP

CLR	ACLK

SETB	MODE SETB	ACLK CLR	ACLK CLR 	MODE

MOV	C,INPUT RLC	A

SETB	ACLK CLR	ACLK MOV	C,INPUT RLC	A

SETB	ACLK CLR	ACLK MOV	C,INPUT RLC	A

SETB	ACLK CLR	ACLK MOV	C,INPUT RLC	A

SETB	ACLK CLR	ACLK MOV	C,INPUT RLC	A

SETB	ACLK CLR	ACLK MOV	C,INPUT RLC	A

SETB	ACLK CLR	ACLK MOV	C,INPUT RLC	A

SETB	ACLK CLR	ACLK MOV	C,INPUT RLC	A

MOV	MEM_ADC,A RET

TIMER_INT: MOV	TEMP, A INC	US250 MOV	A, #187 CJNE 	A, US250, TIMER_EXIT MOV	US250, #0 INC	MS50 MOV	A, #20 CJNE	A, MS50, SHOW_OUTPUT LCALL AIRCON_STATE LCALL	TX MOV	MS50, #0 INC	SEC MOV	A, SEC MOV	B, #5 DIV	AB MOV	A, B JNZ	END_ADC_COUNT LCALL	AD END_ADC_COUNT: MOV	A, #60 CJNE	A, SEC, SHOW_OUTPUT MOV	SEC, #0 INC	MIN LCALL	SCHEDULE MOV	A, #60 CJNE	A, MIN, TIMER_UPDATE MOV	MIN, #0 INC	HOUR MOV	A, #24 CJNE	A, HOUR, SHOW_OUTPUT MOV	HOUR, #0 TIMER_UPDATE: MOV	SBUF, MEM_ADC SHOW_OUTPUT: LCALL	SW LCALL	SHOW_MENU SHOW_SCHEDULE: LCALL	DECISION TIMER_EXIT: MOV	A,TEMP RETI
 * TIMER INTERRUPT ;
 * TIMER INTERRUPT ;
 * TIMER INTERRUPT ;
 * INTERRUPT Start
 * 250us
 * 50ms
 * 1 second
 * JB     BUZZER, CLR_BUZZER
 * SETB   BUZZER
 * JMP    END_BUZZER
 * CLR_BUZZER:
 * CLR    BUZZER
 * END_BUZZER:
 * 1 minute
 * 1 hour
 * 24 hour
 * LCALL	SHOW_DEBUG

DECISION: MOV	A, MEM_SWV JNB	ACC.0, AUTO JNB	ACC.1, MANUAL_OFF

MANUAL_ON: LCALL	ON_AIRCON MOV    R0, #5 MOV    DPTR, #MSG_MANUAL_ON LCALL  W_STR RET

MANUAL_OFF: LCALL	OFF_AIRCON MOV    R0, #5 MOV    DPTR, #MSG_MANUAL_OFF LCALL  W_STR RET

AUTO: LCALL	FEEDBACK MOV    R0, #5 MOV    DPTR, #MSG_AUTO LCALL  W_STR RET

SHOW_MENU: MOV	A, #00001100B LCALL	W_INS MOV    A, #10000000B           ; SET CURSOR POSITION 00H, LINE 1, POS 1 LCALL  W_INS

MOV	A, MENU_MODE JNZ	SHOW_MENU_SCHEDULE

MOV    R0, #4 MOV    DPTR, #MSG_MENU LCALL  W_STR MOV	A, #1 LCALL  W_NULL MOV	A, HOUR LCALL	W_D2 MOV	A, #00111010B LCALL	W_DATA MOV	A, MIN LCALL	W_D2 MOV	A, #00111010B LCALL	W_DATA MOV	A, SEC LCALL	W_D2 MOV	A, #3 LCALL	W_NULL

MOV    A, #11000000B           ; SET CURSOR POSITION 40H, LINE 2, POS 1 LCALL  W_INS MOV	A, MEM_ADC LCALL	W_TEMP MOV	A, #2 LCALL  W_NULL MOV	A, MEM_CNT LCALL	W_TEMP MOV	A, #1 LCALL  W_NULL RET

SHOW_MENU_SCHEDULE: SHOW_MENU_SCHEDULE_FIRST_LINE: MOV    R0, #6 MOV    DPTR, #MSG_SCH_ON LCALL  W_STR MOV	A, SHOURON LCALL	W_D2 MOV	A, #00111010B LCALL	W_DATA MOV	A, SMINON LCALL	W_D2 MOV	A, #1 LCALL  W_NULL MOV	A, SON MOV	R0, #3 JZ	MSG_ON_OFF MOV	DPTR, #MSG_ON JMP	MSG_ON_WSTR MSG_ON_OFF: MOV	DPTR, #MSG_OFF MSG_ON_WSTR: LCALL	W_STR MOV	A, SCH_OPTION JNZ	MSG_ON_SPACE MOV	A, #01111111B LCALL	W_DATA JMP	SHOW_MENU_SCHEDULE_SECOND_LINE MSG_ON_SPACE: MOV	A, #1 LCALL	W_NULL

SHOW_MENU_SCHEDULE_SECOND_LINE: MOV    A, #11000000B           ; SET CURSOR POSITION 40H, LINE 2, POS 1 LCALL  W_INS MOV    R0, #6 MOV    DPTR, #MSG_SCH_OFF LCALL  W_STR MOV	A, SHOUROFF LCALL	W_D2 MOV	A, #00111010B LCALL	W_DATA MOV	A, SMINOFF LCALL	W_D2 MOV	A, #1 LCALL  W_NULL MOV	A, SOFF MOV	R0, #3 JZ	MSG_OFF_OFF MOV	DPTR, #MSG_ON JMP	MSG_OFF_WSTR MSG_OFF_OFF: MOV	DPTR, #MSG_OFF MSG_OFF_WSTR: LCALL	W_STR MOV	A, SCH_OPTION JZ	MSG_OFF_SPACE MOV	A, #01111111B LCALL	W_DATA RET MSG_OFF_SPACE: MOV	A, #1 LCALL	W_NULL

RET

AIRCON_STATE: MOV	A, AIRCON JZ	AIRCON_STATE_OFF JB	P1.4, AIRCON_STATE_EXIT LCALL  OFF_AIRCON MOV	MEM_SWV, #1 JMP	AIRCON_STATE_EXIT AIRCON_STATE_OFF: JNB	P1.4, AIRCON_STATE_EXIT LCALL  ON_AIRCON MOV	MEM_SWV, #3 AIRCON_STATE_EXIT: RET

FEEDBACK: MOV	A, AIRCON JZ	FEEDBACK_AIRCON_OFF

FEEDBACK_AIRCON_ON: MOV	A, MEM_ADC INC	A INC	A SUBB	A, MEM_CNT JNB	ACC.7, FEEDBACK_EXIT LCALL	OFF_AIRCON JMP	FEEDBACK_EXIT

FEEDBACK_AIRCON_OFF: MOV	A, MEM_CNT INC	A INC	A SUBB	A, MEM_ADC JNB	ACC.7, FEEDBACK_EXIT LCALL	ON_AIRCON

FEEDBACK_EXIT: RET

TX: MOV	SBUF, SEC JNB	TI, $ CLR	TI MOV	SBUF, MEM_ADC JNB	TI, $ CLR	TI MOV	SBUF, MEM_CNT JNB	TI, $ CLR	TI MOV	SBUF, MEM_SWV JNB	TI, $ CLR	TI MOV	SBUF, AIRCON JNB	TI, $ CLR	TI MOV	SBUF, SON JNB	TI, $ CLR	TI MOV	SBUF, SHOURON JNB	TI, $ CLR	TI MOV	SBUF, SMINON JNB	TI, $ CLR	TI MOV	SBUF, SOFF JNB	TI, $ CLR	TI MOV	SBUF, SHOUROFF JNB	TI, $ CLR	TI MOV	SBUF, SMINOFF JNB	TI, $ CLR	TI

JNB	RI, $ MOV	A, SBUF MOV	STMP1, A CLR	RI

JNB	RI, $ MOV	A, SBUF MOV	STMP2, A CLR	RI

JNB	RI, $ MOV	A, SBUF MOV	STMP3, A CLR	RI

JNB	RI, $ MOV	A, SBUF CLR	RI

JZ	RX_END MODE1: CJNE	A, #1, MODE2 MOV	HOUR, STMP1 MOV	MIN, STMP2 MOV	SEC, STMP3 JMP RX_END MODE2: CJNE	A, #2, MODE3 MOV	SON, STMP1 MOV	SHOURON, STMP2 MOV	SMINON, STMP3 JMP RX_END MODE3: CJNE	A, #3, MODE4 MOV	SOFF, STMP1 MOV	SHOUROFF, STMP2 MOV	SMINOFF, STMP3 JMP RX_END MODE4: CJNE	A, #43, MODE5 INC	MEM_CNT JMP RX_END MODE5: CJNE	A, #45, MODE6 DEC	MEM_CNT JMP RX_END MODE6: CJNE	A, #65, MODE7 MOV	MEM_SWV, #0 JMP RX_END MODE7: CJNE	A, #66, MODE8 MOV	MEM_SWV, #1 JMP RX_END MODE8: CJNE	A, #67, RX_END MOV	MEM_SWV, #3 JMP RX_END RX_END: RET


 * SCHEDULE  ;
 * SCHEDULE  ;
 * SCHEDULE  ;

SCHEDULE: SCHEDULE_ON: MOV	A, SON JZ	SCHEDULE_OFF MOV	A, HOUR CJNE	A, SHOURON, SCHEDULE_OFF MOV	A, MIN CJNE	A, SMINON, SCHEDULE_OFF

LCALL	ON_AIRCON MOV 	MEM_SWV, #0

SCHEDULE_OFF: MOV	A, SOFF JZ	SCHEDULE_END MOV	A, HOUR CJNE	A, SHOUROFF, SCHEDULE_END MOV	A, MIN CJNE	A, SMINOFF, SCHEDULE_END

LCALL	OFF_AIRCON MOV 	MEM_SWV, #1

SCHEDULE_END: RET

ON_AIRCON: MOV 	A, AIRCON CJNE	A, #0, ON_AIRCON_EXIT SETB	P1.0 CLR	P1.1 JNB	P1.4, $ MOV 	R1, #10 ON_AIRCON_WAIT1: MOV	MEM_DJ, #255 ON_AIRCON_WAIT2: NOP DJNZ	MEM_DJ, ON_AIRCON_WAIT2 DJNZ	R1, ON_AIRCON_WAIT1

CLR	P1.0 SETB	P1.1

MOV 	R1, #255 ON_AIRCON_DELAY1: MOV	MEM_DJ, #255 ON_AIRCON_DELAY2: NOP NOP NOP NOP NOP DJNZ	MEM_DJ, ON_AIRCON_DELAY2 DJNZ	R1, ON_AIRCON_DELAY1 CLR 	P1.1 MOV	AIRCON, # 1 ON_AIRCON_EXIT: RET

OFF_AIRCON: MOV 	A, AIRCON CJNE	A, #1, OFF_AIRCON_EXIT CLR	P1.0 SETB	P1.1 JB	P1.4, $

MOV	R1, #100 OFF_AIRCON_WAIT1: MOV	MEM_DJ, #255 OFF_AIRCON_WAIT2: NOP DJNZ	MEM_DJ, OFF_AIRCON_WAIT2 DJNZ	R1, OFF_AIRCON_WAIT1

CLR	P1.1 SETB	P1.0

MOV	R1, #255 OFF_AIRCON_DELAY1: MOV	MEM_DJ, #255 OFF_AIRCON_DELAY2: NOP NOP NOP NOP NOP DJNZ	MEM_DJ, OFF_AIRCON_DELAY2 DJNZ	R1, OFF_AIRCON_DELAY1 CLR 	P1.0 MOV	AIRCON, #0 OFF_AIRCON_EXIT: RET

NULL:  	DB      '                ' MSG_MENU:	DB	'TIME ' MSG_MANUAL_ON:	DB	'M-ON ' MSG_MANUAL_OFF:	DB	'M-OFF' MSG_AUTO:	DB	'AUTO           ' MSG_SCH_ON:	DB	'S-ON ' MSG_SCH_OFF:	DB	'S-OFF ' MSG_ON:	DB	'ON ' MSG_OFF:	DB	'OFF'
 * STRINGS   ;
 * STRINGS   ;
 * STRINGS   ;

END �