📄 main.c
字号:
//=====================================================================
// The information contained herein is the exclusive property of
// Sunnnorth Technology Co. And shall not be distributed, reproduced,
// or disclosed in whole in part without prior written permission.
// (C) COPYRIGHT 2003 SUNNORTH TECHNOLOGY CO.
// ALL RIGHTS RESERVED
// The entire notice above must be reproduced on all authorized copies.
//======================================================================
//=========================================================================
// 工程名称: ex2_Led_Show_Key
// 功能描述: 《实验仪指导书》综合实验
// 数码管显示与1*8键盘
// 涉及的库: CMacro1016.lib
// 组成文件: main.c
// isr.asm,Dig.asm,Key.asm
// Dig.inc,SPCE061A.inc,Key.inc
// Dig.h,SPCE061A.h,Key.h
// 硬件连接: 实验仪KEYPAD接口的IOA7~IOA0与COL1~COL8分别连接,IOA8与ROW连接
// IOB8~IOB15与LED_SEG接口的a~h连接
// LED_DIG接口的IOB2~IOB5与DIG1~DIG4分别连接
// 维护记录: 2005-10-14 v1.0
//
//===========================================================================
//========================================================
// 文件名称: main.c
// 功能描述: 数码管显示
// 维护记录: 2005-10-14 v1.0
//========================================================
#include "SPCE061A.h"
#include "Dig.h"
#include "Key.h"
//========================================================
// 语法格式: void LED_ShiftLeft(void)
// 实现功能: 数码管显示左移一位
// 参数: 无
// 返回值: 无
//========================================================
void LED_ShiftLeft(void)
{
unsigned int DIG_Data[4];
unsigned int Temp, i;
DIG_GetAll(DIG_Data);
for(i=3; i>0; i--)
{
Temp = DIG_Data[i];
DIG_Set(i, Temp);
}
DIG_Set(4, 0x00);
}
const unsigned int g_Data[] = {0x003f,0x0006,0x005b,0x004f,0x0066,0x006d,0x007d,0x0007,0x007f,0x006f};
//0, 1, 2, 3, 4, 5, 6, 7, 8, 9
//========================================================
// 语法格式: int main(void)
// 实现功能: 数码管显示
// 参数: 无
// 返回值: 无
//========================================================
int main(void)
{
unsigned int uiKey, i;
*P_IOA_Dir |= 0x0100; // IOA8输出高电平
*P_IOA_Attrib |= 0x0100;
*P_IOA_Buffer |= 0x0100;
Key_Init(); // 初始化按键驱动程序
DIG_Init(); // 初始化数码管驱动程序
for(i=1; i<=4; i++) // 数码管初始显示'0'
DIG_Set(i, g_Data[0]);
while(1)
{
uiKey = Key_Get();
switch(uiKey)
{
case 0x80: // K1
LED_ShiftLeft();
DIG_Set(4, g_Data[1]);
break;
case 0x40: // K2
LED_ShiftLeft();
DIG_Set(4, g_Data[2]);
break;
case 0x20: // K3
LED_ShiftLeft();
DIG_Set(4, g_Data[3]);
break;
case 0x10: // K4
LED_ShiftLeft();
DIG_Set(4, g_Data[4]);
break;
case 0x08: // K5
LED_ShiftLeft();
DIG_Set(4, g_Data[5]);
break;
case 0x04: // K6
LED_ShiftLeft();
DIG_Set(4, g_Data[6]);
break;
case 0x02: // K7
LED_ShiftLeft();
DIG_Set(4, g_Data[7]);
break;
case 0x01: // K8
LED_ShiftLeft();
DIG_Set(4, g_Data[8]);
break;
default:
break;
}
*P_Watchdog_Clear = 0x0001; //清看门狗
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -