单片机开发资料光盘-双龙-686M.zip

源代码在线查看: 测脉宽.asm

软件大小: 574027 K
上传用户: rllfllef
关键词: 686 zip 单片机 光盘
下载地址: 免注册下载 普通下载 VIP

相关代码

				; 测脉冲宽度,测周期,脉宽信号从AT90S8535的ICP引脚输入,最大值为为999999μS
				
				.include"8535def.inc"
					rjmp   reset
				.def    temp   = r16                   ;暂存器
				
				.def    cnt1d  = r17
				.def    cnt2d  = r18                   ;cnt1、dcnt2d和cnt3d存放结果的十进制
				.def    cnt3d  = r19
				
				.def    count  = r20
				
				.def    res1   = r21
				.def    res2   = r22                   ;res1、res2和res3存放结果的十六进制
				.def    res3   = r23
				
				.def    dt     = r25
				.def    aa     = r26
				
				.def    bb     = r27
				.def    cc     = r28
				.org   0x003                           ;icp触发中断向量
					rjmp   captr
				
				.org   0x007                           ;timer0触发中断向量
					rjmp   interru
				captr:                                 ;icp触发中断子程序
					brts  cap2
				cap1:
					ldi   temp,  0b00000010           
					out   tccr0, temp              ;开timer0
					ldi   temp,  0b00001010
					out   timsk, temp
					ldi   temp,  0b11000000        ;致timer0中断和捕捉中断
					out   tccr1b,temp
					set
					reti
				cap2:
					ldi   temp,  00
					out   tccr0, temp
					in    res1,  tcnt0
					rcall htd3
				over:
					rcall clrm1
					rcall sys
					reti
				interru:                               ;timer0溢出中断子程序
					clc
					inc   res2
					brne  b
					inc   res3
					cpi   res3,  15                ;溢出处理
					brlo  b
					rjmp  over	
				b:
					clc
					ldi   temp,  0b00001010
					out   timsk, temp
					ldi   temp,  0b11000000
					out   tccr1b,temp
					reti
				reset:
					ldi   temp,  low(ramend)
					out   spl,   temp
					ldi   temp,  high(ramend)      ;设置堆栈
					out   spl+1, temp
					ldi   temp,  $ff               ;初始化数码管状态
					out   ddrb,  temp              ;B口:数码管数据输出
					out   ddrd,  temp              ;D口:pd0-pd5为数码管片选  
					ldi   temp,  $00
					out   portb, temp              ;共阴极,数码管全灭
					out   portd, temp
					rcall clrm
					sei
					rcall sys
				loop:	                               ;在数码管显出十进制数
					mov   aa,   cnt1d
					andi  aa,   $0f                ;显示个位
					rcall a
					cbi   portd, 00
					nop
					sbi   portd, 00
					mov   aa,  cnt1d
					andi  aa,  $f0                 ;显示十位
					swap  aa
					rcall a
					cbi   portd, 01
					nop
					sbi   portd, 01
					mov   aa,  cnt2d
					andi  aa,  $0f                 ;显示百位
					rcall a
					cbi   portd, 02
					nop
					sbi   portd, 02
					mov   aa,  cnt2d
					andi  aa,  $f0                 ;显示千位
					swap  aa
					rcall a
					cbi   portd, 03
					nop
					sbi   portd, 03
					mov   aa,  cnt3d
					andi  aa,  $0f                 ;显示万位
					rcall a
					cbi   portd, 04
					nop
					sbi   portd, 04
					mov   aa,  cnt3d
					andi  aa,  $f0                 ;显示十万位
					swap  aa
					rcall a
					cbi   portd, 05
					nop
					sbi   portd, 05
					sbrc  dt,    0
					ret
					rjmp  loop
				sys:                                   ;初始化
					clt
					clc
					ldi   bb,    $0f
					ldi   dt,    00
					ldi   temp,  00
					out   tcnt0, temp
					ldi   temp,  0b00001000
					out   timsk, temp
					ldi   temp,  0b11000000
					out   tccr1b,temp
					ret
				htd3:                                  ;16转10子程序
					sbr   dt,    1
					ldi   count, 24
					clr   cnt1d
					clr   cnt2d
					clr   cnt3d
					clc
				loopd:
					rol   res1
					rol   res2
					rol   res3
				
					rol   cnt1d
					rol   cnt2d
					rol   cnt3d
					dec   count
					brne  c	
					rjmp  loop
				c:	rcall adjn
					rjmp  loopd
				a:
					ldi   zh,    high(zk*2)
					ldi   zl,    low(zk*2)
					add   zl,    aa
					lpm
					out   portb, r0	
					ret
				adjn:
					push  count
					mov   count,  cnt1d
					rcall adjd1
					mov   cnt1d,  count
					mov   count,  cnt2d
					rcall adjd1
					mov   cnt2d,  count
					mov   count,  cnt3d
					rcall adjd1
					mov   cnt3d,  count
					pop   count
					ret
				adjd1:
					ldi   temp,  3
					add   temp,  count
					sbrc  temp,  3
					mov   count, temp
					ldi   temp,  $30
					add   temp,  count
					sbrc  temp,  7
					mov   count, temp
					ret
				clrm:
					clr   cnt1d
					clr   cnt2d
					clr   cnt3d
				clrm1:
					clr   res1
					clr   res2
					clr   res3
					ret
				
				
				
				
				.equ   zk=0x0200
				.org   zk                       ;字形表
				.db    0x03f,0x006,0x05b,0x04f
				.db    0x066,0x06d,0x07d,0x007
				.db    0x07f,0x06f,0x077,0x07c
				.db    0x039,0x05e,0x071,0x0ff                        
				
				
									

相关资源