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

📄 main.s

📁 AVR单片机解码普通PC键盘码值
💻 S
字号:
	.module main.c
	.area data(ram, con, rel)
_KB_HitFlag::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\AVRchengcu\PS2--AVR\ps2\main.c
	.dbsym e KB_HitFlag _KB_HitFlag c
_KB_UpFlag::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\AVRchengcu\PS2--AVR\ps2\main.c
	.dbsym e KB_UpFlag _KB_UpFlag c
_KB_Buf::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\AVRchengcu\PS2--AVR\ps2\main.c
	.dbsym e KB_Buf _KB_Buf c
	.area text(rom, con, rel)
	.dbfile D:\AVRchengcu\PS2--AVR\ps2\main.c
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 22
; /******************************************************************************
; //程序功能解码PC键盘,然后把键盘码值通过串口发送到串口显示
; //晶振频率:16 MHZ
; //单片机类型:maget 16
; //编写日期:2009年3月13日      谢巍
; *******************************************************************************/
; 
; #include <iom16v.h>
; #include <macros.h>
; 
; #define IRsignal    (PINA&BIT(0))            //检测一个端口电平输入情况就要这样定义了
; #define DIR_I       DDRA&=~BIT(0)  
; #define DIR_O       DDRA|=BIT(0)
; 
; //定义全局变量
; unsigned char    KB_HitFlag = 0;		    //按键标志
; unsigned char    KB_UpFlag = 0;		    //抬起标志
; unsigned char    KB_Buf=0;	//键盘缓冲区
; 
; //外部中断初始化函数
; void init_devices(void)
; {
	.dbline 23
;  MCUCR = 0x02;    //INT1 的下降沿产生异步中断请求
	ldi R24,2
	out 0x35,R24
	.dbline 24
;  GICR  = 0x40;    //INT1中断使能
	ldi R24,64
	out 0x3b,R24
	.dbline 25
;  TIMSK = 0x00;    //timer interrupt sources
	clr R2
	out 0x39,R2
	.dbline 26
;  SEI();           //打开外部所有中断    两种表达方式是相同的
	sei
	.dbline -2
	.dbline 27
; }
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 4
	jmp _int1_isr
	.area text(rom, con, rel)
	.dbfile D:\AVRchengcu\PS2--AVR\ps2\main.c
	.area data(ram, con, rel)
	.dbfile D:\AVRchengcu\PS2--AVR\ps2\main.c
L3:
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\AVRchengcu\PS2--AVR\ps2\main.c
L4:
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\AVRchengcu\PS2--AVR\ps2\main.c
	.area text(rom, con, rel)
	.dbfile D:\AVRchengcu\PS2--AVR\ps2\main.c
	.dbfunc e int1_isr _int1_isr fV
	.dbsym s k L4 c
	.dbsym s cnt L3 c
	.even
_int1_isr::
	xcall push_lset
	.dbline -1
	.dbline 32
; 
; //外部中断1中断服务函数
; #pragma interrupt_handler int1_isr:2
; void int1_isr(void)
; {
	.dbline 35
; 	static unsigned char cnt = 0;
; 	static unsigned char k=0;
; 	if ( cnt == 0 )		    //起始位
	lds R2,L3
	tst R2
	brne L5
	.dbline 36
; 	{;
	.dbline 36
	.dbline 37
; 	}
	xjmp L6
L5:
	.dbline 38
; 	else if ( cnt <= 8 )	//数据位
	ldi R24,8
	lds R2,L3
	cp R24,R2
	brlo L7
	.dbline 39
; 	{
	.dbline 40
; 		k >>= 1;
	lds R2,L4
	lsr R2
	sts L4,R2
	.dbline 41
; 		if (IRsignal==BIT(0)) 
	in R24,0x19
	andi R24,1
	cpi R24,1
	brne L8
	.dbline 42
; 		      k|= 0x80;
	mov R24,R2
	ori R24,128
	sts L4,R24
	.dbline 43
; 	}
L7:
	.dbline 45
; 	else	//校验位和停止位
; 	{;
	.dbline 45
	.dbline 46
; 	}
L8:
L6:
	.dbline 47
; 	cnt++;
	lds R24,L3
	subi R24,255    ; addi 1
	sts L3,R24
	.dbline 48
; 	if ( cnt >= 11 )	    //一帧数据接收完毕
	cpi R24,11
	brlo L11
	.dbline 49
; 	{
	.dbline 50
; 		cnt = 0;
	clr R2
	sts L3,R2
	.dbline 51
; 		if ( k == 0xF0 )	//抬起标志
	lds R24,L4
	cpi R24,240
	brne L13
	.dbline 52
; 		{
	.dbline 53
; 			KB_UpFlag = 1;
	ldi R24,1
	sts _KB_UpFlag,R24
	.dbline 54
; 		}
	xjmp L14
L13:
	.dbline 56
; 		else
; 		{
	.dbline 57
; 			if ( KB_UpFlag )
	lds R2,_KB_UpFlag
	tst R2
	breq L15
	.dbline 58
; 			{
	.dbline 59
; 				KB_UpFlag = 0;
	clr R2
	sts _KB_UpFlag,R2
	.dbline 60
; 			}
	xjmp L16
L15:
	.dbline 62
; 			else
; 			{
	.dbline 63
; 				KB_Buf = k;
	lds R2,L4
	sts _KB_Buf,R2
	.dbline 64
; 				k=0;
	clr R2
	sts L4,R2
	.dbline 65
; 				KB_HitFlag = 1;
	ldi R24,1
	sts _KB_HitFlag,R24
	.dbline 67
; 
;                 put_c(KB_Buf);
	lds R16,_KB_Buf
	clr R17
	xcall _put_c
	.dbline 68
; 	    	}
L16:
	.dbline 69
; 		}
L14:
	.dbline 70
L11:
	.dbline -2
	.dbline 71
; 	}        
; }
L2:
	xcall pop_lset
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 74
; 
; void main()
; {
	.dbline 75
;  	 init_devices();
	xcall _init_devices
	.dbline 76
; 	 init_USART(); 
	xcall _init_USART
	.dbline 77
; 	 KB_Buf=0;
	clr R2
	sts _KB_Buf,R2
L18:
	.dbline 79
	.dbline 80
	.dbline 81
L19:
	.dbline 78
	xjmp L18
X0:
	.dbline -2
	.dbline 83
; 	 while(1)
; 	 {
; 	    ;
; 	 }
; 	
; }
L17:
	.dbline 0 ; func end
	ret
	.dbend

⌨️ 快捷键说明

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