本帖最后由 34af9uc 于 2021-2-28 14:23 编辑
/**************四线流水灯****************/
/*************QQ774145445****************/
/***********快手共同学习STM8*************/
/*******PMS150CSOP23-6PADAUK-0.91********/
// PMS150-C
// _______@_______
// yi--|1 PA4 PA3 6|--er
// |2 GND VDD 5|
// si--|3_PA6_____PA5_4|--san
// ___第一种显示___ ___第二种显示___ ___第三种显示___ ___第四种显示___
// _|_ _|_ _|_ | _|_ _|_ _|_ | _|_ _|_ _|_ | _|_ _|_ _|_ |
// \|/ \|/ \|/ | \|/ \|/ \|/ | \|/ \|/ \|/ | \|/ \|/ \|/ |
// | | | | | | | | | | | | | | | |
// @2 @3 @4 @1 @1 @3 @4 @2 @1 @2 @4 @3 @1 @2 @3 @4
//@1----------------------------------------------------------------------------------yi
//@2----------------------------------------------------------------------------------er
//@3----------------------------------------------------------------------------------san
//@4----------------------------------------------------------------------------------si
//原理:用四个三态引脚用拼灯原理可以显示12个发光二极管(3*4=12)
#include "extern.h"
/****************************************/ //使用手册,mini.c介绍,io的设定
/*
$ yi out,high
$ yi out,low
$ yi in;
$ er out,high
$ er out,low
$ er in
$ san out,pull
$ san out,low
$ san in
$ si out,high
$ si out,low
$ si in
*/
yi bit pa.4;
er bit pa.3;
san bit pa.5;
si bit pa.6;
/****************************************/
void xianshi(); //显示
void yanshi(); //延时
word xian_a1; //显示用
/****************************************/
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/8 // SYSCLK=IHRC/4
byte a1,a2,a3;
a1 =1; //左移1
while(a1--)
{
xian_a1 =0b0000_0000_0000_0001; //初值
a2 =12;
while(a2--)
{
a3 =20; //50次约1秒
while(a3--) {xianshi();}
xian_a1 <<=1;
}
}
a1 =1; //右移1
while(a1--)
{
xian_a1 =0b0000_1000_0000_0000; //初值
a2 =12;
while(a2--)
{
a3 =10; //50次约1秒
while(a3--) {xianshi();}
xian_a1 >>=1;
}
}
while(1) //心跳
{
word b1,b2;
b1=0b0000_0000_0100_0000;
b2=0b0000_0000_0010_0000;
xian_a1 =0;
a2 =5;
while(a2--)
{
xian_a1 |=b1;
xian_a1 |=b2;
a3 =5; while(a3--) {xianshi();}
b1 <<=1;
b2 >>=1;
}
b1=0b0000_1111_1100_0000;
b2=0b0000_0000_0011_1111;
xian_a1 =0;
a2 =5;
while(a2--)
{
xian_a1 |=b1;
xian_a1 |=b2;
a3 =4; while(a3--) {xianshi();}
b1 >>=1;
b1.5 =0;
b2 <<=1;
b2.6 =0;
xian_a1 =0;
}
}
}
/****************************************/
void yanshi() //延时
{
.delay 10000;
}
/****************************************/
void xianshi() //显示
{
byte x_b1,x_b2;
x_b1 =xian_a1$1; //取高八位
x_b2 =xian_a1$0; //取低八位
$ yi out,high; //第一种显示
$ er in;
$ san in;
$ si in;
if(x_b1.3) {$ er out,low;}
if(x_b1.2) {$ san out,low;}
if(x_b1.1) {$ si out,low;}
yanshi();
$ yi in; //第二种显示
$ er out,high;
$ san in;
$ si in;
if(x_b1.0) {$ yi out,low;}
if(x_b2.7) {$ san out,low;}
if(x_b2.6) {$ si out,low;}
yanshi();
$ yi in; //第三种显示
$ er in;
$ san out,high,pull; //pa5开漏输出
$ si in;
if(x_b2.5) {$ yi out,low;}
if(x_b2.4) {$ er out,low;}
if(x_b2.3) {$ si out,low;}
yanshi();
$ yi in; //第四种显示
$ er in;
$ san in;
$ si out,high;
if(x_b2.2) {$ yi out,low;}
if(x_b2.1) {$ er out,low;}
if(x_b2.0) {$ san out,low;}
yanshi();
}
/****************************************/
/****************************************/
|