📄 ch451222.c
字号:
#include "ch451.h"
#include "mcs51.h"
//#include <reg52.h>
#include <intrins.h>
#define DCLCK P25
#define DIN P24
#define LOAD P33
#define DOUT P32
void delay1(unsigned char dat)
{
dat--;
}
unsigned char get_key()
{
unsigned char i ,temp=0xe0;
// EA=0;
for(i=0;i<4;i++)
{
DCLCK=0;
if(0x80&temp) DIN=1;
else DIN=0;
temp<<=1;
DCLCK=1;
delay1(1);
_nop_();
}
LOAD=0;
_nop_();
delay1(1);
temp=0;
DIN=1;
LOAD=1;
_nop_();
delay1(1);
if(DOUT)
temp+=1;
for(i=0;i<6;i++)
{
temp<<=1;
DCLCK=0;
_nop_();
delay1(1);
if(DOUT)
temp+=1;
DCLCK=1;
_nop_();
delay1(1);
}
// EA=1;
return(temp);
}
void init_ch451()
{
unsigned char temp,i;
temp=0x03;//03
for(i=0;i<4;i++)
{ DCLCK=0;
if(0x01&temp) DIN=1;
else DIN=0;
temp>>=1;
DCLCK=1;
delay1(1);
_nop_();
}
temp=0x40;
for(i=0;i<8;i++)
{ DCLCK=0;
if(0x01&temp) DIN=1;
else DIN=0;
temp>>=1;
DCLCK=1;
delay1(1);
_nop_();
}
LOAD=0;
_nop_();
delay1(1);
LOAD=1;
}
void display_led(unsigned char digo,dat )
{
unsigned char i;
for(i=0;i<8;i++)
{ DCLCK=0;
if(0x01&dat) DIN=1;
else DIN=0;
dat>>=1;
DCLCK=1;
delay1(1);
_nop_();
}
for(i=0;i<3;i++)
{ DCLCK=0;
if(0x01&digo) DIN=1;
else DIN=0;
digo>>=1;
DCLCK=1;
delay1(1);
_nop_();
}
DCLCK=0;
_nop_();
delay1(1);
DIN=1;
_nop_();
delay1(1);
DCLCK=1;
_nop_();
delay1(1);
LOAD=0;
_nop_();
delay1(1);
LOAD=1;
}
/*unsigned char CH451_READ() {
unsigned char i,keycode;
EX0=0; //关中段
keycode=0X07;
LOAD=0;
for(i=0;i<4;i++){
DIN=keycode&1; //低位在前,高位在后
DCLCK=0;
keycode>>=1; //右移一位
DCLCK=1; //产生时钟上升沿锁通知CH451输入位数据
}
LOAD=1;
keycode=0;
for(i=0;i<7;i++){
keycode<<=1; //数据移入keycode,高位在前,低位在后
keycode|=DOUT; //从高到低读入451的数据
DCLCK=0; //产生时钟下升沿通知CH451输出下一位
_nop_();
DCLCK=1;
}
IE0=0; //清中断标志
EX0=1;
return(keycode); //反回键值
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -