⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mega88.asm

📁 mega88代码示例 数码管,双机通讯,四位显示 动态扫描
💻 ASM
字号:
.include "m88def.inc"
.def temp=r16
.def temp1=r17
.def position=r18
.def counter=r20
.org 0x00
rjmp reset
reti 		// IRQ0 处理
reti		// IRQ1 处理
reti 		//PCINT0 处理
reti		// PCINT1 处理
reti 		// PCINT2 处理
reti 		// 看门狗定时器处理
reti 		// 定时器2 比较A 处理
reti 		// 定时器2 比较B 处理
reti		// 定时器2 溢出处理
reti 		// 定时器1 捕捉处理
reti		// 定时器1 比较A 处理
          // 定时器1 比较B 处理
rjmp time2
reti 		// 定时器1 比较处理
reti		// 定时器0 比较A 处理
reti 		// 定时器0 比较B 处理
reti 		// 定时器0 溢出处理
reti 		//SPI 传输结束处理
reti 		// USART, RX 结束处理
reti 		//USART, UDR 空处理
reti 		// USART, TX 结束处理
reti 		// ADC 转换结束处理
reti 		// EEPROM 就绪处理
reti 		// 模拟比较器处理
reti 		// 两线串行接口处理
reti		// SPM 就绪处理

.org  $01A
RESET:					//上电初始化程序
	ldi temp, high(RAMEND) 
	out SPH,  temp
	ldi temp, low(RAMEND)
	out SPL, temp 	

	ser temp
	out ddrd,temp
	out ddrb,temp

	ldi temp,0x00		//初始化定时器,比较B
	sts tccr1a,temp
	ldi temp,0x04			//256分频
	sts tccr1b,temp
	ldi temp,0x40			//强制 输出比较B使能
	sts tccr1c,temp
	ldi temp,0x04
	sts timsk1,temp
	ldi temp,0x00
	sts tcnt1h,temp
	ldi	temp,0x00
	sts tcnt1l,temp
	ldi temp,0x20			//比较计数器为 32,2ms*(4000000/256)
	sts ocr1bl,temp
	ldi temp,0x00
	sts OCR1BH,temp 


	sbi ddrc,4			//PC4设为输出接16的PB1
	sbi portc,4
	cbi ddrc,5			//PC5设为输入接16的PB0
	sbi portc,5
	cbi ddrc,3			//设置PC0-PC3接受atmega16的A口数据
	sbi portc,3
	cbi ddrc,2
	sbi portc,2
	cbi ddrc,1
	sbi portc,1
	cbi ddrc,0			//------------------------
	sbi portc,0			//上拉电阻有效
	
	ldi xl,low(buff)
	ldi xh,high(buff)
	ldi position,0b11111110
	
main:
waitsl:						//接受秒的个位

	sbis pinc,5
	rjmp readsl
	rjmp waitsl
readsl:
	cli
	in temp,pinc
	ldi temp1,0x0F
	and temp,temp1
	sts 0x110,temp
;	ldi temp1,0x01
;	and temp,temp1
;	ldi temp1,0x01
;	cp temp,temp1
;	brne p
;	sbi portd,7
;	rjmp p1
;p:	cbi portd,7
;p1:	
	cbi portc,4
dsl:
	sbis pinc,5
	rjmp dsl
	sbi portc,4

;	rjmp waitml
	nop

waitsh:						//接受秒的十位
	sbis pinc,5
	rjmp readsh
	rjmp waitsh
readsh:
	in temp,pinc
	ldi temp1,0x0F
	and temp,temp1
	sts 0x111,temp
	cbi portc,4
dsh:
	sbis pinc,5
	rjmp dsh
	sbi portc,4

	nop

waitml:							//接受分的个位
	sbis pinc,5
	rjmp readml
	rjmp waitml
readml:
	in temp,pinc
	ldi temp1,0x0F
	and temp,temp1
	sts 0x112,temp
	cbi portc,4
dml:
	sbis pinc,5
	rjmp dml
	sbi portc,4

	nop

waitmh:								//接受分的十位
	sbis pinc,5
	rjmp readmh
	rjmp waitmh
readmh:
	in temp,pinc
	ldi temp1,0x0F
	and temp,temp1
	sts 0x113,temp
	cbi portc,4
dmh:
	sbis pinc,5
	rjmp dmh
	sbi portc,4
	nop


waithl:								//接受小时的个位
	sbis pinc,5
	rjmp readhl
	rjmp waithl
readhl:
	in temp,pinc
	ldi temp1,0x0F
	and temp,temp1
	sts 0x114,temp
	cbi portc,4
dhl:
	sbis pinc,5
	rjmp dhl
	sbi portc,4
	nop


waithh:								//接受小时的个位
	sbis pinc,5
	rjmp readhh
	rjmp waithh
readhh:
	in temp,pinc
	ldi temp1,0x0F
	and temp,temp1
	sts 0x115,temp
	cbi portc,4
dhh:
	sbis pinc,5
	rjmp dhh
	sbi portc,4
	nop
	sei
	rjmp main

time2:
	in r4,sreg
	push temp
	ldi temp,0x00
	sts tcnt1h,temp
	ldi	temp,0x00
	sts tcnt1l,temp
	ld temp,x+
	ldi zl,low(led*2)
	ldi zh,high(led*2)
	add zl,temp
	clr temp
	adc zh,temp
	lpm 
	out portb,position
	out portd,r0


	lds temp,0x0110			//控制灯的闪烁
	andi temp,0b00000001
	brne an
	cbi portd,7
	rjmp an_0
an:	sbi portd,7
an_0:						//*********
	sec 
	rol position
	cpi position,0b10111111

	brne time2_ret
	ldi xl,low(buff)
	ldi xh,high(buff)
	ldi position,0b11111110	
time2_ret:
	out sreg,r4
	pop temp
	reti

;通用延时子程序
delay:	push temp				;压栈(2t)
del1:	push temp				;压栈(2t)
del2:	push temp				;压栈(2t)
del3:	dec temp				;r16 = r16 - 1,(1t)
		brne del3				;不为0跳转移,为0顺序执行(2t/1t)
		pop temp				;出栈(2t)
		dec temp				;r16 = r16 - 1,(1t)
		brne del2				;不为0跳转移,为0顺序执行(2t/1t)
		pop temp				;出栈(2t)
		dec temp				;r16 = r16 - 1,(1t)
		brne del1				;不为0跳转移,为0顺序执行(2t/1t)
		pop temp				;出栈(2t)
		ret		
.cseg
led:
.db 0x3f,0x86,0xDb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xbf,0x00,0x00,0x00,0x00,0xbF
.dseg 
.org 0x0110
buff:
.byte 0x00
.byte 0x00
.byte 0x00
.byte 0x00
.byte 0x00
.byte 0x00

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -