- /****************NY8TE64A触摸实验*******************/
- /****************ID:共同学习stm8********************/
- /****************20240707**************************/
- /**************************************************/
- // gnd-|1‾vss‾‾\_/‾‾vdd‾20|-5v
- // -|2 pa6 N pa4 19|-x1
- // -|3 pa7 Y pa3 18|-x2
- // -|4 pa5 8 pa2 17|-x3
- // -|5 pb3 T pa1 16|-x4
- // -|6 pb2 E pa0 15|-x5
- // -|7 pb1 6 pb5 14|-x6
- // -|8 pb0 4 pb4 13|-x7
- // -|9 pc0 A pb6 12|-x8
- // -|10_pc1______pb7_11|-x9
- /**************************************************/
- // ___a___ _______ _______ _______
- //| | | | | | | |
- //f b | | ◇ | | | |
- // ---g--- ------- ------- -------
- //| | | | ◇ | | | |
- //e c | | | | | |
- // ‾‾‾d‾‾‾ ‾‾‾‾‾‾‾ ‾‾‾‾‾‾‾ ‾‾‾‾‾‾‾
- // @x1 @x2 @x3 @x4 @x5 @x6 @x7 @x8 @x9
- // | | | | | | | | |
- // PA4 PA3 PA2 PA1 PA0 PB5 PB4 PB6 PB7
- //x1--a--x2 x2--►--x3 x3--►--x4 x4--►--x5
- //x1--►--x3 x2--►--x4 x3--►--x5 x4--►--x6
- //x1--►--x4 x2--►--x5 x3--►--x6 x4--►--x7 x9--►--|
- //x1--d--x5 x2--►--x6 x3--►--x7 x4--►--x8 x9--►--|
- //x1--►--x6 x2--►--x7 x3--►--x8 x4--►--x1 ↓
- //x1--►--x7 x2--►--x8 x3--►--x1 x4--►--x2
- //x1--g--x8 x2--►--x1 x3--►--x2 x4--►--x3
- /**************************************************/
- #include <ny8.h>
- /**************************************************/
- __sbit x1 =PORTA:4;
- __sbit x2 =PORTA:3;
- __sbit x3 =PORTA:2;
- __sbit x4 =PORTA:1;
- __sbit x5 =PORTA:0;
- __sbit x6 =PORTB:5;
- __sbit x7 =PORTB:4;
- __sbit x8 =PORTB:6;
- __sbit x9 =PORTB:7;
- /**************************************************/
- #define x1_gao IOSTA&=~(1<<4);x1=1
- #define x1_di IOSTA&=~(1<<4);x1=0
- #define x1_zu IOSTA|=1<<4;
- #define x2_gao IOSTA&=~(1<<3);x2=1
- #define x2_di IOSTA&=~(1<<3);x2=0
- #define x2_zu IOSTA|=1<<3;
- #define x3_gao IOSTA&=~(1<<2);x3=1
- #define x3_di IOSTA&=~(1<<2);x3=0
- #define x3_zu IOSTA|=1<<2;
- #define x4_gao IOSTA&=~(1<<1);x4=1
- #define x4_di IOSTA&=~(1<<1);x4=0
- #define x4_zu IOSTA|=1<<1;
- #define x5_gao IOSTA&=~(1<<0);x5=1
- #define x5_di IOSTA&=~(1<<0);x5=0
- #define x5_zu IOSTA|=1<<0;
- #define x6_gao IOSTB&=~(1<<5);x6=1
- #define x6_di IOSTB&=~(1<<5);x6=0
- #define x6_zu IOSTB|=1<<5;
- #define x7_gao IOSTB&=~(1<<4);x7=1
- #define x7_di IOSTB&=~(1<<4);x7=0
- #define x7_zu IOSTB|=1<<4;
- #define x8_gao IOSTB&=~(1<<6);x8=1
- #define x8_di IOSTB&=~(1<<6);x8=0
- #define x8_zu IOSTB|=1<<6;
- #define x9_gao IOSTB&=~(1<<7);x9=1
- #define x9_di IOSTB&=~(1<<7);x9=0
- #define x9_zu IOSTB|=1<<7;
- /**************************************************/
- unsigned char const zi1[]={
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, //0-9
- 0x77,0x7c,0x39,0x5e,0x79,0x71,0x7e, //a-f,20
- 0x00,0x00,0x00}; //不显
- unsigned char const zi12[]={
- 0x77,0x7c,0x39,0x5e,0x79, //a-e
- 0x71,0x6f,0x76,0x04,0x1e, //f-J
- 0x78,0x38,0x55,0x54,0x5c, //k-o
- 0X73,0X67,0X50,0X49,0X31, //p-t
- 0X3e,0X1c,0X1f,0X52,0X6e,0X5b};//u-z
- /**************************************************/
- static unsigned char xian_b1; //第一个数码管要显示的数据
- static unsigned char xian_b2; //第二个数码管要显示的数据
- static unsigned char xian_b3; //第三个数码管要显示的数据
- static unsigned char xian_b4; //第四个数码管要显示的数据
- static unsigned char xian_c1; //第一个数码管要显示的字模
- static unsigned char xian_c2; //第二个数码管要显示的字模
- static unsigned char xian_c3; //第三个数码管要显示的字模
- static unsigned char xian_c4; //第四个数码管要显示的字模
- static unsigned char xian_c5; //点点
- /**************************************************/
- void xianshi(); //显示
- void xianshi_jisuan(); //显示计算
- void yanshi(); //延时
- /**************************************************/
- void main(void)
- {
- /**************************************************/
- static unsigned int xian_a1; //计次
- static unsigned int xian_a2;
- unsigned int a1 =0;
- unsigned char a2 =0;
- /**************************************************/
- WDTEN =0; //关闭WDT,关狗
- /**************************************************/
- xian_c1=zi1[a1+0];
- xian_c2=zi1[a1+1];
- xian_c3=zi1[a1+2];
- xian_c4=zi1[a1+3];
- /**************************************************/
- while(1)
- {
- xian_a1 ++;
- if(xian_a1 ==435) //显示50HZ
- {
- xian_a1 =0;
- xian_a2 ++;
- if(xian_a2 ==100){/*xian_c5 =1;*/} //点点
- if(xian_a2 >200)
- {
- xian_a2 =0;
- xian_c5 =0;
- xian_b1 =a1+0;
- xian_b2 =a1+1;
- xian_b3 =a1+2;
- xian_b4 =a1+3;
- a1 ++;
- if(a1 >16){a1 =0;}
- xianshi_jisuan();
- }
- xianshi();
- }
- }
- /**************************************************/
- }
- /**************************************************/
- void yanshi() //延时
- {
- unsigned int z1,z2;
- for(z1=200;z1>0;z1--)
- for(z2=500;z2>0;z2--);
- }
- /**************************************************/
- void xianshi_jisuan() //显示计算
- {
- xian_c1 =zi1[xian_b1];
- xian_c2 =zi1[xian_b2];
- xian_c3 =zi1[xian_b3];
- xian_c4 =zi1[xian_b4];
- }
- /**************************************************/
- void xianshi() //显示
- {
- //static unsigned char xian_a1; //计次
- static unsigned char xian_a2; //状态数码管1234
- xian_a2 ++;
- if(xian_a2 ==4){xian_a2 =0;}
- if(xian_a2 ==0) //第一个数码管算法
- {
- x1_di;
- if(xian_c1&0b00000001){x2_di;} else{x2_zu;} //a
- if(xian_c1&0b00000010){x3_di;} else{x3_zu;} //b
- if(xian_c1&0b00000100){x4_di;} else{x4_zu;} //c
- if(xian_c1&0b00001000){x5_di;} else{x5_zu;} //d
- if(xian_c1&0b00010000){x6_di;} else{x6_zu;} //e
- if(xian_c1&0b00100000){x7_di;} else{x7_zu;} //f
- if(xian_c1&0b01000000){x8_di;} else{x8_zu;} //g
- x1_gao;
- }
- if(xian_a2 ==1) //第二个数码管算法
- {
- x2_di;
- if(xian_c2&0b00000001){x3_di;} else{x3_zu;}
- if(xian_c2&0b00000010){x4_di;} else{x4_zu;}
- if(xian_c2&0b00000100){x5_di;} else{x5_zu;}
- if(xian_c2&0b00001000){x6_di;} else{x6_zu;}
- if(xian_c2&0b00010000){x7_di;} else{x7_zu;}
- if(xian_c2&0b00100000){x8_di;} else{x8_zu;}
- if(xian_c2&0b01000000){x1_di;} else{x1_zu;}
- x2_gao;
- }
- if(xian_a2 ==2) //第三个数码管算法
- {
- x3_di;
- if(xian_c3&0b00000001){x4_di;} else{x4_zu;}
- if(xian_c3&0b00000010){x5_di;} else{x5_zu;}
- if(xian_c3&0b00000100){x6_di;} else{x6_zu;}
- if(xian_c3&0b00001000){x7_di;} else{x7_zu;}
- if(xian_c3&0b00010000){x8_di;} else{x8_zu;}
- if(xian_c3&0b00100000){x1_di;} else{x1_zu;}
- if(xian_c3&0b01000000){x2_di;} else{x2_zu;}
- x3_gao;
- }
- if(xian_a2 ==3) //第四个数码管算法
- {
- x4_di;
- if(xian_c4&0b00000001){x5_di;} else{x5_zu;}
- if(xian_c4&0b00000010){x6_di;} else{x6_zu;}
- if(xian_c4&0b00000100){x7_di;} else{x7_zu;}
- if(xian_c4&0b00001000){x8_di;} else{x8_zu;}
- if(xian_c4&0b00010000){x1_di;} else{x1_zu;}
- if(xian_c4&0b00100000){x2_di;} else{x2_zu;}
- if(xian_c4&0b01000000){x3_di;} else{x3_zu;}
- x4_gao;
- }
- if(xian_c5==1){x9_gao;} else{x9_di;}
- }
- /**************************************************/
- /**************************************************/
- /**************************************************/