TM1668显示与按键程序调试成功的

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
unsigned char tm1668_date;
tm1668_date=0;
pd3_4=0;//数据线为输入口
CLK_TM1668=0;
for(i=0;i<8;i++)
{
// asm("nop")ቤተ መጻሕፍቲ ባይዱ
CLK_TM1668=1;
tm1668_date=tm1668_date>>1; //先读出的是低位
Send_data(0x42); //读按键命令
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
//delay_tm1668();//1us延时
key_data1=Incept_data();
asm("nop");
CLK_TM1668=1;
}
//CLK_TM1668=0;
}
//下面是接收tm1668数据函数
unsigned char Incept_data(void)
{
unsigned char i;
{
STB_TM1668=0;
Send_data(0x03); //设置显示模式,4位14段
STB_TM1668=1;
asm("nop");
STB_TM1668=0;
//Send_data(0x44); //固定地址
//asm("nop");
//STB_TM1668=0;
//Send_data(0xC7); //发送地址
Send_data(0x0);//灭发光管
//
//STB_TM1668=1;
//asm("nop");
//STB_TM1668=0;
// Send_data(0xCc); //发送地址
Send_data(0x0);
//STB_TM1668=1;
//asm("nop");
//STB_TM1668=0;
// Send_data(0xCd); //发送地址
//asm("nop");
// STB_TM1668=0;
// Send_data(0xCb); //发送地址
Send_data(0x0);//灭发光管
//
//STB_TM1668=1;
// asm("nop");
// STB_TM1668=0;
//Send_data(0xC8); //发送地址
Send_data(0x0);
//STB_TM1668=1;
//asm("nop");
//STB_TM1668=0;
//Send_data(0xC9); //发送地址
//STB_TM1668=1;
//asm("nop");
//STB_TM1668=0;
//Send_data(0xC1); //发送地址
Send_data(0x0);//灭发光管
//STB_TM1668=1;
//STB_TM1668=1;
//asm("nop");
//STB_TM1668=0;
//Send_data(0xC6); //发送地址
Send_data(data4);
//STB_TM1668=1;
}
//CLK_TM1668=0;
pd3_4=1;//数据线为输出口
//asm("nop");
return(tm1668_date);
}
//读按键函数
void read_key (void)
{
//STB_TM1668=1;
STB_TM1668=0;
{
unsigned char i;
for(i=0;i<8;i++)
{
CLK_TM1668=0;
if(dat & (1 << i)) {SDA_TM1668=1;}
else {SDA_TM1668=0;}
//asm("nop");
Send_data(0x40); //自动累加地址
STB_TM1668=1;
asm("nop");
STB_TM1668=0;
Send_data(0xC0); //发送地址
Send_data(data1);
Send_data(0x0);//灭发光管
//
STB_TM1668=1;
asm("nop");
STB_TM1668=0;
Send_data(0x89); //开显示
STB_TM1668=1;
}
Send_data(0x0);//灭发光管
//
//STB_TM1668=1;
//asm("nop");
// STB_TM1668=0;
//Send_data(0xCa); //发送地址
Send_data(0x0);
//STB_TM1668=1;
// TM1668显示与按键程序
#define SDA_TM1668 p3_4
#define CLK_TM1668 p3_5
#define STB_TM1668 p3_7
//下面是发送tm1668数据函数
void Send_data(unsigned char dat)
Send_data(data3);
//STB_TM1668=1;
//asm("nop");
//STB_TM1668=0;
//Send_data(0xC5); //发送地址
Send_data(0x0);//灭发光管
key_data2=Incept_data();
key_data3=Incept_data();
key_data4=Incept_data();
key_data5=Incept_data();
//asm("nop");
STB_TM1668=1;
}
void DIS_1668(unsigned char data1,unsigned char data2,unsigned char data3,unsigned char data4)
if(SDA_TM1668){tm1668_date=tm1668_date|0x80;}
else{tm1668_date=tm1668_date&0x7f; }
//asm("nop");
//asm("nop");
CLK_TM1668=0;
//Send_data(0xC3); //发送地址
Send_data(0x0);//灭发光管
//STB_TM1668=1;
//asm("nop");
//STB_TM1668=0;
//Send_data(0xC4); //发送地址
//asm("nop");
//STB_TM1668=0;
//Send_data(0xC2); //发送地址
Send_data(data2);
//STB_TM1668=1;
//asm("nop");
//STB_TM1668=0;
相关文档
最新文档