代码拉取完成,页面将自动刷新
#include<reg52.h>
#define uchar unsigned char #define uint unsigned int
char Tab[] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F };
char a = 0, b = 0, ag = 0, bg = 0;
char miao = 24, go = 0, qh = 0, symbols = 1;
int bittime = 0, bitdisplay = 0;
const char P2_arr[4] = { 0xfe, 0xfd, 0xfb, 0xf7 };
const char zero = 0x00, whole = 0xff;
sbit s1 = P1 ^ 0;
sbit s2 = P1 ^ 1;
sbit s3 = P1 ^ 2;
sbit s4 = P1 ^ 3;
sbit s5 = P1 ^ 4;
sbit s6 = P1 ^ 5;
sbit s7 = P1 ^ 6;
sbit s8 = P1 ^ 7;
sbit fm = P3 ^ 7;
sbit ledA = P2 ^ 4;
sbit ledB = P2 ^ 5;
sbit ledQH = P2 ^ 6; sbit ledFuHao = P2 ^ 7;
void handleButtonPress(char *value, int maxValue, int incValue);
void buzzerOperation(int buzzer);
void ledOperation(char led1, char led2, char led3, char led4);
void buttonFunction();
void timer0_init();
void delay(int t);
void ledSymbols();
void ledANDsmgInit();
void timer0(void) interrupt 1 using 0
{
TH0 = (65536 - 2000) / 256;
TL0 = (65536 - 2000) % 256;
switch (bitdisplay)
{
case 0:
P2 = P2_arr[0];
P0 = (qh == 0) ? Tab[a / 10] : (qh == 1) ? Tab[miao / 10] : Tab[ag / 10];
break;
case 1:
P2 = P2_arr[1];
P0 = (qh == 0) ? Tab[a % 10] : (qh == 1) ? Tab[miao % 10] : Tab[ag % 10];
break;
case 2:
P2 = P2_arr[2];
P0 = (qh == 0) ? Tab[b / 10] : (qh == 1) ? zero : Tab[bg / 10];
break;
case 3:
P2 = P2_arr[3];
P0 = (qh == 0) ? Tab[b % 10] : (qh == 1) ? zero : Tab[bg % 10];
break;
}
bitdisplay = (bitdisplay + 1) % 4;
ledSymbols();
if (++bittime == 500)
{
bittime = 0;
if (go)
{
if (miao-- == 0)
{
go = 0;
miao = 24;
ledOperation(0, 0, 0, 0);
buzzerOperation(0);
delay(2000);
ledOperation(1, 1, 1, 1);
buzzerOperation(1);
}
}
}
}
void main(void) {
fm = 1;
ledANDsmgInit();
timer0_init();
while (1)
{
buttonFunction();
}
}
void delay(int t) {
int i, j;
for (i = 0; i < t; i++)
{
for (j = 0; j < 200; j++);
}
}
void timer0_init() {
TMOD = 0x01;
TH0 = (65536 - 2000) / 256;
TL0 = (65536 - 2000) % 256;
ET0 = 1;
EA = 1;
TR0 = 1;
}
void handleButtonPress(char *value, int maxValue, int incValue) {
delay(15);
*value += (symbols ? incValue : -incValue);
if (*value == maxValue || *value < 0)
{
*value = 0;
}
}
void buttonFunction() {
if (!s1 && !s2)
{
while (1)
{
if (s1 || s2)
{
break;
}
}
}
if (!s1)
{
ledA = 0;
if (!s4 && qh == 0)
{
handleButtonPress(&a, 100, 1);
while (1)
{
if (s4)
{
break;
}
}
}
if (!s5 && qh == 0)
{
handleButtonPress(&a, 100, 2);
while (1)
{
if (s5)
{
break;
}
}
}
if (!s6 && qh == 0)
{
handleButtonPress(&a, 100, 3);
while (1)
{
if (s6)
{
break;
}
}
}
if (!s7 && qh == 2)
{
handleButtonPress(&ag, 100, 1);
while (1)
{
if (s7)
{
break;
}
}
}
}
if (!s2)
{
ledB = 0;
if (!s4 && qh == 0)
{
handleButtonPress(&b, 100, 1);
while (1)
{
if (s4)
{
break;
}
}
}
if (!s5 && qh == 0)
{
handleButtonPress(&b, 100, 2);
while (1)
{
if (s5)
{
break;
}
}
}
if (!s6 && qh == 0)
{
handleButtonPress(&b, 100, 3);
while (1)
{
if (s6)
{
break;
}
}
}
if (!s7 && qh == 2)
{
handleButtonPress(&bg, 100, 1);
while (1)
{
if (s7)
{
break;
}
}
}
}
if (!s3)
{
delay(15);
qh = (qh < 2) ? (qh + 1) : 0;
while (1)
{
ledQH = 0;
if (s3)
{
break;
}
}
}
if (!s4)
{
delay(15);
if (qh == 1 && go++ == 1)
{
go = 0;
}
while (1)
{
if (s4)
{
break;
}
}
}
if (!s5)
{
delay(15);
if (qh == 1)
{
miao = 24;
go = 0;
}
while (1)
{
if (s5)
{
break;
}
}
}
if (!s8)
{
delay(15);
symbols = (symbols == 1) ? 0 : 1;
while (1)
{
if (s8)
{
break;
}
}
}
ledA = 1;
ledB = 1;
ledQH = 1;
}
void ledANDsmgInit() {
int i, start = 0, end = 1;
for (i = 0; i < 1; i++)
{
P2 = P2_arr[0];
P0 = whole;
ledA = start;
delay(160);
P2 = P2_arr[1];
P0 = whole;
ledB = start;
delay(160);
P2 = P2_arr[2];
P0 = whole;
ledQH = start;
delay(160);
P2 = P2_arr[3];
P0 = whole;
ledFuHao = start;
delay(160);
ledA = end;
delay(120);
ledB = end;
delay(120);
ledQH = end;
delay(120);
ledFuHao = end;
delay(120);
}
ledQH = start;
delay(120);
ledB = start;
delay(20);
ledA = start;
delay(20);
ledFuHao = start;
delay(100);
}
void ledSymbols() {
ledFuHao = (symbols == 1) ? 0 : 1;
}
void ledOperation(char led1, char led2, char led3, char led4) {
ledA = led1;
ledB = led2;
ledQH = led3;
ledFuHao = led4;
}
void buzzerOperation(int buzzer) {
fm = buzzer;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。