c 做交易網(wǎng)站谷歌外貿(mào)
1,參考上篇,將LED點陣屏更換成數(shù)碼管如下圖
2,修改驅動函數(shù),數(shù)組seg[14]前10個是0-9數(shù)字的編碼,后四個是空格,點,橫線,下劃線
char seg_decode(char num)//數(shù)字解碼
{const char seg[14]={0xC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90, 0xff,0x7f,0xbf,0xf7};return seg[num];
}
void disp_set_row(unsigned char dat,char sel)//單個數(shù)碼管顯示
{GPIOB->ODR=0xff;GPIOA->ODR=~seg_decode(dat);switch(sel){case 0:GPIOB->ODR=0xfe;break;case 1:GPIOB->ODR=0xfd;break;case 2:GPIOB->ODR=0xfb;break;case 3:GPIOB->ODR=0xf7;break;case 4:GPIOB->ODR=0xef;break;case 5:GPIOB->ODR=0xdf;break;case 6:GPIOB->ODR=0xbf;break;case 7:GPIOB->ODR=0x7f;break;}
}
unsigned char dispbuff[8];
void disp_scan()//定時刷新函數(shù),毫秒級調(diào)用
{static char scan=0;disp_set_row(dispbuff[scan],scan);scan++;if(scan>=8)scan=0;
}
char char_decode(char ch)//字符解碼
{if((ch>='0')&&(ch<='9'))return ch-'0';else if(ch == ' ')return 10;else if(ch =='.')return 11;else if(ch =='-')return 12;else if(ch =='_')return 13;else return 10;
}
void disp_string(char *str)//字符串顯示
{char len = strlen(str);char i;if(len>8)len=8;memset(dispbuff,10,8);for(i=0;i<len;i++){dispbuff[i]=char_decode(str[i]);}
}void key1_action()//更新屏幕字符
{disp_string("1.4 -2_5");
}
void key2_action()//更新屏幕字符
{disp_string("12-30-00");
}
git源碼:stm32_proutes: Protues仿真STM32單片機教程源碼-WWW.ARMFUN.CN