这是本人的单片机接口技术课程设计 题目如下: 通过89C51单片机控制家用电风扇的运行。 1)电风扇有三种风速选择:高、中、低; 2)运转时间设定; 3)三种运行形式: (1)正常:电扇连续运转; (2)自然:电扇以运转4秒、间断4秒的方式工作,模拟产生自然风; (3)睡眠:指风扇运转断8秒,间断8秒,产生轻柔的微风。 汇编语言和C语言代码实现功能相同 以下是C语言代码: PROTEUS 仿真图如图所示: 完整工程在附件里面: 以下是汇编语言代码:
- ORG 0000H
- lJMP MAIN
- ORG 000BH
- AJMP tim0
- ORG 0001BH
- AJMP tim1
- ORG 0030H
- Motor bit P2.0
- HighSpeed bit P1.0
- MediumSpeed bit P1.1
- LowSpeed bit P1.2
- NormalMode bit P1.3
- NatureMode bit P1.4
- SleepMode bit P1.5
-
-
- speed EQU 31H
- worktime EQU 32h
- flag EQU 33h
- MAIN:
- MOV SP,#60H;
- MOV TMOD,#11H
-
- MOV TH1,#0FFH;time for frequency
- MOV TL1,#0F6H
-
- MOV TH0,#3CH;time for work basic 50ms(65536-50000)
- MOV TL0,#0B0H
- MOV P1,#0FFH; set io in mode
-
- SETB EA;
- SETB ET1;
- SETB TR1;
-
- MOV speed,#50;preset the mode
- MOV flag,#0FFH
- mov R0,#0
- mov R1,#0
-
- MOV P0,#04H;display the mode
- MOV P3,#088H
- LOOP0:
-
- MOV R2,P1
- CJNE R2,#0FFH,processkey
- SJMP LOOP0
- processkey:;read the key
- call DELAY
- MOV R2,P1
- CJNE R2,#0FFH,PROCESS;judge again
- SJMP LOOP0;if not go back to the main programm
- PROCESS:
- JB HighSpeed,K0
- MOV speed,#100
- MOV P0,#0H;all the led light up
-
- K0: JB MediumSpeed,K1
- MOV speed,#50
- MOV P0,#04H;light up two lights
-
-
- K1:
- JB LowSpeed,K2;
- MOV speed,#20
- MOV P0,#06H;light up one light
-
- K2:
- JB NormalMode,K3
- MOV flag,#0ffH
- CLR ET0
- CLR TR0
- MOV P3,#88H
-
- K3:
- JB NatureMode,K4
- MOV worktime,#20;two seconds
- SETB ET0
- SETB TR0
- MOV P3,#83H
-
- K4: JB SleepMode,LOOP0
- MOV worktime,#40;fout seconds
- SETB ET0
- SETB TR0
- MOV P3,#0C6H
-
- SJMP LOOP0
- tim0: ;generate the work time
- clr tr0
- MOV TH0,#3CH;time for work basic 50ms(65536-50000)
- MOV TL0,#0B0H
- setb tr0
-
- PUSH ACC
- MOV A, worktime
-
- SUBB A,R0
- jnc loop1
- mov R0,#0
-
- mov A,flag;
- cpl A
- mov flag,A
-
- loop1:
- inc R0;
- POP ACC
- RETI
-
-
-
- tim1:
- clr tr1
- MOV TH1,#0xff;time for pwm basic 0.01ms(65536-10)
- MOV TL1,#0xf6
- setb tr1
-
- PUSH ACC
- mov A,#100
- subb A,R1
- jnc loop2
- mov R1,#0;
- loop2:
- mov A,flag;
- jz loop3
- mov A,speed;
- subb A,R1;
- jnc loop4
- loop3:
- clr Motor
- SJMP OUT1
- loop4:
- setb Motor;
- OUT1:
- POP ACC
- inc R1
- RETI
- DELAY:
- MOV R7,#10
- DE: MOV R6,#10
- DJNZ R6,$
- DJNZ R7,DE
- RET
-
- END
复制代码
|