当前位置:首页 > MCU > CT107D > 正文内容

CT107D-按键的使用(查询法)

chanra1n5年前 (2019-11-17)CT107D3529
#include <reg52.h>
sbit S4=P3^3;
sbit S5=P3^2;
sbit S6=P3^1;
sbit S7=P3^0;
sbit buzzer=P0^6;  //蜂鸣器
void key_get();
void Led_print(int key);
void stop_buzzer();
int main()
{
	 stop_buzzer();
	 P2=(P2&0x1f)|0x80;
	 P0=0xff;
	 while(1)
	 key_get();
	 return 0;
}

void key_get()
{
	if(S4==0)
	Led_print(1);
	if(S5==0)
	Led_print(2);
	if(S6==0)
	Led_print(3);
	if(S7==0)
	Led_print(4);
}

void Led_print(int key)
{
	P2 = ((P2&0x1f)|0x80);
	P0=0xff;
	P0=0xfe<<(key-1);
	P2 &= 0x1f;
}

void stop_buzzer()//关蜂鸣器
{
	P2=0xa0;
	buzzer=0;
	P2=0x00;
}


扫描二维码推送至手机访问。

版权声明:本文由我的FPGA发布,如需转载请注明出处。

本文链接:https://myfpga.cn/index.php/post/61.html

分享给朋友:

“CT107D-按键的使用(查询法)” 的相关文章

CT107D-让我们先从亮第一个LED灯开始吧!

CT107D-让我们先从亮第一个LED灯开始吧!

我们从官方的SCH文件中,可以看到LED相关电路:上面还很贴心的给标注了D1~D8连接的相应MCU引脚,真是非常方便,从原理图上可以看出,假如我们想让LED(L1)亮起来,由于LED组为共阳结构,需给Q1端推送一个低电平,才能使得L1亮起来。于是我信心满满的打开keil,然后编写C程序:#inclu...

CT107D DS1302

CT107D DS1302

使用官方的ds1302.h和ds1302.c,下方有核心代码讲解main.c#include<reg52.h> #include<intrins.h> #include<ds1302.h> typedef unsigned char&nb...

CT107D DS18B20

CT107D DS18B20

先贴上核心代码unsigned char get_temp(void) { unsigned char TH,TL; init_ds18b20(); Write_DS18B20(0xCC); Write_DS18B20(0x44); De...

CT107D DAC 电压模拟输出

CT107D DAC 电压模拟输出

/*   程序说明: IIC总线驱动程序   软件环境: Keil uVision 4.10    硬件环境: CT107单片机综合实训平台 8051,12MHz...

CT107D V10 V20 原理图

CT107D V10 V20 原理图

CT107D单片机竞赛板V10原理图.pdfCT107D单片机竞赛板V20原理图.pdfIAP15转接板原理图.pdf...