本帖最后由 34af9uc 于 2021-3-17 22:10 编辑
/*******************五线数码管*********************/
/********************PMS150G***********************/
/****************QQ774145445***********************/
/****************快手:共同学习STM8*****************/
/****************20200926**************************/
/**************************************************/
//__________________________________________
//| __2a__ __3a__ 4a 4b |
//| 1a| | | | | IN OUT |
//| | 2f| 2b| 3f| 3b| 4c 4d |
//| __2g__ __3g__ 5V 2.1A |
//| 1b| | | | | |
//| | | | 3e| 3c| 4e 4f 4g |
//| __2d__ __3d__ % 5V 1.0A |
//| @1 @2 @3 @4 @5 |
//|_________________________________________|
/**************************************************/
//__________________________________________
//| | 1- | 2- | 3- | 4- | 5- |
//| 1+ | ** | 2f | 2b | 2d | 2g |
//| 2+ | 1a1b | ** | 3a | 3c | 3f |
//| 3+ | 2a | 3g | ** | 4e | 4b |
//| 4+ | 2c | 3b | 3d | ** | 4f4g |
//| 5+ | 2e | 3e | 4a | 4c4d | ** |
//|_________________________________________|
/**************************************************/
/**************************************************/
// ------@------
// --|VDD GND|--
// @4--|PA7 PA0|--@1
// @5--|PA6 PA4|--@2
// PWM--|PA5 PA3|--@3
// -------------
/**************************************************/
/**************************************************/
led_1 bit pa.0;
led_2 bit pa.4;
led_3 bit pa.3;
led_4 bit pa.7;
led_5 bit pa.6;
/**************************************************/
void xianshi_fenjie(); //显示分解
void xianshi(); //显示
void yanshi(); //延时
byte xianshi_a1; //要显示的数字0-199
byte xianshi_c1; //百位字模
byte xianshi_c2; //十位字模
byte xianshi_c3; //个位字模
#include "extern.h"
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/4 // SYSCLK=IHRC/4
byte a1=0;
byte a2;
$ led_1 out;
$ led_2 out;
$ led_3 out;
$ led_4 out;
$ led_5 out;
while(1)
{
xianshi_a1=a1;
xianshi_fenjie();
a2=50;
while(a2)
{
a2 --;
xianshi();
}
a1++;
}
}
/**************************************************/
void xianshi_fenjie() //显示分解
{
byte xianshi_b1; //百位
byte xianshi_b2; //十位
byte xianshi_b3; //个位
byte xianshi_b4;
xianshi_b1 =0;
xianshi_b2 =0;
xianshi_b3 =0;
xianshi_b4 =xianshi_a1;
while(xianshi_b4>99) //代替除法计算出百位
{
xianshi_b4 -=100;
xianshi_b1 ++;
}
while(xianshi_b4>9) //代替除法计算出十位
{
xianshi_b4 -=10;
xianshi_b2 ++;
}
xianshi_b3 =xianshi_b4; //个位
/**************************************************/ //查表
//共阳0-9//0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
//共阴0-9//0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
xianshi_c1 =xianshi_b1; //百位
if (xianshi_b2 ==0){xianshi_c2 =0x3f;} //0十位字模
if (xianshi_b2 ==1){xianshi_c2 =0x06;} //1
if (xianshi_b2 ==2){xianshi_c2 =0x5b;} //2
if (xianshi_b2 ==3){xianshi_c2 =0x4f;} //3
if (xianshi_b2 ==4){xianshi_c2 =0x66;} //4
if (xianshi_b2 ==5){xianshi_c2 =0x6d;} //5
if (xianshi_b2 ==6){xianshi_c2 =0x7d;} //6
if (xianshi_b2 ==7){xianshi_c2 =0x07;} //7
if (xianshi_b2 ==8){xianshi_c2 =0x7f;} //8
if (xianshi_b2 ==9){xianshi_c2 =0x6f;} //9
if (xianshi_b3 ==0){xianshi_c3 =0x3f;} //0个位字模
if (xianshi_b3 ==1){xianshi_c3 =0x06;} //1
if (xianshi_b3 ==2){xianshi_c3 =0x5b;} //2
if (xianshi_b3 ==3){xianshi_c3 =0x4f;} //3
if (xianshi_b3 ==4){xianshi_c3 =0x66;} //4
if (xianshi_b3 ==5){xianshi_c3 =0x6d;} //5
if (xianshi_b3 ==6){xianshi_c3 =0x7d;} //6
if (xianshi_b3 ==7){xianshi_c3 =0x07;} //7
if (xianshi_b3 ==8){xianshi_c3 =0x7f;} //8
if (xianshi_b3 ==9){xianshi_c3 =0x6f;} //9
}
/**************************************************/
void xianshi() //显示
{
$ led_1 out,high; //第一种状态
$ led_2 in;
$ led_3 in;
$ led_4 in;
$ led_5 in;
if(xianshi_c2.5) //2f
{$ led_2 out,low;}
if(xianshi_c2.1) //2b
{$ led_3 out,low;}
if(xianshi_c2.3) //2d
{$ led_4 out,low;}
if(xianshi_c2.6) //2g
{$ led_5 out,low;}
yanshi();
$ led_1 in; //第二种状态
$ led_2 out,high;
$ led_3 in;
$ led_4 in;
$ led_5 in;
if(xianshi_c1) //1a1b百位
{$ led_1 out,low;}
if(xianshi_c3.0) //3a
{$ led_3 out,low;}
if(xianshi_c3.2) //3c
{$ led_4 out,low;}
if(xianshi_c3.5) //3f
{$ led_5 out,low;}
yanshi();
$ led_1 in; //第三种状态
$ led_2 in;
$ led_3 out,high;
$ led_4 in;
$ led_5 in;
if(xianshi_c2.0) //2a
{$ led_1 out,low;}
if(xianshi_c3.6) //3g
{$ led_2 out,low;}
//if(xianshi_c2.3){$ led_2 out,low;} //4e
$ led_4 out,low; //百分号
//if(xianshi_c2.6){$ led_2 out,low;} //4b
yanshi();
$ led_1 in; //第四种状态
$ led_2 in;
$ led_3 in;
$ led_4 out,high;
$ led_5 in;
if(xianshi_c2.2) //2c
{$ led_1 out,low;}
if(xianshi_c3.1) //3b
{$ led_2 out,low;}
if(xianshi_c3.3) //3d
{$ led_3 out,low;}
//if(xianshi_c2.6){$ led_5 out,low;} //4f4g
yanshi();
$ led_1 in; //第五种状态
$ led_2 in;
$ led_3 in;
$ led_4 in;
$ led_5 out,high;
if(xianshi_c2.4) //2e
{$ led_1 out,low;}
if(xianshi_c3.4) //3e
{$ led_2 out,low;}
//if(xianshi_c2.3){$ led_3 out,low;} //4a
//if(xianshi_c2.6){$ led_4 out,low;} //4c4d
yanshi();
}
/**************************************************/
void yanshi() //延时
{
.delay 8000;
}
/**************************************************/
/**************************************************/
/**************************************************/
/**************************************************/ |
|