⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 disp_小数点0005.c

📁 单片机C语言15个实验附有原理图和程序 是我的课程作业 以经过实践验证
💻 C
字号:
#include <stdio.h>
#include <reg51.h>
#include <intrins.h>
#define hi 0x3c
#define lo 0xb0
float disp_value=5;
unsigned char code ledk[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6D,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
unsigned char mask=0xee,point=0,i=0,disp[4],key,key_flag,key_count,t0_count;
sbit P37=P3^7;sbit clk=P0^7;sbit sda=P0^6;//74LS164
void delay(unsigned int n)
{ unsigned int i,j;
  for(i=0;i<n;i++)
     for(j=0;j<n;j++)
       ;}
void shift(unsigned char dx)
{ unsigned char j=0;
 while(j<8)
	{if((dx&0x80)!=0) sda=1;
       else  sda=0;
	   clk=0;clk=1;
	   dx<<=1;j++;}  }
void hextodec(float yy)
 {unsigned int xx;
  if(yy>=1)xx=(int)(yy);
  if(yy<1 && yy>=0.1)xx=(int)(yy*10);
  if(yy<0.1 && yy>=0.01)xx=(int)(yy*100);
  if(yy<0.01 && yy>=0.001)xx=(int)(yy*1000);
  disp[3]=xx/1000; xx=xx%1000;
  disp[2]=xx/100;  xx=xx%100;
  disp[1]=xx/10;           
  disp[0]=xx%10;
  if(yy>=1){disp[3]=16;disp[2]=16;disp[1]=16;}  
  if(yy<1 && yy>=0.1){disp[3]=16;disp[2]=16;} 
  if(yy<0.1 && yy>=0.01)disp[3]=16; 
  }
void display()
{ if((point!=4 && point!=0) && point==i)shift(ledk[disp[i]]|0x80);
			    else shift(ledk[disp[i]]);  }
void t0() interrupt 1 
 {TH0=hi;TL0=lo;t0_count++;key_count++;
   if(t0_count==20)t0_count=0;
   if(key_count>10)key_count=0; }
unsigned char get_char(void)
 {unsigned char	key_code;
  static unsigned char column=0;
  if(P37==0 && key_flag==1){key_code=column;key_flag=0;key_count=0;}
        else key_code=0xff;
  mask=_crol_(mask,1);i++;if(i>3)i=0;
  column++; if(column>3)column=0; 
  return(key_code);}
void key_func(key)
 {switch (key)
   {case 0:  disp_value=disp_value/10;point++;
            if(point==4){point=0;disp_value=5;}
      break;
    default: break;}  }
void main(void)
{ TMOD=0x01; TH0=hi;TL0=lo; EA=1;ET0=1;TR0=1; 
while(1)
 {key=get_char( );key_func(key);
  hextodec(disp_value);
  display(); P2=mask;
  delay(22);
  if(key_flag==0 && key_count==10 && P37==1)key_flag=1;    
 }		   
 }



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -