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

📄 asmavr.asm

📁 ATMEL AVR 单片机开发套件和大量C和ASM代码工程
💻 ASM
字号:
.include "8515def.inc"
;***** 引脚定义
.equ	Data=2	      ;数据
.equ	Clk=3	      ;时钟
.equ	Cs=4          ;片选 
.equ    Key=1         ;键盘
;***** 全局寄存器变量
.def	bitcnt=R16    ;位计数器
.def	temp=R17		
.def    temp1=r18 
.def    temp2=r19
.cseg
.org 0
rjmp reset
;**************************************
;     发送子程序,发送字节存放在temp中
;**************************************
send:   ldi    	bitcnt,$08
      	cbi    	PORTC,Cs 
      	rcall  	d90us	
again:  lsl    	temp
      	brcc   	COP
      	sbi    	PORTC,Data
      	rjmp  	next
COP:  	cbi 	PORTC,Data
next: 	nop
      	nop
      	sbi 	PORTC,Clk
      	rcall 	d10us
      	cbi 	PORTC,Clk
      	rcall	d10us
      	dec	bitcnt
      	brne	again
      	cbi	PORTC,Data
      	ret


;*****************************************
;        接收子程,接收字节存放temp2
;*****************************************
receive:ldi	bitcnt,$08
        cbi	DDRC,Data
	rcall 	d90us
        nop 
loop1:  sbi	PORTC,Clk
    	rcall 	d10us
        sbic 	PINC,Data     
        rjmp	plus                
        clc 
  	rol 	temp2         
       	nop
        cbi  	PORTC,Clk
     	rcall	d10us
  	rjmp	last 
plus: 	sec
        rol	temp2
    	nop
        cbi 	PORTC,Clk
       	rcall  	d10us             
last:   dec	bitcnt
        breq  	loop2
	rjmp  	loop1
loop2:	sbi	ddrc,Data
        ret
  
;********** 程序由此执行*********************

reset:   ldi 	temp,low(RAMEND)
         out  	SPL,temp
         ldi	temp,high(RAMEND)
         out 	SPH,temp
         ldi	temp,$1c
         out	DDRC,temp
         ldi    temp,$10
         out	PORTC,temp 
         ldi 	temp,60
         rcall	delay_ms        ;初次启动延时30ms
         ldi    temp,$bf
         rcall 	send
         sbi    PORTC,Cs
         ldi	bitcnt,6
wait_1:  ldi    temp,200
         rcall	delay_ms 
	 dec	bitcnt
 	 brne	wait_1
         ldi	temp,$a4         
         rcall  send
         sbi	PORTC,Cs
         ldi	temp,$98
         rcall	send
	 ldi 	temp,$ff
         rcall	send
	 sbi	PORTC,Cs
         ldi	temp,$88
         rcall	send
	 ldi 	temp,$fe
         rcall	send
	 sbi	PORTC,Cs
         ldi	temp,$90
         rcall	send
	 ldi 	temp,$08
         rcall	send
	 sbi	PORTC,Cs
key_wait:         
         ldi 	temp,$1c
         out    DDRC,temp
         ldi	temp,$10
         out	PORTC,temp
	 sbic 	PINC,Key       
         rjmp 	key_wait 
         ldi 	temp,$15           ;read keypad
         rcall 	send
         rcall 	receive           
         sbi 	PORTC,Cs           
         ldi    temp,$a1
         rcall	send
         sbi    PORTC,Cs
         ldi    temp,$a1
         rcall	send
         sbi    PORTC,Cs
	 ldi 	temp,$c8
         rcall	send
         mov    temp,temp2
         rcall	send
         sbi	PORTC,Cs
         swap	temp2
	 andi	temp2,$0f 
         ldi 	temp,$c9
         rcall	send
         mov    temp,temp2
         rcall	send
         sbi	PORTC,Cs         
ss:	 sbis	PINC,key
         rjmp	ss
         rjmp   key_wait

;*********************************************************
;                  延时子程序
;*********************************************************
		
d10us:  ldi	temp1,26
lp:     dec	temp1
       	brne	lp
      	ret    
d90us:  ldi	temp1,238
lp1:    dec	temp1
        brne	lp1
        ret
;*********************************************************
;                ms级延时程序,延时(temp)ms     
;*********************************************************    
delay_ms:
	ldi	temp2,11
lp2:
        rcall	d90us
        dec	temp2
        brne    lp2
        dec	temp
        brne	delay_ms
	ret          


⌨️ 快捷键说明

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