/*****************pfc161+tm1651********************/
/******************20210608************************/
/****************qq:774145445**********************/
/****************快手:共同学习stm8*****************/
/**************************************************/
// _______ ______
// dio-|1 pb7 \_/ pb010|-clk
// |2 vdd gnd 9|
// cs-||-|3 pa7 pa0 8|-hong
// tk8-|4 pa6 pa4 7|-lv
// tk9-|5_pa5_______pa3_6|-lan
// 5v
// pb0--clk
// pb7--dio
// gnd
/**************************************************/
#include "extern.h"
tm1651_clk bit pb.0;
tm1651_dio bit pb.7;
/**************************************************/
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(); //显示
/**************************************************/
void yanshi()
{
.delay 1000000;
}
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/4 // SYSCLK=IHRC/4
$ tm1651_clk out,high; //输出,高
$ tm1651_dio out,high;
/**************************************************/
//0x7e;0x30;0x6d;0x79;0x33;0x5b;0x5f;0x70;0x7f;0x7b;0x77;0x1f;0x4e;0x3d;0x4f;0x47;
while (1)
{
tm1651_a1 =0x7e;
tm1651_a2 =0x30;
tm1651_a3 =0x6d;
tm1651_a4 =0x79;
tm1651_xianshi();
yanshi();
tm1651_a1 =0x33;
tm1651_a2 =0x5b;
tm1651_a3 =0x5f;
tm1651_a4 =0x70;
tm1651_xianshi();
yanshi();
tm1651_a1 =0x7f;
tm1651_a2 =0x7b;
tm1651_a3 =0x77;
tm1651_a4 =0x1f;
tm1651_xianshi();
yanshi();
tm1651_a1 =0x4e;
tm1651_a2 =0x3d;
tm1651_a3 =0x4f;
tm1651_a4 =0x47;
tm1651_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() //显示
{
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();
}
/**************************************************/
/**************************************************/
|