1,参考上篇,将LED点阵屏更换成数码管如下图
2,修改驱动函数,数组seg[14]前10个是0-9数字的编码,后四个是空格,点,横线,下划线
char seg_decode(char num)//数字解码
{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)//单个数码管显示
{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()//定时刷新函数,毫秒级调用
{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