要求将所有的.c和.h文件已经其中包括的所有代码都写出来,越详细越好,不要提供思路,我要代码,我要代码!
时间: 2024-09-11 16:04:48 浏览: 34
根据您的需求,以下是各个文件的具体代码:
### keypad.c
```c
#include "keypad.h"
unsigned char GetKey(void)
{
unsigned char i;
unsigned char j;
unsigned char keyscan;
for(i=0; i<ROW_COUNT; i++) // 行线输出低电平
row[i] = 0;
for(j=0; j<COL_COUNT; j++) // 读入列线状态
if(col[j] == 0)
return i * COL_COUNT + j + 1;
return 0;
}
```
### keypad.h
```c
#ifndef KEYPAD_H_
#define KEYPAD_H_
#include <STC32G.H>
extern unsigned char key;
// 定义矩阵键盘引脚
#define ROW_COUNT 4
#define COL_COUNT 3
sbit row[ROW_COUNT] = { P2_0, P2_1, P2_2, P2_3 };
sbit col[COL_COUNT] = { P2_4, P2_5, P2_6 };
unsigned char GetKey(void);
#endif /* KEYPAD_H_ */
```
### display.c
```c
#include "display.h"
u16 disd = 0;
void dis(void)
{
u8 d2, d1, d0;
d2 = (u8)(disd / 100);
d1 = (u8)(disd / 10 % 10);
d0 = (u8)(disd % 10);
P1 = digcode[d2];
if (dp2) P1 = P1 | 0x10; c1 = 0; c2 = 1; c3 = 1;
delay100us(30);
P1 = digcode[d1];
if (dp1) P1 = P1 | 0x10; c1 = 1; c2 = 0; c3 = 1;
delay100us(30);
P1 = digcode[d0];
if (dp0) P1 = P1 | 0x10; c1 = 1; c2 = 1; c3 = 0;
delay100us(1);
}
void Timer1_init(void)
{
TR1 = 0; // 停止计数
ET1 = 1; // 允许中断
TMOD &= ~0x30;
TMOD |= (0 << 4); // 工作模式, 0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动重装
T1_CT = 0; // 定时
#if (Timer1_Reload < 65536UL)
T1x12 = 1; // 1T 模式
TH1 = (u8)((65536UL - Timer1_Reload) / 256);
TL1 = (u8)((65536UL - Timer1_Reload) % 256);
#else
T1x12 = 0; // 12T 模式
TH1 = (u8)((65536UL - Timer1_Reload/12) / 256);
TL1 = (u8)((65536UL - Timer1_Reload/12) % 256);
#endif
TR1 = 1; // 开始运行
}
void main()
{
Timer1_init();
EA = 1; // 全局中断使能
while(1)
{
disd = GetKey() - 1; // 更新要显示的数字
}
}
void timer1(void) interrupt 3
{
#if (Timer1_Reload < 65536UL)
T1x12 = 1; // 1T mode
TH1 = (u8)((65536UL - Timer1_Reload) / 256);
TL1 = (u8)((65536UL - Timer1_Reload) % 256);
#else
T1x12 = 0; // 12T mode
TH1 = (u8)((65536UL - Timer1_Reload/12) / 256);
TL1 = (u8)((65536UL - Timer1_Reload/12) % 256);
#endif
dis();
}
```
### display.h
```c
#ifndef DISPLAY_H_
#define DISPLAY_H_
#include <STC32G.H>
#include "keypad.h"
#include "common.h"
void dis(void);
void Timer1_init(void);
#endif /* DISPLAY_H_ */
```
请确认以上代码是否符合您的要求。如有任何错误或遗漏,请告知以便进行修正。
阅读全文