/****************188拼灯数码管**********************/
/****************ID:共同学习stm8********************/
/****************20241007**************************/
/**************************************************/
// ____ ____
// PB4-|1 \_/ 16|-PB3
// PB5-|2 NY 15|-PB2
// PA0-|3 8 14|-PB1
// PA1-|4 A 13|-PB0
// VDD-|5 0 12|-VSS
// PA7-|6 5 11|-PA2
// PA6-|7 4 10|-PA3
// PA5-|8____E____9|-PA4
// WY1208BWE16-10.28
// _A2_ _A3_
// | F2 B2 F3 B3 /L1
// B1 |_G2_| |_G3_|
// | E2 C2 E3 C3 %L2
// C1 |_D2_| |_D3_|
// [url=home.php?mod=space&uid=2514798]@1[/url] @2 @3 [url=home.php?mod=space&uid=26072]@4[/url] @5
// | | | | |
// pb4 pb3 pb2 pb1 pb0
// _____________________________
//第一次|_1高_|_A3__|_C3__|_____|_E3__|
//第二次|_B3__|_2高_|_A2__|_C1__|_L2__|
//第三次|_D3__|_B2__|_3高_|_B1__|_L1__|
//第四次|_F3__|_D2__|_C2__|_4高_|_____|
//第五次|_G3__|_E2__|_F2__|_G2__|_5高_|
/**************************************************/
#include <ny8.h>
//#include "NY8_constant.h"
//#define UPDATE_REG(x) __asm__("MOVR _" #x ",F")
__sbit x1 =PORTA:4;
__sbit x2 =PORTA:3;
__sbit x3 =PORTA:2;
__sbit x4 =PORTA:1;
__sbit x5 =PORTA:0;
#define x1_gao IOSTB&=~(1<<4);x1=1
#define x1_di IOSTB&=~(1<<4);x1=0
#define x1_zu IOSTB|=1<<4;
#define x2_gao IOSTB&=~(1<<3);x2=1
#define x2_di IOSTB&=~(1<<3);x2=0
#define x2_zu IOSTB|=1<<3;
#define x3_gao IOSTB&=~(1<<2);x3=1
#define x3_di IOSTB&=~(1<<2);x3=0
#define x3_zu IOSTB|=1<<2;
#define x4_gao IOSTB&=~(1<<1);x4=1
#define x4_di IOSTB&=~(1<<1);x4=0
#define x4_zu IOSTB|=1<<1;
#define x5_gao IOSTB&=~(1<<0);x5=1
#define x5_di IOSTB&=~(1<<0);x5=0
#define x5_zu IOSTB|=1<<0;
unsigned char xianshi_a1; //显示RAM变量
unsigned char xianshi_b1; //显示RAM数字
unsigned char xianshi_b2;
unsigned char xianshi_b3;
unsigned char xianshi_c1; //显示RAM字模
unsigned char xianshi_c2;
unsigned char xianshi_c3;
unsigned char const zi1[]={
0x3f, //0,0
0x06, //1,1
0x5b, //2,2
0x4f, //3,3
0x66, //4,4
0x6d, //5,5
0x7d, //6,6
0x07, //7,7
0x7f, //8,8
0x6f, //9,9
0x77, //10,a
0x7c, //11,b
0x39, //12,c
0x5e, //13,d
0x79, //14,e
0x71}; //15,f
/**************************************************/
void yanshi(unsigned char z1); //延时
void chushihua(); //初始化
void xianshi_jisuan(); //显示计算
void xianshi(); //显示
/**************************************************/
void main(void)
{
unsigned char a1;
chushihua(); //初始化
xianshi_a1 =0;
yanshi(100); //延时
while(1)
{
//CLRWDT(); //喂狗
xianshi_a1 ++; if(xianshi_a1 >199){xianshi_a1 =0;}
xianshi_jisuan(); //显示计算
for(a1 =50;a1 >0;a1 --) //显示50次
{
xianshi(); //显示
}
}
}
/**************************************************/
void xianshi() //显示
{
x1_zu; //第一种
x2_zu;
x3_zu;
x4_zu;
x5_zu;
//if(xianshi_c3 &0b00000000){} //1高
if(xianshi_c3 &0b00000001){x2_di;} //3A
if(xianshi_c3 &0b00000100){x3_di;} //3C
//if(xianshi_c1 &0b00000000){x4_di;} //无
if(xianshi_c3 &0b00010000){x5_di;} //3E
x1_gao;
yanshi(100); //延时
x1_zu; //第二种
x2_zu;
x3_zu;
x4_zu;
x5_zu;
if(xianshi_c3 &0b00000010){x1_di;} //3B
//if(xianshi_c1 &0b00000000){} //2高
if(xianshi_c2 &0b00000001){x3_di;} //2A
//if(xianshi_c1 &0b00000100){x4_di;} //1C
if(xianshi_c1 ==1){x4_di;} //1C
//if(xianshi_c1 &0b00000000){x5_di;} //%
x2_gao;
yanshi(100); //延时
x1_zu; //第三种
x2_zu;
x3_zu;
x4_zu;
x5_zu;
if(xianshi_c3 &0b00001000){x1_di;} //3D
if(xianshi_c2 &0b00000010){x2_di;} //2B
//if(xianshi_c1 &0b00000000){} //3高
//if(xianshi_c1 &0b00000010){x4_di;} //1B
if(xianshi_c1 ==1){x4_di;} //1B
//if(xianshi_c3 &0b00000000){x5_di;} // /
x3_gao;
yanshi(100); //延时
x1_zu; //第四种
x2_zu;
x3_zu;
x4_zu;
x5_zu;
if(xianshi_c3 &0b00100000){x1_di;} //3F
if(xianshi_c2 &0b00001000){x2_di;} //2D
if(xianshi_c2 &0b00000100){x3_di;} //2C
//if(xianshi_c1 &0b00000000){} //4高
//if(xianshi_c1 &0b00000000){} //无
x4_gao;
yanshi(100); //延时
x1_zu; //第五种
x2_zu;
x3_zu;
x4_zu;
x5_zu;
if(xianshi_c3 &0b01000000){x1_di;} //3G
if(xianshi_c2 &0b00010000){x2_di;} //2E
if(xianshi_c2 &0b00100000){x3_di;} //2F
if(xianshi_c2 &0b01000000){x4_di;} //2G
//if(xianshi_c1 &0b00000000){} //5高
x5_gao;
yanshi(100); //延时
}
/**************************************************/
void xianshi_jisuan() //显示计算
{
xianshi_b1 =xianshi_a1 /100; //取百位
xianshi_b2 =(xianshi_a1 %100)/10; //取十位
xianshi_b3 =xianshi_a1 %10; //取个位
xianshi_c1 =zi1[xianshi_b1]; //取百位字模
xianshi_c2 =zi1[xianshi_b2]; //取十位字膜
xianshi_c3 =zi1[xianshi_b3]; //取个位字膜
}
/**************************************************/
void chushihua() //初始化
{
}
/**************************************************/
void yanshi(unsigned char z1) //延时
{
unsigned char z2,z3;
for(z2=z1;z2>0;z2--)
for(z3=180;z3>0;z3--);
}
/**************************************************/
|