PWM控制LED漸亮漸滅的51匯編程序
MAIN:
MOV P3,#00001100B
MOV TMOD,#01H
MOV A10,#10 ;子周期寬設置
MOV B20,#20 ;母周期寬設置
MOV T10,A10
MOV T20,B20
MOV AAA,#6 ;子周初始占空寬度設置
MOV BBB,#20 ;母周初始占空寬度設置
MOV SSS,AAA
MOV MMM,BBB
SETB ET0
SETB TR0
SETB EA
SETB LED
MOV 20H,#0;所有標志位清零
MOV R0,#250
MOV R1,#2 ;每隔0.07*250*2ms調節(jié)一次亮度
FREE: ;KEY BBBBBBBBBBBBBBBBBBBBBBBBBBBB
MOV PCON,#1
CHANGE2:
JB KEY,CHOU1
JB KEY2,CHOU1
DJNZ NOISE1,FREE
JNB KEY,$
JNB KEY2,$
AJMP FREE3
CHOU1:
MOV NOISE1,#0
DOWN1:
JB KEY,UP1
DJNZ NOISE2,FREE
DJNZ BBB,NEXT ;減1修正
MOV BBB,#1
NEXT:
JB KEY,FREE ;操作完成后待松鍵再退出
JNB KEY2,FREE
SJMP NEXT
UP1:
MOV NOISE2,#0
IFUP:
JB KEY2,LCRNOS
DJNZ NOISE3,FREE
INC BBB ;加1修正
MOV A,BBB
CJNE A,#21,NEXT2
MOV BBB,#20
NEXT2:
JB KEY2,FREE ;操作完成后待松鍵再退出
JNB KEY,FREE
SJMP NEXT2
LCRNOS:
MOV NOISE3,#0
AJMP FREE ;KEY B
FREE3: ;KEY
MOV PCON,#1
CHANGE1:
JB KEY,CHOU2
JB KEY2,CHOU2
DJNZ NOISE1,FREE3
JNB KEY,$
JNB KEY2,$
AJMP FREE
CHOU2:
MOV NOISE1,#0
DOWN2:
JB KEY,UP2
DJNZ NOISE2,FREE3
DJNZ AAA,NEXT3 ;減1修正
MOV AAA,#1
NEXT3:
JB KEY,FREE3 ;操作完成后待松鍵再退出
JNB KEY2,FREE3
SJMP NEXT3
UP2:
MOV NOISE2,#0
IFUP2:
JB KEY2,LCRNOS2
DJNZ NOISE3,FREE3
INC AAA ;加1修正
MOV A,AAA
CJNE A,#11,NEXT4
MOV AAA,#10
NEXT4:
JB KEY2,FREE3 ;操作完成后待松鍵再退出
JNB KEY,FREE3
SJMP NEXT4
LCRNOS2:
MOV NOISE3,#0
AJMP FREE3 ;
END
pwm相關文章:pwm原理
評論