📄 led.c
字号:
/*============================================================
功能:使用TM1623数码管显示演示.
作者: Mingtree ycxms88@163.com http://www.mcu123.com
==============================================================*/
#include <REG52.H>
//TM1623显示控制口
sbit DOUT_LED=P1^5;
sbit DIN_LED=P1^2;
sbit CS_LED=P1^0;
sbit CLK_LED=P1^4;
unsigned char Disp_Buf[6];
/*;======================================================================================== 10
; 0 1 2 3 4 5 6 7 8 9 A B C D E F */
unsigned char code D_Code[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0xF7,0x77,0xB7,0xC7,0xE2,0xD5,0xff};/*显示码表*/
//延时
void dly(unsigned int i)
{
while (i--)
{
;
} ;
}
//输出一个字节
void Sent_Byte(unsigned char wrdata){
unsigned char k;
CLK_LED=0;
for(k=0;k<8;k++){
if((wrdata & 0x01)==0){
DIN_LED=0;
}
else{
DIN_LED=1;
}
wrdata>>=1;
CLK_LED=1;
CLK_LED=0;
}
}
/*//显示程序
void disp(void)
{
CLK_LED0;
CS_LED0;
Sent_Byte(0xc1);
CS_LED1;
CLK_LED0;
CS_LED0;
Sent_Byte(0xf8);
Sent_Byte(0x88);
Sent_Byte(0x61);
CS_LED1;
}
*/
void Disp_Led(void)
{
CS_LED=0;
Sent_Byte(0x01);//显示模式5位13段
CS_LED=1;
CS_LED=0;
Sent_Byte(0x40);//设置数据
CS_LED=1;
CS_LED=0;
Sent_Byte(0xc0);//设置地址
Sent_Byte(D_Code[Disp_Buf[0]]);//1
Sent_Byte(0x00);
Sent_Byte(D_Code[Disp_Buf[1]]);//2
Sent_Byte(0x00);
Sent_Byte(D_Code[Disp_Buf[2]]);//3
Sent_Byte(0x00);
Sent_Byte(D_Code[Disp_Buf[3]]);//4
Sent_Byte(0x00);
Sent_Byte(D_Code[Disp_Buf[4]]);//5
//Sent_Byte(0x00);
CS_LED=1;
CS_LED=0;
Sent_Byte(0x8a);//控制显示
CS_LED=1;
}
void Fill_DispBuf(void)
{
Disp_Buf[0]=1;
Disp_Buf[1]=1;
Disp_Buf[2]=8;
Disp_Buf[3]=8;
Disp_Buf[4]=0x10;
}
unsigned char Scan_Key(void)//按键读数据子程序
{
unsigned char key_i,key_temp;//key_read;
key_temp=0;
for(key_i=0;key_i<8;key_i++)
{
key_temp>>=1;
CLK_LED=0;//下降沿输出数据
if(DOUT_LED!=0)
key_temp=key_temp|0x80;
//key_read=key_temp;
CLK_LED=1;
}
return key_temp;
}
unsigned char Get_Key(void)//按键处理子程序,返回按键编号
{
unsigned char K1,K2;
CS_LED=0;
Sent_Byte(0x42);//读键扫数据指令
K1=Scan_Key()&0x1b;
K2=Scan_Key()&0x1b;
CS_LED=1;
if(K1!=0x00)
{
switch(K1)
{
case 0x01:
return 0x01;
break;
case 0x02:
return 0x02;
break;
case 0x08:
return 0x03;
break;
case 0x10:
return 0x04;
break;
default:
return 0x00;
break;
}
}
if(K2!=0x00)
{
switch(K2)
{
case 0x01:
return 0x05;
break;
case 0x02:
return 0x06;
break;
case 0x08:
return 0x07;
break;
case 0x10:
return 0x08;
break;
default:
return 0x00;
break;
}
}
return 0x00;
}
void Disp_All(void)
{
Fill_DispBuf();
Disp_Buf[3]=Get_Key();
Disp_Led();
}
void Disp_buf(unsigned char xdata * buf)
{
Disp_Buf[0]=buf[0]-0x30;
Disp_Buf[1]=buf[1]-0x30;
Disp_Buf[2]=buf[2]-0x30;
Disp_Buf[3]=buf[3]-0x30;
Disp_Buf[4]=0x10;
Disp_Led();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -