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

📄 ex_support.s

📁 一个解决5个IO口扫描25个按键的解决方法,完整文件包,有参考意义,C51.
💻 S
📖 第 1 页 / 共 3 页
字号:
	.module EX_Support.c
	.area text(rom, con, rel)
	.dbfile F:\AVR\按键扫描\EX_Support.c
	.area data(ram, con, rel)
	.dbfile F:\AVR\按键扫描\EX_Support.c
_s_wSystemDelayTimerCounter:
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile F:\AVR\按键扫描\EX_Support.c
_g_wSystemTimer::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile F:\AVR\按键扫描\EX_Support.c
	.area text(rom, con, rel)
	.dbfile F:\AVR\按键扫描\EX_Support.c
	.dbfunc e Driver_INIT _Driver_INIT fV
	.even
_Driver_INIT::
	.dbline -1
	.dbline 108
; /***********************************************************
; *   函数库说明:底层硬件初始化驱动函数库                   *
; *   版本:                                                 *
; *   作者:                                                 *
; *   创建日期:                                             *
; * -------------------------------------------------------- *
; *  [硬件说明]                                              *
; *   处理器:                                               *
; *   系统时钟:                                             *
; * -------------------------------------------------------- *
; *  [支 持 库]                                              *
; *   支持库名称:HD_Support.h                               *
; *   需要版本:  -----                                      *
; *   支持库说明:底层硬件初始化声明库                       *
; *                                                          *
; *   支持库名称:EX_Support.h                               *
; *   需要版本:  -----                                      *
; *   支持库说明:底层硬件初始化驱动声明库                   *
; *                                                          *
; *   支持库名称:PF_Config.h                                *
; *   需要版本:  -----                                      *
; *   支持库说明:硬件平台配置声明库                         *
; * -------------------------------------------------------- *
; *  [版本更新]                                              *
; *   修改:                                                 *
; *   修改日期:                                             *
; *   版本:                                                 *
; * -------------------------------------------------------- *
; *  [版本历史]                                              *
; * -------------------------------------------------------- *
; *  [使用说明]                                              *
; ***********************************************************/
; 
; /********************
; * 头 文 件 配 置 区 *
; ********************/
; //# define _USE_VIRTUAL_SPI_SND_CODE
; # include "PF_Config.h"
; # include "Ex_Support.h"
; 
; /********************
; *   系 统 宏 定 义  *
; ********************/
; 
; /*------------------*
; *   常 数 宏 定 义  *
; *------------------*/
; 
; /*------------------*
; *   动 作 宏 定 义  *
; *------------------*/
; /*
; # define VSPI_WAIT_SIGNAL_LOW(__SIGNAL)  \
;             do\
;             {\
;                 while((__SIGNAL));\
;                 Delay_MS(50);\
;             }\
;             while((__SIGNAL));
; # define VSPI_WAIT_SIGNAL_HIGH(__SIGNAL)  \
;             do\
;             {\
;                 while(!(__SIGNAL));\
;                 Delay_MS(50);\
;             }\
;             while(!(__SIGNAL));
; */
; # define VSPI_WAIT_SIGNAL_LOW(__SIGNAL)  while((__SIGNAL));
; # define VSPI_WAIT_SIGNAL_HIGH(__SIGNAL) while(!(__SIGNAL));
; /********************
; *  模块结构体定义区 *
; ********************/
; 
; /********************
; *   函 数 声 明 区  *
; ********************/
; void Insert_Timer0_OVF_ISR_Code(void);
; void Driver_INIT(void);
; void Delay_MS(uint16 wTime);
; UINT8 Key_Scan(void);
; #ifdef _USE_VIRTUAL_SPI_RCV_CODE
; UINT8 chVirtualSPIReceiver(void);
; #endif
; #ifdef _USE_VIRTUAL_SPI_SND_CODE
; void chVirtualSPISender(UINT8 chData);
; #endif
; /********************
; *   模块函数声明区  *
; ********************/
; 
; 
; /********************
; *   模块变量声明区  *
; ********************/
; static uint16 s_wSystemDelayTimerCounter = 0;
; /********************
; *   全局变量声明区  *
; ********************/
; uint16 g_wSystemTimer = 0;
; 
; /***********************************************************
; *   函数说明:软件驱动初始化函数                           *
; *   输入:    无                                           *
; *   输出:    无                                           *
; *   调用函数:无                                           *
; ***********************************************************/
; void Driver_INIT(void)
; {
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Delay_MS _Delay_MS fV
;          wTime -> R16,R17
	.even
_Delay_MS::
	.dbline -1
	.dbline 119
;     //*在这里插入你的各类软件驱动初始化代码*//
; }
; 
; /***********************************************************
; *   函数说明:系统毫秒延时函数                             *
; *   输入:    需要延时的时间长度                           *
; *   输出:    无                                           *
; *   调用函数:无                                           *
; ***********************************************************/
; void Delay_MS(uint16 wTime)
; {
	.dbline 120
;     s_wSystemDelayTimerCounter = wTime;
	sts _s_wSystemDelayTimerCounter+1,R17
	sts _s_wSystemDelayTimerCounter,R16
L3:
	.dbline 122
;     
;     while(s_wSystemDelayTimerCounter);
L4:
	.dbline 122
	lds R2,_s_wSystemDelayTimerCounter
	lds R3,_s_wSystemDelayTimerCounter+1
	tst R2
	brne L3
	tst R3
	brne L3
X0:
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbsym r wTime 16 i
	.dbend
	.area data(ram, con, rel)
	.dbfile F:\AVR\按键扫描\EX_Support.c
L7:
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile F:\AVR\按键扫描\EX_Support.c
	.area text(rom, con, rel)
	.dbfile F:\AVR\按键扫描\EX_Support.c
	.dbfunc e Insert_Timer0_OVF_ISR_Code _Insert_Timer0_OVF_ISR_Code fV
	.dbsym s n L7 c
	.even
_Insert_Timer0_OVF_ISR_Code::
	.dbline -1
	.dbline 132
; }
; 
; /***********************************************************
; *   函数说明:定时器0中断处理程序代码插入函数              *
; *   输入:    无                                           *
; *   输出:    无                                           *
; *   调用函数:无                                           *
; ***********************************************************/
; void Insert_Timer0_OVF_ISR_Code(void)
; {
	.dbline 134
;     static UINT8 n = 0;
;     g_wSystemTimer++;
	lds R24,_g_wSystemTimer
	lds R25,_g_wSystemTimer+1
	adiw R24,1
	sts _g_wSystemTimer+1,R25
	sts _g_wSystemTimer,R24
	.dbline 136
; 
;     if (s_wSystemDelayTimerCounter)
	lds R2,_s_wSystemDelayTimerCounter
	lds R3,_s_wSystemDelayTimerCounter+1
	tst R2
	brne X1
	tst R3
	breq L8
X1:
	.dbline 137
;     {
	.dbline 138
;         s_wSystemDelayTimerCounter--;
	movw R24,R2
	sbiw R24,1
	sts _s_wSystemDelayTimerCounter+1,R25
	sts _s_wSystemDelayTimerCounter,R24
	.dbline 139
;     }
L8:
	.dbline 141
;     
;     if (!(g_wSystemTimer & (BIT(7) - 1)))
	lds R24,_g_wSystemTimer
	lds R25,_g_wSystemTimer+1
	andi R24,127
	andi R25,0
	cpi R24,0
	cpc R24,R25
	brne L10
X2:
	.dbline 142
;     {
	.dbline 143
;         n++;
	lds R24,L7
	subi R24,255    ; addi 1
	sts L7,R24
	.dbline 144
;         n &= BIT(3)-1;
	andi R24,7
	sts L7,R24
	.dbline 145
;         chVirtualSPISender(~BIT(n));
	mov R17,R24
	ldi R16,1
	rcall lsl8
	com R16
	rcall _chVirtualSPISender
	.dbline 146
;     }
L10:
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e chVirtualSPISender _chVirtualSPISender fV
;  chBITCounter1 -> R20
;         chData -> R10
	.even
_chVirtualSPISender::
	st -y,R10
	st -y,R20
	mov R10,R16
	.dbline -1
	.dbline 192
; }
; 
; 
; 
; #ifdef _USE_VIRTUAL_SPI_RCV_CODE
; /***********************************************************
; *   函数说明:虚拟SPI接收机                                *
; *   输入:    无                                           *
; *   输出:    接收到的数据                                 *
; *   调用函数:无                                           *
; ***********************************************************/
; UINT8 chVirtualSPIReceiver(void)
; {
;     UINT8 chRCVData = 0;
;     UINT8 chCounter = 0;
;     
;     VSPI_WAIT_SIGNAL_LOW(VSPI_SS)
;     //PORTC &= ~BIT(PC0);
;     while(!VSPI_SS)
;     {
;         VSPI_WAIT_SIGNAL_LOW(VSPI_CLK)
;         PORTC ^= BIT(PC0);
;         chRCVData <<= 1;
;         chRCVData |= VSPI_DATA;
;         chCounter++;
;         VSPI_WAIT_SIGNAL_HIGH(VSPI_CLK)
;         if (chCounter == 8)
;         {
;             break;
;         }   
;     }
;     PORTC &= ~BIT(PC0);
;     return chRCVData;
;     
; }
; #endif
; 
; #ifdef _USE_VIRTUAL_SPI_SND_CODE
; /***********************************************************
; *   函数说明:虚拟SPI发送函数                              *
; *   输入:    要发送的字节                                 *
; *   输出:    无                                           *
; *   调用函数:无                                           *
; ***********************************************************/
; void chVirtualSPISender(UINT8 chData)
; {
	.dbline 193
;     UINT8 chBITCounter = 0;
	.dbline 195
;     
;     CLR_VSPI_SS
	cbi 0x18,3
	.dbline 197
;     
;     for (chBITCounter = 0;chBITCounter < 8;chBITCounter++)
	clr R20
	rjmp L16
L13:
	.dbline 198
;     {
	.dbline 199
;         SET_VSPI_CLK
	sbi 0x18,2
	.dbline 200
;         if (chData & BIT(chBITCounter))
	ldi R16,1
	mov R17,R20
	rcall lsl8
	mov R2,R10
	and R2,R16
	breq L17
X3:
	.dbline 201
;         {
	.dbline 202
;             SET_VSPI_DATA
	sbi 0x18,1
	.dbline 203
;         }
	rjmp L18
L17:
	.dbline 205
;         else
;         {
	.dbline 206
;             CLR_VSPI_DATA
	cbi 0x18,1
	.dbline 207
;         }
L18:
	.dbline 208
;         Delay_MS(5);
	ldi R16,5
	ldi R17,0
	rcall _Delay_MS
	.dbline 209
;         CLR_VSPI_CLK
	cbi 0x18,2
	.dbline 211
;         
;         Delay_MS(5);
	ldi R16,5
	ldi R17,0
	rcall _Delay_MS
	.dbline 212
;     }
L14:
	.dbline 197
	inc R20
L16:
	.dbline 197
	cpi R20,8
	brlo L13
X4:
	.dbline 214
;     
;     SET_VSPI_SS
	sbi 0x18,3
	.dbline -2
L12:
	.dbline 0 ; func end
	ld R20,y+
	ld R10,y+
	ret
	.dbsym r chBITCounter1 20 c
	.dbsym r chData 10 c
	.dbend
	.dbfunc e Key_Scan _Key_Scan fc
; chTempKeyCode0 -> R16
	.even
_Key_Scan::
	.dbline -1
	.dbline 225
; }
; #endif
; 
; /***********************************************************
; *   函数说明:按键扫描函数                                 *
; *   输入:    无                                           *
; *   输出:    按键的扫描码(如果无按键返回KEY_NULL)       *
; #   调用函数:无                                           *
; ***********************************************************/
; UINT8 Key_Scan(void)
; {
	.dbline 226
;    UINT8 chTempKeyCode = KEY_NULL;
	ldi R16,255
	.dbline 230
;    //填写扫描代码
;    
;    //首先扫描A列
;    CLR_A;
	in R24,0x15
	ori R24,56
	out 0x15,R24
	.dbline 230
	.dbline 230
	cbi 0x15,3
	.dbline 230
	nop
	.dbline 230
	.dbline 232
;    
;    if (!READ_PINX)                                         
	sbis 0x13,1
	rjmp L22
X5:
	ldi R18,1
	rjmp L23
L22:
	clr R18
L23:
	tst R18
	brne L20
X6:
	.dbline 233
;    {
	.dbline 234
;        chTempKeyCode = 0x00;
	clr R16
	.dbline 235
;    }
	rjmp L21
L20:
	.dbline 236
;    else if (!READ_PINY)
	sbis 0x13,2
	rjmp L26
X7:
	ldi R18,1
	rjmp L27
L26:
	clr R18
L27:
	tst R18
	brne L24
X8:
	.dbline 237
;    {
	.dbline 238
;        chTempKeyCode = 0x03;
	ldi R16,3
	.dbline 239
;    }
L24:
L21:
	.dbline 241
;    
;    CLR_B;
	in R24,0x15
	ori R24,56
	out 0x15,R24
	.dbline 241
	.dbline 241
	cbi 0x15,4
	.dbline 241
	nop
	.dbline 241
	.dbline 242
;    if (!READ_PINX)                                         
	sbis 0x13,1
	rjmp L30
X9:
	ldi R18,1
	rjmp L31
L30:
	clr R18
L31:
	tst R18
	brne L28
X10:
	.dbline 243
;    {
	.dbline 244
;        chTempKeyCode = 0x01;
	ldi R16,1
	.dbline 245
;    }
	rjmp L29
L28:
	.dbline 246
;    else if (!READ_PINY)
	sbis 0x13,2
	rjmp L34
X11:
	ldi R18,1
	rjmp L35
L34:

⌨️ 快捷键说明

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