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

📄 kb.s

📁 双龙AVR-MEGA128开发板的配套源码
💻 S
字号:
	.module kb.c
	.area lit(rom, con, rel)
_unshifted::
	.byte 13,9
	.byte 14,96
	.byte 21,'q
	.byte 22,49
	.byte 26,'z
	.byte 27,'s
	.byte 28,'a
	.byte 29,'w
	.byte 30,50
	.byte 33,'c
	.byte 34,'x
	.byte 35,'d
	.byte 36,'e
	.byte 37,52
	.byte 38,51
	.byte 41,32
	.byte 42,'v
	.byte 43,'f
	.byte 44,'t
	.byte 45,'r
	.byte 46,53
	.byte 49,'n
	.byte 50,'b
	.byte 51,'h
	.byte 52,'g
	.byte 53,'y
	.byte 54,54
	.byte 57,44
	.byte 58,'m
	.byte 59,'j
	.byte 60,'u
	.byte 61,55
	.byte 62,56
	.byte 'A,44
	.byte 'B,'k
	.byte 'C,'i
	.byte 'D,'o
	.byte 'E,48
	.byte 'F,57
	.byte 'I,46
	.byte 'J,47
	.byte 'K,'l
	.byte 'L,59
	.byte 'M,'p
	.byte 'N,45
	.byte 'R,39
	.byte 'T,91
	.byte 'U,61
	.byte 'Z,13
	.byte 91,93
	.byte 93,92
	.byte 'a,60
	.byte 'f,8
	.byte 'i,49
	.byte 'k,52
	.byte 'l,55
	.byte 'p,48
	.byte 'q,44
	.byte 'r,50
	.byte 's,53
	.byte 't,54
	.byte 'u,56
	.byte 'y,43
	.byte 'z,51
	.byte 123,45
	.byte 124,42
	.byte 125,57
	.byte 0,0
	.dbfile D:\ICC-AVR\Pc_At/scancodes.h
	.dbsym s unshifted _unshifted A[136:68:2]c
_shifted::
	.byte 13,9
	.byte 14,126
	.byte 21,'Q
	.byte 22,33
	.byte 26,'Z
	.byte 27,'S
	.byte 28,'A
	.byte 29,'W
	.byte 30,64
	.byte 33,'C
	.byte 34,'X
	.byte 35,'D
	.byte 36,'E
	.byte 37,36
	.byte 38,35
	.byte 41,32
	.byte 42,'V
	.byte 43,'F
	.byte 44,'T
	.byte 45,'R
	.byte 46,37
	.byte 49,'N
	.byte 50,'B
	.byte 51,'H
	.byte 52,'G
	.byte 53,'Y
	.byte 54,94
	.byte 57,'L
	.byte 58,'M
	.byte 59,'J
	.byte 60,'U
	.byte 61,38
	.byte 62,42
	.byte 'A,60
	.byte 'B,'K
	.byte 'C,'I
	.byte 'D,'O
	.byte 'E,41
	.byte 'F,40
	.byte 'I,62
	.byte 'J,63
	.byte 'K,'L
	.byte 'L,58
	.byte 'M,'P
	.byte 'N,95
	.byte 'R,34
	.byte 'T,123
	.byte 'U,43
	.byte 'Z,13
	.byte 91,125
	.byte 93,124
	.byte 'a,62
	.byte 'f,8
	.byte 'i,49
	.byte 'k,52
	.byte 'l,55
	.byte 'p,48
	.byte 'q,44
	.byte 'r,50
	.byte 's,53
	.byte 't,54
	.byte 'u,56
	.byte 'y,43
	.byte 'z,51
	.byte 123,45
	.byte 124,42
	.byte 125,57
	.byte 0,0
	.dbsym s shifted _shifted A[136:68:2]c
_ascii::
	.word 48
	.word 49
	.word 50
	.word 51
	.word 52
	.word 53
	.word 54
	.word 55
	.word 56
	.word 57
	.word 65
	.word 66
	.word 67
	.word 68
	.word 69
	.word 70
	.dbfile D:\ICC-AVR\Pc_At\kb.c
	.dbsym s ascii _ascii A[32:16]I
	.area data(ram, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
_input::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
	.dbsym s input _input c
_output::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
	.dbsym s output _output c
	.area text(rom, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
	.dbfunc s put_kbbuff _put_kbbuff fI
;              c -> R16
	.even
_put_kbbuff::
	.dbline -1
	.dbline 12
; #include <iom103.h>
; #include "pindefs.h"
; #include "scancodes.h"
; #define BUFF_SIZE 64
; const ascii[16]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
;                  0x39,0x41,0x42,0x43,0x44,0x45,0x46};
; unsigned char bitcount;  
; unsigned char kb_buffer[BUFF_SIZE];
; unsigned char input=0;
; unsigned char output=0;
; void put_kbbuff(unsigned char c)
;  {
	.dbline 13
;   kb_buffer[input]=c;
	ldi R24,<_kb_buffer
	ldi R25,>_kb_buffer
	lds R30,_input
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R16
	.dbline 14
;   if (input<(BUFF_SIZE-1))
	lds R24,_input
	cpi R24,63
	brsh L2
	.dbline 15
;      input++; 
	subi R24,255	; addi 1
	sts _input,R24
	xjmp L3
L2:
	.dbline 17
	clr R2
	sts _input,R2
L3:
	.dbline -2
	.dbline 18
;   else
;      input=0;	 
;  }
L1:
	.dbline 0 ; func end
	ret
	.dbsym r c 16 c
	.dbfunc s getchar _getchar fI
;           temp -> R16
	.even
_getchar::
	.dbline -1
	.dbline 20
; unsigned char getchar(void)
;   {
	.dbline 22
;    unsigned char temp;
;    if(output==input)
	lds R2,_input
	lds R3,_output
	cp R3,R2
	brne L5
	.dbline 23
;        return 0;
	clr R16
	clr R17
	xjmp L4
L5:
	.dbline 25
;    else
;       {
	.dbline 26
; 	   temp=kb_buffer[output];
	ldi R24,<_kb_buffer
	ldi R25,>_kb_buffer
	lds R30,_output
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	.dbline 27
; 	   if(output<(BUFF_SIZE-1))
	lds R24,_output
	cpi R24,63
	brsh L7
	.dbline 28
; 	     {
	.dbline 29
; 		  output++;
	subi R24,255	; addi 1
	sts _output,R24
	.dbline 30
; 		 }
	xjmp L8
L7:
	.dbline 32
; 	   else
; 	     output=0;
	clr R2
	sts _output,R2
L8:
	.dbline 33
; 	   return temp;	  
	clr R17
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbsym r temp 16 c
	.dbfunc s init_kb _init_kb fI
	.even
_init_kb::
	.dbline -1
	.dbline 37
; 	  }	     
;   }
; void init_kb(void)
;     {
	.dbline 38
; 	EICR=0x02; 
	ldi R24,2
	out 0x3a,R24
	.dbline 39
;     bitcount = 11;
	ldi R24,11
	sts _bitcount,R24
	.dbline -2
	.dbline 40
;     }
L9:
	.dbline 0 ; func end
	ret
	.area bss(ram, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
L11:
	.blkb 1
L12:
	.blkb 1
L13:
	.blkb 1
	.area text(rom, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
	.dbfunc s decode _decode fI
	.dbsym s shiftup L13 c
	.dbsym s up L12 c
	.dbsym s shift L11 c
;              i -> R20
;             sc -> R22
	.even
_decode::
	xcall push_gset3
	mov R22,R16
	sbiw R28,2
	.dbline -1
	.dbline 42
; void decode(unsigned char sc)
;     {
	.dbline 45
;       static unsigned char shift,up,shiftup;
; 	  unsigned char i;
; 	  if (sc==0xf0)
	cpi R22,240
	brne L14
	.dbline 46
; 	      {
	.dbline 47
; 		   up=1;
	ldi R24,1
	sts L12,R24
	.dbline 48
; 		   return;
	xjmp L10
L14:
	.dbline 50
; 		  }
; 	  if (up==1)
	lds R24,L12
	cpi R24,1
	brne L16
	.dbline 51
; 	  	  {
	.dbline 52
; 		   up=0;
	clr R2
	sts L12,R2
	.dbline 53
; 		   if ((sc==0x12)|(sc==0x59)) shift=0;
	cpi R22,18
	brne L20
	ldi R24,1
	ldi R25,0
	mov R10,R24
	mov R11,R25
	xjmp L21
L20:
	clr R10
	clr R11
L21:
	cpi R22,89
	brne L22
	ldi R20,1
	ldi R21,0
	xjmp L23
L22:
	clr R20
	clr R21
L23:
	mov R2,R10
	mov R3,R11
	or R2,R20
	or R3,R21
	tst R2
	brne X1
	tst R3
	brne X2
	xjmp L10
X2:
X1:
	.dbline 53
	clr R2
	sts L11,R2
	.dbline 54
; 		   return;
	xjmp L10
L16:
	.dbline 56
; 		  }
; 	  if(sc==0x71)
	cpi R22,113
	brne L24
	.dbline 57
; 	     {
	.dbline 58
; 		  ocmj_write(0xf4);
	ldi R16,244
	ldi R17,0
	xcall _ocmj_write
	.dbline 59
; 		  hz_tran(1,1,"将要重新启动");
	ldi R24,<L26
	ldi R25,>L26
	std y+0,R24
	std y+1,R25
	ldi R18,1
	ldi R19,0
	ldi R16,1
	ldi R17,0
	xcall _hz_tran
	.dbline 60
; 		  asm("wdr");
	wdr
	.dbline 61
;           WDTCR = 0x0F;
	ldi R24,15
	out 0x21,R24
	.dbline 62
; 		  delay_ms(3000);
	ldi R16,3000
	ldi R17,11
	xcall _delay_ms
	.dbline 63
; 		 }	 	   
L24:
	.dbline 64
; 	  switch (sc)
	mov R20,R22
	clr R21
	cpi R20,18
	ldi R30,0
	cpc R21,R30
	breq L30
	cpi R20,18
	ldi R30,0
	cpc R21,R30
	brlt L27
L50:
	cpi R20,89
	ldi R30,0
	cpc R21,R30
	breq L31
	xjmp L27
X0:
	.dbline 65
; 	    {
L30:
	.dbline 66
; 		 case 0x12:{
	.dbline 67
; 					shift=1;		
	ldi R24,1
	sts L11,R24
	.dbline 68
; 					shiftup=1;
	sts L13,R24
	.dbline 69
; 		           }		           
L31:
	.dbline 70
; 		 case 0x59:{
	.dbline 71
; 				    shift=1;	
	ldi R24,1
	sts L11,R24
	.dbline 72
; 					shiftup=1;
	sts L13,R24
	.dbline 73
; 		           }		           
L27:
	.dbline 74
; 		 default:{
	.dbline 75
; 		          if (shift==0)
	lds R2,L11
	tst R2
	breq X3
	xjmp L32
X3:
	.dbline 76
; 					 {
	.dbline 77
	clr R20
	xjmp L37
L34:
	.dbline 77
L35:
	.dbline 77
	inc R20
L37:
	.dbline 77
; 					 for(i = 0;unshifted[i][0]!=sc && unshifted[i][0]; i++);
	ldi R24,<_unshifted
	ldi R25,>_unshifted
	mov R2,R20
	clr R3
	lsl R2
	rol R3
	add R2,R24
	adc R3,R25
	mov R30,R2
	mov R31,R3
	lpm
	mov R2,R0
	clr R3
	mov R4,R22
	clr R5
	cp R2,R4
	cpc R3,R5
	breq L38
	tst R2
	brne L34
	tst R3
	brne L34
L38:
	.dbline 78
;                      if (unshifted[i][0] == sc)
	ldi R24,<_unshifted
	ldi R25,>_unshifted
	mov R2,R20
	clr R3
	lsl R2
	rol R3
	add R2,R24
	adc R3,R25
	mov R30,R2
	mov R31,R3
	lpm
	cp R0,R22
	breq X4
	xjmp L33
X4:
	.dbline 79
; 						  put_kbbuff(unshifted[i][1]);	 
	ldi R24,<_unshifted+1
	ldi R25,>_unshifted+1
	mov R2,R20
	clr R3
	lsl R2
	rol R3
	add R2,R24
	adc R3,R25
	mov R30,R2
	mov R31,R3
	lpm
	mov R16,R0
	xcall _put_kbbuff
	.dbline 80
; 					 }
	xjmp L33
L32:
	.dbline 82
; 				  else
; 				     {
	.dbline 83
	clr R20
	xjmp L45
L42:
	.dbline 83
L43:
	.dbline 83
	inc R20
L45:
	.dbline 83
; 					 for(i = 0;shifted[i][0]!=sc && shifted[i][0]; i++);
	ldi R24,<_shifted
	ldi R25,>_shifted
	mov R2,R20
	clr R3
	lsl R2
	rol R3
	add R2,R24
	adc R3,R25
	mov R30,R2
	mov R31,R3
	lpm
	mov R2,R0
	clr R3
	mov R4,R22
	clr R5
	cp R2,R4
	cpc R3,R5
	breq L46
	tst R2
	brne L42
	tst R3
	brne L42
L46:
	.dbline 84
;                      if (shifted[i][0] == sc)
	ldi R24,<_shifted
	ldi R25,>_shifted
	mov R2,R20
	clr R3
	lsl R2
	rol R3
	add R2,R24
	adc R3,R25
	mov R30,R2
	mov R31,R3
	lpm
	cp R0,R22
	brne L47
	.dbline 85
;                          {
	.dbline 86
; 						  put_kbbuff(shifted[i][1]);						  
	ldi R24,<_shifted+1
	ldi R25,>_shifted+1
	mov R2,R20
	clr R3
	lsl R2
	rol R3
	add R2,R24
	adc R3,R25
	mov R30,R2
	mov R31,R3
	lpm
	mov R16,R0
	xcall _put_kbbuff
	.dbline 87
; 						 }	 	 						 
L47:
	.dbline 88
; 					 } 
L33:
	.dbline 89
; 		         }		         
	.dbline 90
; 		} 
	.dbline -2
	.dbline 96
; 		/*debug
; 	 kb_buffer[1]=ascii[sc%16];
; 	 sc=sc/16;
; 	 kb_buffer[0]=ascii[sc%16];
; 	    debug*/	
;     }
L10:
	adiw R28,2
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r sc 22 c
	.area vector(rom, abs)
	.org 20
	jmp _int4_isr
	.area text(rom, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
	.area bss(ram, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
L52:
	.blkb 1
	.area text(rom, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
	.dbfunc s int4_isr _int4_isr fI
	.dbsym s data L52 c
	.even
_int4_isr::
	xcall push_lset
	xcall push_gset1
	.dbline -1
	.dbline 99
; #pragma interrupt_handler int4_isr:6
; void int4_isr(void)
;    {
	.dbline 112
;     static unsigned char data;   
; 	/*if((bitcount < 11)&(bitcount > 2))
;        {
; 	    data = (data >> 1);
;         if((PINE&0x20)!=0)
;            data|=0x80;
; 	   }   
;     if (--bitcount==0)
; 	     {
; 		  bitcount=11;
; 		  decode(data);
; 		 }*/
;     switch (bitcount)
	lds R20,_bitcount
	clr R21
	cpi R20,1
	ldi R30,0
	cpc R21,R30
	breq L60
	cpi R20,2
	ldi R30,0
	cpc R21,R30
	breq L59
	cpi R20,1
	ldi R30,0
	cpc R21,R30
	brlt L53
L65:
	cpi R20,11
	ldi R30,0
	cpc R21,R30
	breq L56
	xjmp L53
X5:
	.dbline 113
; 	  {
L56:
	.dbline 114
; 	   case 11:{
	.dbline 115
; 	            if ((PINE&0x20)!=0)
	sbis 0x1,5
	rjmp L57
	.dbline 116
; 				     return;
	xjmp L51
L57:
	.dbline 118
; 			    else		 
; 	   			    bitcount--;
	lds R24,_bitcount
	subi R24,1
	sts _bitcount,R24
	.dbline 119
; 	    		break;}
	xjmp L54
L59:
	.dbline 120
; 	   case 2:{
	.dbline 121
; 	   			bitcount--;	   		   
	lds R24,_bitcount
	subi R24,1
	sts _bitcount,R24
	.dbline 122
; 			    break;}
	xjmp L54
L60:
	.dbline 123
; 	   case 1:{
	.dbline 124
; 	   			bitcount--;	 
	lds R24,_bitcount
	subi R24,1
	sts _bitcount,R24
	.dbline 125
; 				if ((PINE&0x20)==0)
	sbic 0x1,5
	rjmp L61
	.dbline 126
; 				    {
	.dbline 127
; 					 bitcount=11;
	ldi R24,11
	sts _bitcount,R24
	.dbline 128
; 					 return;
	xjmp L51
L61:
	.dbline 131
; 					}
; 				else
; 				   {
	.dbline 132
; 				    bitcount=11;
	ldi R24,11
	sts _bitcount,R24
	.dbline 133
; 		            decode(data);
	lds R16,L52
	xcall _decode
	.dbline 134
; 				   }	  
	.dbline 135
; 	   	        break;}
	xjmp L54
L53:
	.dbline 136
; 	   default:{
	.dbline 137
; 	   	        data = (data >> 1);
	lds R2,L52
	lsr R2
	sts L52,R2
	.dbline 138
;                 if((PINE&0x20)!=0)
	sbis 0x1,5
	rjmp L63
	.dbline 139
;                     data|=0x80;
	mov R24,R2
	ori R24,128
	sts L52,R24
L63:
	.dbline 140
	lds R24,_bitcount
	subi R24,1
	sts _bitcount,R24
	.dbline 141
	.dbline 142
L54:
	.dbline -2
	.dbline 143
; 				bitcount--;
; 	            }		
; 	  }		 		 	  	
;     } 
L51:
	xcall pop_gset1
	xcall pop_lset
	.dbline 0 ; func end
	reti
	.area bss(ram, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
_kb_buffer::
	.blkb 64
	.dbsym s kb_buffer _kb_buffer A[64:64]c
_bitcount::
	.blkb 1
	.dbsym s bitcount _bitcount c
	.area data(ram, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c
L26:
	.blkb 13
	.area idata
	.byte 189,171,210,170,214,216,208,194,198,244,182,175,0
	.area data(ram, con, rel)
	.dbfile D:\ICC-AVR\Pc_At\kb.c

⌨️ 快捷键说明

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