C51 COMPILER V9.57.0.0 - SN: K1DZC-VY5QIC
COPYRIGHT Copyright (C) 2012 - 2016 ARM Ltd and ARM Germany GmbH. All rights reserved.
*** WARNING C206 IN LINE 70 OF d:\c51\work4\main.c: 'delay_ms': missing function-prototype
*** ERROR C267 IN LINE 70 OF d:\c51\work4\main.c: 'delay_ms': requires ANSI-style prototype
该怎么该,求救
#include <reg51.h>
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef unsigned long uint32_t;
sbit wei1 = P2^0;
sbit wei2 = P2^1;
sbit wei3 = P2^2;
sbit wei4 = P2^3;
sbit bt1 = P2^4;
sbit bt2 = P2^5;
sbit bt3 = P2^6;
uint8_t miao1 = 30;
uint8_t start = 0;
uint8_t lock = 1;
uint8_t turn1 = 0;
uint8_t miao2 = 20;
uint8_t disp_num = 0;
uint8_t check = 0;
uint8_t scores[16] = {0};
uint8_t score = 0;
// 共阳极数码管显示0-9的编码
uint8_t code duanma[10] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
// 定时器0中断服务函数
void timer0_isr() interrupt 1 {
static uint16_t cnt = 0;
TH0 = 0xFC; // 重新赋值,产生 1ms 的定时中断
TL0 = 0x18;
cnt++;
if (cnt >= 1000) { // 每隔 1000ms 更新一次倒计时
cnt = 0;
if (start && !lock) {
if (turn1 == 0)
miao1--;
if (turn1 == 1)
miao2--;
if (miao1 == 0) {
start = !start;
miao1 = 30;
turn1 = 0;
miao2 = 20;
lock = 1;
disp_num = 0;
}
if (miao2 == 0) {
start = !start;
miao1 = 30;
turn1 = 0;
miao2 = 20;
disp_num = 0;
}
}
}
}
// 显示数字函数
void display_num(uint16_t num) {
uint8_t shi, ge;
shi = num / 10 % 10;
ge = num % 10;
wei1 = 1; wei2 = 0;
P0 = duanma[shi];
delay_ms(5);
wei1 = 0; P0 = 0xff;
delay_ms(1);
wei1 = 0; wei2 = 1;
P0 = duanma[ge];
delay_ms(5);
wei2 = 0; P0 = 0xff;
delay_ms(1);
}
// 按键扫描函数
uint8_t key_scan() {
uint8_t i = 0; // 无按键按下时的返回值
// 按列扫描
uint8_t key[] = {0xef, 0xdf, 0xbf, 0x7f};
if ((start == 0 || lock == 0) && check == 0) { // 只有在暂停状态或初始状态下才能查分
for (i = 0; i < 4; i++) {
P1 = key[i];
if ((P1 & 0x0f) != 0x0f) {
delay_ms(10);
if ((P1 & 0x0f) == 0x0e)
return i + 1;
else if ((P1 & 0x0f) == 0x0d)
return (i + 5);
else if ((P1 & 0x0f) == 0x0b)
return (i + 9);
else if ((P1 & 0x0f) == 0x07)
return (i + 13);
}
}
}
return 0;
}
void main() {
uint8_t key_num = 0;
EA = 1; // 开启总中断
// 定时器0初始化
TMOD |= 0x01; // 定时器0工作模式1
TH0 = 0xFC; // 1ms 定时
TL0 = 0x18;
ET0 = 1; // 开启定时器0中断
TR0 = 1; // 启动定时器0
while (1) {
if (bt1 == 0)
check++;
while (bt1 == 0);
if (check > 16)
check = 1;
if (check == 0) {
key_num = key_scan();
if (key_num) {
lock = 1;
turn1 = 1;
disp_num = key_num;
}
display_num(disp_num);
if (turn1 == 0)
display_djs(miao1);
else
display_djs(miao2);
}
if (check) {
score = scores[--check];
display_djs(score);
check++;
display_num(check);
if (bt2 == 0) {
scores[--check]++;
display_djs(score);
check++;
}
while (bt2 == 0);
if (score > 0)
if (bt3 == 0) {
scores[--check]--;
display_djs(score);
check++;
}
while (bt3 == 0);
}
}
}
void key1() interrupt 0 {
start = !start;
lock = !lock;
}
void key2() interrupt 2 {
miao1 = 30;
miao2 = 20;
turn1 = 0;
start = 0;
disp_num = 0;
lock = 1;
check = 0;
}