本帖最后由 34af9uc 于 2021-6-12 13:36 编辑
/*****************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_a1;
/**************************************************/
void tm1651_yanshi(); //延时
void tm1651_start(); //起始信号
void tm1651_data(); //数据
void tm1651_ack(); //应答
void tm1651_stop(); //结束
/**************************************************/
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/4 // SYSCLK=IHRC/4
$ tm1651_clk out,high; //输出,高
$ tm1651_dio out,high;
/**************************************************/
//0x7f;0x30;0x6d;0x79;0x33;0x5b;0x5f;0x70;0x7f;0x7b;0x77;0x1f;0x4e;0x3d;0x4f;0x47;
tm1651_yanshi();
while (1)
{
tm1651_start();
tm1651_a1 =0b0100_0000; tm1651_data(); //写数据到显示寄存器,自动地址增加
tm1651_stop();
tm1651_start();
tm1651_a1 =0b1100_0000; tm1651_data(); //设置地址00H
/*
tm1651_a1 =0b1111_1111; tm1651_data();
tm1651_a1 =0b0000_0000; tm1651_data();
tm1651_a1 =0b0000_1111; tm1651_data();
tm1651_a1 =0b1111_0000; tm1651_data();
*/
tm1651_a1 =0x7e;tm1651_data();
tm1651_a1 =0x30;tm1651_data();
tm1651_a1 =0x6d;tm1651_data();
tm1651_a1 =0x79;tm1651_data();
tm1651_stop();
tm1651_start();
tm1651_a1 =0b1000_1011; tm1651_data(); //显示开,10/16
tm1651_stop();
//while(1){}
}
}
/**************************************************/
void tm1651_yanshi() //延时
{
.delay 100;
}
/**************************************************/
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_a1.0){tm1651_dio =1;} else{tm1651_dio =0;}
tm1651_clk =1;tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a1.1){tm1651_dio =1;} else{tm1651_dio =0;}
tm1651_clk =1;tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a1.2){tm1651_dio =1;} else{tm1651_dio =0;}
tm1651_clk =1;tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a1.3){tm1651_dio =1;} else{tm1651_dio =0;}
tm1651_clk =1;tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a1.4){tm1651_dio =1;} else{tm1651_dio =0;}
tm1651_clk =1;tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a1.5){tm1651_dio =1;} else{tm1651_dio =0;}
tm1651_clk =1;tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a1.6){tm1651_dio =1;} else{tm1651_dio =0;}
tm1651_clk =1;tm1651_yanshi();
tm1651_clk =0; tm1651_yanshi();
if(tm1651_a1.7){tm1651_dio =1;} else{tm1651_dio =0;}
tm1651_clk =1;tm1651_yanshi();
tm1651_ack();
}
/**************************************************/
void tm1651_ack() //应答
{
$ tm1651_dio in,pull;
tm1651_clk =0; tm1651_yanshi(); //第八个时钟的下降沿
while(tm1651_dio){nop;}
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();
}
/**************************************************/
/**************************************************/
/**************************************************/ |