搞了一个下午阿....差点崩溃了
实验要求:
(1)、定时采集:用定时器定时中断,每秒对一路模拟信号(0--5v)采样16次。
(2)、显示:通过七段LED显示器,显示十六进制采样的平均值。
(3)、报警:若模拟信号大于4v,使一个LED指示灯亮。
CODE:
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP PTF0
ORG 0040H
MAIN: MOV SP,#0EFH ;中断初始化
MOV TL0,#00H
MOV TH0,#4CH
MOV TMOD ,#1
MOV IE,#82H
SETB TR0
MOV 30H,#14H
MOV DPTR,#0BFFFH ;8255控制字
MOV A,#81H
MOVX @DPTR,A
MOV 70H,#10H
MOV 71H,#10H
HERE: ACALL DIS
SJMP HERE
PTF0: push ACC
PUSH DPH
PUSH DPL
PUSH R0
PUSH R3
PUSH R6
PUSH R7
MOV TL0,#00H ;中断程序
MOV TH0,#4CH
DJNZ 30H,PTF0R
MOV 30H,#14H
MOV DPTR,#7FF8H ;选中ADC0809通道0
MOVX @DPTR,A
MOV 40H,#0
MOV 41H,#0
MOV R7,#16
SAMPLE: MOVX @DPTR,A ;采样
FINISH: JB P3.2,FINISH
MOVX A,@DPTR
ADD A,41H ;累加
MOV 41H,A
MOV A,#0
ADDC A,40H
MOV 40H,A
DJNZ R7,SAMPLE
AVERAGE:MOV A,41H
ANL A,#0F0H
SWAP A
MOV 41H,A
MOV 70H,A
MOV A,40H
;XCHD A,@R1
ANL A,#0FH
MOV 71H,A
SWAP A
ADD A,41H
ALERT: SUBB A,#205
JC PTF0R1
CLR P3.3
PTF0R:
POP R7
POP R6
POP R3
POP R0
POP DPL
POP DPH
POP ACC
RETI
PTF0R1: SETB P3.3
SJMP PTF0R
DIS: MOV R3,#0FEH
MOV A,R3
MOV R0,#70H
AGAIN: MOV DPTR,#0BFFCH
MOVX @DPTR,A
MOV A,@R0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV DPTR,#0BFFDH
MOVX @DPTR,A
ACALL DELAY
INC R0
MOV A,R3
JNB ACC.1,RE
RL A
MOV R3,A
AJMP AGAIN
RE: RET
DELAY: MOV R7,#02H
DL1: MOV R6,#0FFH
DL0: DJNZ R6,DL0
DJNZ R7,DL1
RET
TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H
DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H,0
END
;接口电路:
;A15---CS0809
;A14---CS8255
;PB0--PB7----LEDA--LED-DP
;PA0---LCS1 PA1--LCS2
;IN0---5VE
;EOC---P3.3
;P3.3--LED
阅读全文
类别:默认分类 查看评论文章来源:
http://hi.baidu.com/%D2%EC%B6%C8%BF%D5%BC%E4%5F%B5%DA%CB%C4%CE%AC/blog/item/bf08e3b353c68b58082302d8.html
posted on 2010-05-18 14:21
ccyy 阅读(242)
评论(0) 编辑 收藏 引用