|
7219数码管模实现显示正负浮点数字的程序。自动选择位数,末尾0不显示
下面是模块的电路图:
- void Show_num(double Num)
- {
- unsigned char point = 0;
- unsigned char negative = 0;//负数标记
- unsigned char i = 0;
- unsigned char n;
- unsigned char tab[8]={0,0,0,0,0,0,0,0};
- Write_Max7219(0x0f, 0x00); //显示测试:1;测试结束,正常显示:0
- if(Num < 0){
- Num = -Num;
- negative = 1; //负数
- }
- if(Num>=0 && Num<10){
- Num = Num * 10000000;
- point = 8;
- }else if(Num>=10 && Num<100){
- Num = Num * 1000000;
- point = 7;
- }else if(Num>=100 && Num<1000){
- Num = Num * 100000;
- point = 6;
- }else if(Num>=1000 && Num<10000){
- Num = Num * 10000;
- point = 5;
- }else if(Num>=10000 && Num<100000){
- Num = Num * 1000;
- point = 4;
- }else if(Num>=100000 && Num<1000000){
- Num = Num * 100;
- point = 3;
- }else if(Num>=1000000 && Num<10000000){
- Num = Num * 10;
- point = 2;
- }else if(Num>=10000000 && Num<100000000){
- Num = Num * 1;
- point = 1;
- }
-
- if(negative == 1){
- tab[7] = 10;
- for(i=7;i>0;i--){
- n = Num/10000000;
- if(i == point-1){
- tab[i-1] = n+0x80;
- }else
- tab[i-1] = n;
- Num = (Num-(n*10000000))*10;
- }
- }else{
- for(i=8;i>0;i--){
- n = Num/10000000;
- if(i == point){
- tab[i-1] = n+0x80;
- }else
- tab[i-1] = n;
- Num = (Num-(n*10000000))*10;
- }
- }
- i=0;
- while(1){
- if(tab[i] == 0){
- tab[i] = 15;
- i++;
- }else{
- break;
- }
- }
- for(i=8;i>0;i--){
- Write_Max7219(i,tab[i-1]);
- }
- }
复制代码
|
-
-
main.rar
1.09 KB, 下载次数: 24, 下载积分: 黑币 -5
源代码
评分
-
查看全部评分
|