https://www.kuaishou.com/f/X2F98gmVZrQL2iv_A
PFC161
https://www.kuaishou.com/f/X2F98gmVZrQL2iv_A
/*****************pfc161+tm1651********************/
/****************qq:774145445**********************/
/****************快手:共同学习stm8*****************/
/****************IDE:PADAUK-0.91*******************/
/************触摸按键IPHONE4解锁屏效果*************/
/******************20210621************************/
// ________ ________
// dio-|1 pb7 \_/ pb010|-clk
// |2 vdd pfc161 gnd 9|
// cs,47n-||-|3 pa7 essop10 pa0 8|-hong
// tk8-|4 pa6 pa4 7|-tk6
// tk9-|5_pa5_________pa3_6|-tk5
//touch _____ _____ _____ _____
// _____ _____ _____ _____
// | | | |
// | | | |
// pa6 pa5 pa4 pa3
// pfc161 | tm1651
// | 5v
// pb0-|-clk
// pb7-|-dio
// | gnd
// __a__ __a__ __a__ __a__
// | | | | | | | |
// f b f b f b f b
// | | | | | | | |
// --g-- --g-- --g-- --g--
// | | | | | | | |
// e c e c e c e c
// |__d__| |__d__| |__d__| |__d__|
// _______________________________________________________
//|_bit7_|_bit6_|_bit5_|_bit4_|_bit3_|_bit2_|_bit1_|_bit0_|
//|__空__|___a__|__b___|__c___|__d___|__e___|__f___|__g___|
/**************************************************/
#include "extern.h"
#define touch_1 $ tke2 pa.6
#define touch_1x tke2 =0
#define touch_2 $ tke2 pa.5
#define touch_2x tke2 =0
#define touch_3 $ tke1 pa.4
#define touch_3x tke1 =0
#define touch_4 $ tke1 pa.3
#define touch_4x tke1 =0
#define touch_run $ tcc tk_run
tm1651_clk bit pb.0;
tm1651_dio bit pb.7;
led_hong bit pa.0;
//led_lv bit pa.4;
//led_lan bit pa.3;
/**************************************************/
/**************************************************/ //tm1651
byte tm1651_a0;
byte tm1651_a1; //千位
byte tm1651_a2; //百位
byte tm1651_a3; //十位
byte tm1651_a4; //个位
void tm1651_yanshi(); //延时
void tm1651_start(); //起始信号
void tm1651_data(); //数据
void tm1651_ack(); //应答
void tm1651_stop(); //结束
void tm1651_xianshi(); //显示
/**************************************************/ //显示
byte xianshi_a1; //千位
byte xianshi_a2; //百位
byte xianshi_a3; //十位
byte xianshi_a4; //个位
byte xianshi_qumo_a1;
void xianshi(); //显示
void xianshi_qumo(); //取模
/**************************************************/ //按键效果
byte anjian_xiaoguo_a1 =0; //按键效果0,off 1,on 2开锁效果
byte anjian_a1; //按键4个
byte anjian_a2;
byte anjian_a3;
byte anjian_a4;
//byte anjian_b1;
//byte anjian_b2;
void anjian(); //按键
/**************************************************/
void yanshi(); //延时
/**************************************************/
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/4 // SYSCLK=IHRC/4
$ tm1651_clk out,high; //输出,高
$ tm1651_dio out,high;
$ led_hong out,low;
//$ led_lv out,low;
//$ led_lan out,low;
/**************************************************/ //touch触摸
$ ts ihrc/4,vcc_04,clk_128;
//$ tcc tk_run;
//$ tke2 pa5;
//$ tke1
//tkch //3-0
//tkcl //7-0
$ tps2 type_b,always_on;
//cs_sel,pa.7,47n
/**************************************************/
while (1)
{
anjian();
xianshi();
yanshi();
}
}
/**************************************************/
void tm1651_yanshi() //延时
{
.delay 50;
}
/**************************************************/
void tm1651_start() //起始信号
{
tm1651_clk =1; tm1651_dio =1; tm1651_yanshi();
tm1651_clk =1; tm1651_dio =0; tm1651_yanshi();
}
/**************************************************/
void tm1651_data() //数据
{
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a0.0){tm1651_dio =1;} else{tm1651_dio =0;}
nop;nop;nop; //太快检测不到需要加延时
tm1651_clk =1; tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a0.1){tm1651_dio =1;} else{tm1651_dio =0;}
nop;nop;nop;
tm1651_clk =1; tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a0.2){tm1651_dio =1;} else{tm1651_dio =0;}
nop;nop;nop;
tm1651_clk =1; tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a0.3){tm1651_dio =1;} else{tm1651_dio =0;}
nop;nop;nop;
tm1651_clk =1; tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a0.4){tm1651_dio =1;} else{tm1651_dio =0;}
nop;nop;nop;
tm1651_clk =1; tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a0.5){tm1651_dio =1;} else{tm1651_dio =0;}
nop;nop;nop;
tm1651_clk =1; tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a0.6){tm1651_dio =1;} else{tm1651_dio =0;}
nop;nop;nop;
tm1651_clk =1; tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a0.7){tm1651_dio =1;} else{tm1651_dio =0;}
nop;nop;nop;
tm1651_clk =1; tm1651_yanshi();
tm1651_ack();
}
/**************************************************/
void tm1651_ack() //应答
{
byte tm1651_ack_a1;
tm1651_ack_a1 =0;
$ tm1651_dio in,pull;
tm1651_clk =0; tm1651_yanshi(); //第八个时钟的下降沿
while(tm1651_dio==1) //检测低电平
{
tm1651_ack_a1 ++;
if(tm1651_ack_a1>150) //退出条件(死机)
{
$ tm1651_dio out,low;
return;
}
}
tm1651_clk =1; tm1651_yanshi();
$ tm1651_dio out,low;
}
/**************************************************/
void tm1651_stop() //结束
{
tm1651_clk =0; tm1651_dio =0; tm1651_yanshi();
tm1651_clk =1; tm1651_dio =0; tm1651_yanshi();
tm1651_clk =1; tm1651_dio =1; tm1651_yanshi();
}
/**************************************************/
void tm1651_xianshi() //tm16511显示
{
tm1651_start();
tm1651_a0 =0b0100_0000; tm1651_data(); //写数据到显示寄存器,自动地址增加
tm1651_stop();
tm1651_start();
tm1651_a0 =0b1100_0000; tm1651_data(); //设置地址00H
tm1651_a0 =tm1651_a1; tm1651_data();
tm1651_a0 =tm1651_a2; tm1651_data();
tm1651_a0 =tm1651_a3; tm1651_data();
tm1651_a0 =tm1651_a4; tm1651_data();
tm1651_stop();
tm1651_start();
tm1651_a0 =0b1000_1011; tm1651_data(); //显示开,10/16
tm1651_stop();
}
/**************************************************/
void xianshi() //显示
{
if(anjian_xiaoguo_a1 ==0) //off
{
//xianshi_a1 =tkch;
//xianshi_a2 =tkcl>>4;
xianshi_a1 =0x18;
xianshi_a2 =0x19;
xianshi_a3 =0x1a;
xianshi_a4 =0x1b;
}
if(anjian_xiaoguo_a1 ==1) //on
{
xianshi_a1 =0x14;
xianshi_a2 =0x15;
xianshi_a3 =0x16;
xianshi_a4 =0x17;
}
if(anjian_xiaoguo_a1 ==2) //触摸效果
{
if(anjian_a1 ==1){xianshi_a1 =0x10;} else{xianshi_a1 =0x14;} //|二
if(anjian_a2 ==1){xianshi_a2 =0x11;} else{xianshi_a2 =0x14;} // 二
if(anjian_a3 ==1){xianshi_a3 =0x12;} else{xianshi_a3 =0x14;} // 二
if(anjian_a4 ==1){xianshi_a4 =0x13;} else{xianshi_a4 =0x14;} // 二|
}
xianshi_qumo_a1 =xianshi_a1;
xianshi_qumo();
tm1651_a1 =xianshi_qumo_a1;
xianshi_qumo_a1 =xianshi_a2;
xianshi_qumo();
tm1651_a2 =xianshi_qumo_a1;
xianshi_qumo_a1 =xianshi_a3;
xianshi_qumo();
tm1651_a3 =xianshi_qumo_a1;
xianshi_qumo_a1 =xianshi_a4;
xianshi_qumo();
tm1651_a4 =xianshi_qumo_a1;
tm1651_xianshi();
}
/**************************************************/
//0x7e;0x30;0x6d;0x79;
//0x33;0x5b;0x5f;0x70;
//0x7f;0x7b;0x77;0x1f;
//0x4e;0x3d;0x4f;0x47;
void xianshi_qumo() //取模
{
if(xianshi_qumo_a1 ==0x00){xianshi_qumo_a1 =0x7e; return;} //0
if(xianshi_qumo_a1 ==0x01){xianshi_qumo_a1 =0x30; return;} //1
if(xianshi_qumo_a1 ==0x02){xianshi_qumo_a1 =0x6d; return;} //2
if(xianshi_qumo_a1 ==0x03){xianshi_qumo_a1 =0x79; return;} //3
if(xianshi_qumo_a1 ==0x04){xianshi_qumo_a1 =0x33; return;} //4
if(xianshi_qumo_a1 ==0x05){xianshi_qumo_a1 =0x5b; return;} //5
if(xianshi_qumo_a1 ==0x06){xianshi_qumo_a1 =0x5f; return;} //6
if(xianshi_qumo_a1 ==0x07){xianshi_qumo_a1 =0x70; return;} //7
if(xianshi_qumo_a1 ==0x08){xianshi_qumo_a1 =0x7f; return;} //8
if(xianshi_qumo_a1 ==0x09){xianshi_qumo_a1 =0x7b; return;} //9
if(xianshi_qumo_a1 ==0x0a){xianshi_qumo_a1 =0x77; return;} //a
if(xianshi_qumo_a1 ==0x0b){xianshi_qumo_a1 =0x1f; return;} //b
if(xianshi_qumo_a1 ==0x0c){xianshi_qumo_a1 =0x4e; return;} //c
if(xianshi_qumo_a1 ==0x0d){xianshi_qumo_a1 =0x3d; return;} //d
if(xianshi_qumo_a1 ==0x0e){xianshi_qumo_a1 =0x4f; return;} //e
if(xianshi_qumo_a1 ==0x0f){xianshi_qumo_a1 =0x47; return;} //f
if(xianshi_qumo_a1 ==0x10){xianshi_qumo_a1 =0x4e; return;} //|二
if(xianshi_qumo_a1 ==0x11){xianshi_qumo_a1 =0x48; return;} // 二
if(xianshi_qumo_a1 ==0x12){xianshi_qumo_a1 =0x48; return;} // 二
if(xianshi_qumo_a1 ==0x13){xianshi_qumo_a1 =0x78; return;} // 二|
if(xianshi_qumo_a1 ==0x14){xianshi_qumo_a1 =0x00; return;} //不显//on
if(xianshi_qumo_a1 ==0x15){xianshi_qumo_a1 =0x00; return;} //不显
if(xianshi_qumo_a1 ==0x16){xianshi_qumo_a1 =0x1d; return;} //o
if(xianshi_qumo_a1 ==0x17){xianshi_qumo_a1 =0x15; return;} //n
if(xianshi_qumo_a1 ==0x18){xianshi_qumo_a1 =0x00; return;} //不显//off
if(xianshi_qumo_a1 ==0x19){xianshi_qumo_a1 =0x1d; return;} //o
if(xianshi_qumo_a1 ==0x1a){xianshi_qumo_a1 =0x47; return;} //f
if(xianshi_qumo_a1 ==0x1b){xianshi_qumo_a1 =0x47; return;} //f
else{xianshi_qumo_a1 =0x16;} //n不会显示
}
/**************************************************/
void yanshi() //延时
{
.delay 1000000;
}
/**************************************************/
void anjian() //按键
{
byte anjian_b1;
byte anjian_b2;
if(anjian_xiaoguo_a1 ==0)
{
touch_1;
touch_run;
.delay 2000;
touch_1; //打开1按键
touch_run;
.delay 2000;
touch_1x; //关闭1按键
anjian_b1 =tkch<<4;
anjian_b1 |=tkcl>>4;
if(anjian_b1<0x39) //35 31
{
anjian_a1 =0; //清屏
anjian_a2 =0;
anjian_a3 =0;
anjian_a4 =0;
xianshi();
yanshi(); //延时
xianshi();
yanshi(); //延时
anjian_b2 =50; //循环20次
anjian_xiaoguo_a1 =2; //显示滑块效果
while(anjian_b2 --)
{
if(led_hong){led_hong=0;}else{led_hong=1;}
anjian_a1 =1; //第1位点亮
xianshi(); //显示
yanshi(); //延时
touch_2; //打开2按键
touch_run;
.delay 2000;
touch_2x;
anjian_b1 =tkch<<4;
anjian_b1 |=tkcl>>4;
if(anjian_b1<0x40)
{
anjian_b2 =20; //循环20次
anjian_a2 =1; //第2位点亮
}
touch_3; //打开3按键
touch_run;
.delay 2000;
touch_3x;
anjian_b1 =tkch<<4;
anjian_b1 |=tkcl>>4;
if(anjian_b1<0x40)
{
anjian_b2 =20; //循环20次
anjian_a3 =1; //第3位点亮
}
touch_4; //打开4按键
touch_run;
.delay 2000;
touch_4x;
anjian_b1 =tkch<<4;
anjian_b1 |=tkcl>>4;
if(anjian_b1<0x40)
{
anjian_b2 =3; //循环3次
anjian_a4 =1; //第4位点亮
}
if(anjian_b2==0) //退出条件
{
anjian_xiaoguo_a1 =1; //显示开on
led_hong =1;
}
}
return;
}
}
if(anjian_xiaoguo_a1 ==1)
{
touch_4;
touch_run;
.delay 2000;
touch_4;
touch_run;
.delay 2000;
touch_4x; //结束按键
anjian_b1 =tkch<<4;
anjian_b1 |=tkcl>>4;
if(anjian_b1<0x39)
{
led_hong =0;
anjian_xiaoguo_a1 =0; //显示off
}
}
}
/**************************************************/
|