/****************WS281215*7************************//****************QQ:774145445**********************//****************快手:共同学习STM8*****************//*****************20210316*************************/// PMS154C// ______@______// |1 PB4 PB3 16|-0// 0-|2 PB5 PB2 15|-kr// ks-|3 PB6 PB1 14|-kg// |4 PB7 PB0 13|-0// |5 VDD GND 12|// x1-|6 PA7 PA0 11|----WS281215*7// x2-|7 PA6 PA4 10|-kb// |8_PA5__PA3__9|-0//// WS2812B串联15*7//pa0--→→→→→→→→ →→→→→→→|// |// |←←←←←←←← ←←←←←←←|// |// |→→→→→→→→ →→→→→→→|// |// |←←←←←←←← ←←←←←←←|// |// |→→→→→→→→ →→→→→→→|// |// |←←←←←←←← ←←←←←←←|// |
// |→→→→→→→→ →→→→→→→/**************************************************///memory 0x74 ~ 0x7F for stack, vector = 0x0//memory 0x0 ~ 0x73 are free//Check Sum is 0x8C136F//PMS154C : ROM Size : 0x7E8//PMS154C : Last use Code : 0x511 , Remain Free-Code : 0x2D7 [+33] , Remain Free-RAM : 82//ICE : ROM Size : 0x7E8//ICE : Last use Code : 0x50F , Remain Free-Code : 0x2D9 [+33] , Remain Free-RAM : 82/**************************************************/#include "extern.h"byte x_0_1,x_0_2; //显示rambyte x_1_1,x_1_2;byte x_2_1,x_2_2;byte x_3_1,x_3_2;byte x_4_1,x_4_2;byte x_5_1,x_5_2;byte x_6_1,x_6_2;byte shi,fen,miao; //时,分,秒byte dian; //点:byte lv,hong,lan;byte shi_shi,shi_ge; //小时十位,小时个位byte fen_shi,fen_ge; //分钟十位,分钟个位byte qumo_a1;byte zimo_a1,zimo_a2,zimo_a3; //字模byte xian_xian; //显示一次标志位//byte k_a1; //按键调时退出条件/**************************************************/void zimo_0(); //字模0void zimo_1(); //字模1void zimo_2(); //字模2void zimo_3(); //字模3void zimo_4(); //字模4void zimo_5(); //字模5void zimo_6(); //字模6void zimo_7(); //字模7void zimo_8(); //字模8void zimo_9(); //字模9void yi(); //发1void ling(); //发0void shijian_fenjie();//时间分解void qing_ram(); //清ramvoid qumo(); //取模void fuzhi(); //赋值void xianshi(); //显示void xianshi_1(); //显示第一行void xianshi_2(); //显示第二行//反取void xianshi_3(); //显示第三行void xianshi_4(); //显示第四行//反取void xianshi_5(); //显示第五行void xianshi_6(); //显示第六行//反取void xianshi_7(); //显示第七行void xian_1(); //显1void xian_0(); //显0void anjian(); //按键/**************************************************/chuan bit pa.0; //串行口ks bit pb.6; //设置kr bit pb.2; //红色,小时+kg bit pb.1; //绿色,分钟+kb bit pa.4; //蓝色
/**************************************************/void FPPA0 (void){.ADJUST_IC SYSCLK=IHRC/4 // SYSCLK=IHRC/4$ chuan out,low; //输出0$ pb.5 out,low;$ pa.3 out,low;$ pb.0 out,low;$ pb.3 out,low;$ ks in,pull; //输入,上拉电阻$ kr in,pull; //$ kg in,pull;$ kb in,pull;/**************************************************/shi =12;fen =00;miao =0;lv =1;hong =1;lan =1;xian_xian =1;/**************************************************/ //开外部晶体eco$ eoscr enable,32khz;/**************************************************/ //系统时钟切换外部晶体//$ clkmd eosc/1,en_ihrc;//$ clkmd EOSC/8;//goto $+1;/**************************************************/ //timer2定时器500ms中断1次$ tm2c eosc,disable,period;//$ tm2c sysclk,disable,period;//$ tm2s 8bit,/4,/11;$ tm2s 8bit,/64,/32;//tm2ct =0; //计数寄存器(初值)tm2b =16; //上限寄存器/**************************************************/ //中断$ inten tm2; //开中断//$ inten ; //关中断engint //允许全部中断//disgint //停止全部中断/**************************************************/while (1){if(xian_xian) { xian_xian =0; xianshi(); }.delay 500000;anjian();}}/**************************************************/void anjian() //按键{if(ks==0) //调时模式 { if(kr==0) { shi ++; if(shi==24){shi=0;} xian_xian =1; } if(kg==0) { fen ++; if(fen==60){fen=0;} xian_xian =1; } if(kb==0) { lv =0; hong =1; lan =0; xian_xian =1; } return; }
if(kr==0) {hong ++; xian_xian =1;}if(kg==0) {lv ++; xian_xian =1;}if(kb==0) {lan ++; xian_xian =1;}}/**************************************************/void Interrupt (void){pushaf; //入栈
if (Intrq.6){//tm2ct =0; //计数寄存器初值miao++;xian_xian =1;if(dian){dian=0;} else{dian=1;}
if(miao==60) { miao =0; fen ++; if(fen==60) { fen =0; shi ++; if(shi==24) {shi=0;} if(shi==20) { lv =1; hong =1; lan =1; } } }Intrq.6 = 0;
}popaf; //出栈}/**************************************************/ //字模//0 fe 82 fe//1 00 fe 00//2 9e 92 f2//3 92 92 fe//4 70 10 fe//5 f2 92 9e//6 fe 92 9e//7 c0 80 fe//8 fe 92 fe//9 f2 92 fevoid zimo_0() //字模0{zimo_a1 =0xfe;zimo_a2 =0x82;zimo_a3 =0xfe;}void zimo_1() //字模1{zimo_a1 =0x00;zimo_a2 =0xfe;zimo_a3 =0x00;}void zimo_2() //字模2{zimo_a1 =0x9e;zimo_a2 =0x92;zimo_a3 =0xf2;}void zimo_3() //字模3{zimo_a1 =0x92;zimo_a2 =0x92;zimo_a3 =0xfe;}void zimo_4() //字模4{zimo_a1 =0x70;zimo_a2 =0x10;zimo_a3 =0xfe;}void zimo_5() //字模5{ zimo_a1 =0xf2;zimo_a2 =0x92;zimo_a3 =0x9e;}void zimo_6() //字模6{zimo_a1 =0xfe;zimo_a2 =0x92;zimo_a3 =0x9e;}void zimo_7() //字模7{zimo_a1 =0xc0;zimo_a2 =0x80;zimo_a3 =0xfe;}void zimo_8() //字模8{zimo_a1 =0xfe;zimo_a2 =0x92;zimo_a3 =0xfe;}void zimo_9() //字模9{zimo_a1 =0xf2;zimo_a2 =0x92;zimo_a3 =0xfe;}/**************************************************/void yi() //发1{chuan =1;nop;nop;nop;nop;chuan =0;nop;
}
/**************************************************/void ling() //发0{chuan =1;//nop;chuan =0;nop;nop;nop;nop;
}
/**************************************************/void shijian_fenjie() //时间分解{byte shi_b1,fen_b1;shi_shi =0;shi_ge =0;fen_shi =0;fen_ge =0;shi_b1 =shi;fen_b1 =fen;while(shi_b1>9) //小时分解{shi_shi ++; //小时十位shi_b1 -=10;}shi_ge =shi_b1; //小时个位
while(fen_b1>9) //分钟分解{fen_shi ++; //分钟十位fen_b1 -=10;}fen_ge =fen_b1; //分钟个位}/**************************************************/
void qing_ram() //清ram{x_0_1 =0;x_0_2 =0;x_1_1 =0;x_1_2 =0;x_2_1 =0;x_2_2 =0;x_3_1 =0;x_3_2 =0;x_4_1 =0;x_4_2 =0;x_5_1 =0;x_5_2 =0;x_6_1 =0;x_6_2 =0;}/**************************************************/void qumo() //取模{if(qumo_a1==0) {zimo_0(); return;}if(qumo_a1==1) {zimo_1(); return;}if(qumo_a1==2) {zimo_2(); return;}if(qumo_a1==3) {zimo_3(); return;}if(qumo_a1==4) {zimo_4(); return;}if(qumo_a1==5) {zimo_5(); return;}if(qumo_a1==6) {zimo_6(); return;}if(qumo_a1==7) {zimo_7(); return;}if(qumo_a1==8) {zimo_8(); return;}if(qumo_a1==9) {zimo_9(); return;}}
/**************************************************/void fuzhi() //赋值{qumo_a1 =shi_shi; //取模赋值qumo(); //取模//zimo_a1,zimo_a2,zimo_a3; //取回的字模值if(zimo_a1.7) {x_0_1.7 =1;} //小时十位//竖转横if(zimo_a1.6) {x_1_1.7 =1;}if(zimo_a1.5) {x_2_1.7 =1;}if(zimo_a1.4) {x_3_1.7 =1;}if(zimo_a1.3) {x_4_1.7 =1;}if(zimo_a1.2) {x_5_1.7 =1;}if(zimo_a1.1) {x_6_1.7 =1;}
if(zimo_a2.7) {x_0_1.6 =1;}if(zimo_a2.6) {x_1_1.6 =1;}if(zimo_a2.5) {x_2_1.6 =1;}if(zimo_a2.4) {x_3_1.6 =1;}if(zimo_a2.3) {x_4_1.6 =1;}if(zimo_a2.2) {x_5_1.6 =1;}if(zimo_a2.1) {x_6_1.6 =1;}
if(zimo_a3.7) {x_0_1.5 =1;}if(zimo_a3.6) {x_1_1.5 =1;}if(zimo_a3.5) {x_2_1.5 =1;}if(zimo_a3.4) {x_3_1.5 =1;}if(zimo_a3.3) {x_4_1.5 =1;}if(zimo_a3.2) {x_5_1.5 =1;}if(zimo_a3.1) {x_6_1.5 =1;}
qumo_a1 =shi_ge; //取模赋值qumo(); //取模//zimo_a1,zimo_a2,zimo_a3; //取回的字模值if(zimo_a1.7) {x_0_1.3 =1;} //小时个位//竖转横if(zimo_a1.6) {x_1_1.3 =1;}if(zimo_a1.5) {x_2_1.3 =1;}if(zimo_a1.4) {x_3_1.3 =1;}if(zimo_a1.3) {x_4_1.3 =1;}if(zimo_a1.2) {x_5_1.3 =1;}if(zimo_a1.1) {x_6_1.3 =1;}
if(zimo_a2.7) {x_0_1.2 =1;}if(zimo_a2.6) {x_1_1.2 =1;}if(zimo_a2.5) {x_2_1.2 =1;}if(zimo_a2.4) {x_3_1.2 =1;}if(zimo_a2.3) {x_4_1.2 =1;}if(zimo_a2.2) {x_5_1.2 =1;}if(zimo_a2.1) {x_6_1.2 =1;}
if(zimo_a3.7) {x_0_1.1 =1;}if(zimo_a3.6) {x_1_1.1 =1;}if(zimo_a3.5) {x_2_1.1 =1;}if(zimo_a3.4) {x_3_1.1 =1;}if(zimo_a3.3) {x_4_1.1 =1;}if(zimo_a3.2) {x_5_1.1 =1;}if(zimo_a3.1) {x_6_1.1 =1;}
qumo_a1 =fen_shi; //取模赋值qumo(); //取模//zimo_a1,zimo_a2,zimo_a3; //取回的字模值if(zimo_a1.7) {x_0_2.7 =1;} //分钟十位//竖转横if(zimo_a1.6) {x_1_2.7 =1;}if(zimo_a1.5) {x_2_2.7 =1;}if(zimo_a1.4) {x_3_2.7 =1;}if(zimo_a1.3) {x_4_2.7 =1;}if(zimo_a1.2) {x_5_2.7 =1;}if(zimo_a1.1) {x_6_2.7 =1;}
if(zimo_a2.7) {x_0_2.6 =1;}if(zimo_a2.6) {x_1_2.6 =1;}if(zimo_a2.5) {x_2_2.6 =1;}if(zimo_a2.4) {x_3_2.6 =1;}if(zimo_a2.3) {x_4_2.6 =1;}if(zimo_a2.2) {x_5_2.6 =1;}if(zimo_a2.1) {x_6_2.6 =1;}
if(zimo_a3.7) {x_0_2.5 =1;}if(zimo_a3.6) {x_1_2.5 =1;}if(zimo_a3.5) {x_2_2.5 =1;}if(zimo_a3.4) {x_3_2.5 =1;}if(zimo_a3.3) {x_4_2.5 =1;}if(zimo_a3.2) {x_5_2.5 =1;}if(zimo_a3.1) {x_6_2.5 =1;}
qumo_a1 =fen_ge; //取模赋值qumo(); //取模//zimo_a1,zimo_a2,zimo_a3; //取回的字模值if(zimo_a1.7) {x_0_2.3 =1;} //分钟个位//竖转横if(zimo_a1.6) {x_1_2.3 =1;}if(zimo_a1.5) {x_2_2.3 =1;}if(zimo_a1.4) {x_3_2.3 =1;}if(zimo_a1.3) {x_4_2.3 =1;}if(zimo_a1.2) {x_5_2.3 =1;}if(zimo_a1.1) {x_6_2.3 =1;}
if(zimo_a2.7) {x_0_2.2 =1;}if(zimo_a2.6) {x_1_2.2 =1;}if(zimo_a2.5) {x_2_2.2 =1;}if(zimo_a2.4) {x_3_2.2 =1;}if(zimo_a2.3) {x_4_2.2 =1;}if(zimo_a2.2) {x_5_2.2 =1;}if(zimo_a2.1) {x_6_2.2 =1;}
if(zimo_a3.7) {x_0_2.1 =1;}if(zimo_a3.6) {x_1_2.1 =1;}if(zimo_a3.5) {x_2_2.1 =1;}if(zimo_a3.4) {x_3_2.1 =1;}if(zimo_a3.3) {x_4_2.1 =1;}if(zimo_a3.2) {x_5_2.1 =1;}if(zimo_a3.1) {x_6_2.1 =1;}}/**************************************************/void xianshi() //显示{shijian_fenjie(); //时间分解qing_ram(); //清ramfuzhi(); //赋值
xianshi_1(); //显示第一行xianshi_2(); //显示第二行xianshi_3(); //显示第三行xianshi_4(); //显示第四行xianshi_5(); //显示第五行xianshi_6(); //显示第六行xianshi_7(); //显示第七行
}/**************************************************/void xian_1() //显1发送顺序绿红蓝grb{if(lv.7) {yi();} else{ling();}if(lv.6) {yi();} else{ling();}if(lv.5) {yi();} else{ling();}if(lv.4) {yi();} else{ling();}if(lv.3) {yi();} else{ling();}if(lv.2) {yi();} else{ling();}if(lv.1) {yi();} else{ling();}if(lv.0) {yi();} else{ling();}
if(hong.7) {yi();} else{ling();}if(hong.6) {yi();} else{ling();}if(hong.5) {yi();} else{ling();}if(hong.4) {yi();} else{ling();}if(hong.3) {yi();} else{ling();}if(hong.2) {yi();} else{ling();}if(hong.1) {yi();} else{ling();}if(hong.0) {yi();} else{ling();}
if(lan.7) {yi();} else{ling();}if(lan.6) {yi();} else{ling();}if(lan.5) {yi();} else{ling();}if(lan.4) {yi();} else{ling();}if(lan.3) {yi();} else{ling();}if(lan.2) {yi();} else{ling();}if(lan.1) {yi();} else{ling();}if(lan.0) {yi();} else{ling();}}/**************************************************/void xian_0() //显0{byte xian_0_a1;xian_0_a1 =24;while(xian_0_a1--) //重复24次 { ling(); }}/**************************************************/void xianshi_1() //显示第一行{if (x_0_1.7) {xian_1();} else{xian_0();}if (x_0_1.6) {xian_1();} else{xian_0();}if (x_0_1.5) {xian_1();} else{xian_0();}if (x_0_1.4) {xian_1();} else{xian_0();}if (x_0_1.3) {xian_1();} else{xian_0();}if (x_0_1.2) {xian_1();} else{xian_0();}if (x_0_1.1) {xian_1();} else{xian_0();}if (x_0_1.0) {xian_1();} else{xian_0();}
if (x_0_2.7) {xian_1();} else{xian_0();}if (x_0_2.6) {xian_1();} else{xian_0();}if (x_0_2.5) {xian_1();} else{xian_0();}if (x_0_2.4) {xian_1();} else{xian_0();}if (x_0_2.3) {xian_1();} else{xian_0();}if (x_0_2.2) {xian_1();} else{xian_0();}if (x_0_2.1) {xian_1();} else{xian_0();}//if (x_0_2.0) {xian_1();} else{xian_0();}}/**************************************************/void xianshi_2() //显示第二行//反取{//if (x_1_2.0) {xian_1();} else{xian_0();}if (x_1_2.1) {xian_1();} else{xian_0();}if (x_1_2.2) {xian_1();} else{xian_0();}if (x_1_2.3) {xian_1();} else{xian_0();}if (x_1_2.4) {xian_1();} else{xian_0();}if (x_1_2.5) {xian_1();} else{xian_0();}if (x_1_2.6) {xian_1();} else{xian_0();}if (x_1_2.7) {xian_1();} else{xian_0();}
if (x_1_1.0) {xian_1();} else{xian_0();}if (x_1_1.1) {xian_1();} else{xian_0();}if (x_1_1.2) {xian_1();} else{xian_0();}if (x_1_1.3) {xian_1();} else{xian_0();}if (x_1_1.4) {xian_1();} else{xian_0();}if (x_1_1.5) {xian_1();} else{xian_0();}if (x_1_1.6) {xian_1();} else{xian_0();}if (x_1_1.7) {xian_1();} else{xian_0();}
}/**************************************************/void xianshi_3() //显示第三行{if (x_2_1.7) {xian_1();} else{xian_0();}if (x_2_1.6) {xian_1();} else{xian_0();}if (x_2_1.5) {xian_1();} else{xian_0();}if (x_2_1.4) {xian_1();} else{xian_0();}if (x_2_1.3) {xian_1();} else{xian_0();}if (x_2_1.2) {xian_1();} else{xian_0();}if (x_2_1.1) {xian_1();} else{xian_0();}//if (x_2_1.0) {xian_1();} else{xian_0();}
if (dian==1) {xian_1();} else{xian_0();} //显示:
if (x_2_2.7) {xian_1();} else{xian_0();}if (x_2_2.6) {xian_1();} else{xian_0();}if (x_2_2.5) {xian_1();} else{xian_0();}if (x_2_2.4) {xian_1();} else{xian_0();}if (x_2_2.3) {xian_1();} else{xian_0();}if (x_2_2.2) {xian_1();} else{xian_0();}if (x_2_2.1) {xian_1();} else{xian_0();}//if (x_2_2.0) {xian_1();} else{xian_0();}}/**************************************************/void xianshi_4() //显示第四行//反取{//if (x_3_2.0) {xian_1();} else{xian_0();}if (x_3_2.1) {xian_1();} else{xian_0();}if (x_3_2.2) {xian_1();} else{xian_0();}if (x_3_2.3) {xian_1();} else{xian_0();}if (x_3_2.4) {xian_1();} else{xian_0();}if (x_3_2.5) {xian_1();} else{xian_0();}if (x_3_2.6) {xian_1();} else{xian_0();}if (x_3_2.7) {xian_1();} else{xian_0();}
if (x_3_1.0) {xian_1();} else{xian_0();}if (x_3_1.1) {xian_1();} else{xian_0();}if (x_3_1.2) {xian_1();} else{xian_0();}if (x_3_1.3) {xian_1();} else{xian_0();}if (x_3_1.4) {xian_1();} else{xian_0();}if (x_3_1.5) {xian_1();} else{xian_0();}if (x_3_1.6) {xian_1();} else{xian_0();}if (x_3_1.7) {xian_1();} else{xian_0();}}/**************************************************/void xianshi_5() //显示第五行{if (x_4_1.7) {xian_1();} else{xian_0();}if (x_4_1.6) {xian_1();} else{xian_0();}if (x_4_1.5) {xian_1();} else{xian_0();}if (x_4_1.4) {xian_1();} else{xian_0();}if (x_4_1.3) {xian_1();} else{xian_0();}if (x_4_1.2) {xian_1();} else{xian_0();}if (x_4_1.1) {xian_1();} else{xian_0();}//if (x_4_1.0) {xian_1();} else{xian_0();}if (dian==1) {xian_1();} else{xian_0();} //显示:
if (x_4_2.7) {xian_1();} else{xian_0();}if (x_4_2.6) {xian_1();} else{xian_0();}if (x_4_2.5) {xian_1();} else{xian_0();}if (x_4_2.4) {xian_1();} else{xian_0();}if (x_4_2.3) {xian_1();} else{xian_0();}if (x_4_2.2) {xian_1();} else{xian_0();}if (x_4_2.1) {xian_1();} else{xian_0();}//if (x_4_2.0) {xian_1();} else{xian_0();}}/**************************************************/void xianshi_6() //显示第六行//反取{//if (x_5_1.0) {xian_1();} else{xian_0();}if (x_5_2.1) {xian_1();} else{xian_0();}if (x_5_2.2) {xian_1();} else{xian_0();}if (x_5_2.3) {xian_1();} else{xian_0();}if (x_5_2.4) {xian_1();} else{xian_0();}if (x_5_2.5) {xian_1();} else{xian_0();}if (x_5_2.6) {xian_1();} else{xian_0();}if (x_5_2.7) {xian_1();} else{xian_0();}
if (x_5_1.0) {xian_1();} else{xian_0();}if (x_5_1.1) {xian_1();} else{xian_0();}if (x_5_1.2) {xian_1();} else{xian_0();}if (x_5_1.3) {xian_1();} else{xian_0();}if (x_5_1.4) {xian_1();} else{xian_0();}if (x_5_1.5) {xian_1();} else{xian_0();}if (x_5_1.6) {xian_1();} else{xian_0();}if (x_5_1.7) {xian_1();} else{xian_0();}}/**************************************************/void xianshi_7() //显示第七行{if (x_6_1.7) {xian_1();} else{xian_0();}if (x_6_1.6) {xian_1();} else{xian_0();}if (x_6_1.5) {xian_1();} else{xian_0();}if (x_6_1.4) {xian_1();} else{xian_0();}if (x_6_1.3) {xian_1();} else{xian_0();}if (x_6_1.2) {xian_1();} else{xian_0();}if (x_6_1.1) {xian_1();} else{xian_0();}if (x_6_1.0) {xian_1();} else{xian_0();}
if (x_6_2.7) {xian_1();} else{xian_0();}if (x_6_2.6) {xian_1();} else{xian_0();}if (x_6_2.5) {xian_1();} else{xian_0();}if (x_6_2.4) {xian_1();} else{xian_0();}if (x_6_2.3) {xian_1();} else{xian_0();}if (x_6_2.2) {xian_1();} else{xian_0();}if (x_6_2.1) {xian_1();} else{xian_0();}//if (x_6_2.0) {xian_1();} else{xian_0();}}/**************************************************//**************************************************//**************************************************//**************************************************/ |
|