📄 led_display.c
字号:
#include "common.h"
#include "led_display.h"
/*
共阴极数码管
___A___
| |
F B
| |
___G___
| |
E C
| |
___D___ .H
数据位 D7 D6 D5 D4 D3 D2 D1 D0 字形码
笔段位 H G F E D C B A
. 1 0 0 0 0 0 0 0 80H
0 0 0 1 1 1 1 1 1 3FH
1 0 0 0 0 0 1 1 0 06H
. .
. .
. .
F 0 1 1 1 0 0 0 1 71H
*/
uchar disp_table[16]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
}
;
uchar dp ;
uchar count=12 ;
//初始化程序********************************************************************
void disp_Initial(void)
{
DDR=0x03 ;
ClearAll();
}
//清除LED***********************************************************************
void ClearAll(void)
{
uchar i ;
for(i=0;i<8;i++)
send_byte(0x00);
}
//对一个164进行操作 ************************************************************
void send_byte(uchar x)
{
uchar i ;
for(i=0;i<8;i++)
{
cbi_clk();
// 产生164时钟信号,
//判断每位数据的电平,及小数点判断
if((x&(1<<(7-i)))||((dp==1)&&(i==0)))sbi_data();
//若为高则输出高电平
else
cbi_data();
//若为低则输出低电平
sbi_clk();
// 产生164时钟信号,上升沿
}
}
//输出8位以内的整数*************************************************************
void PrintInt(long m_lData)
{
long temp=10000000 ;
//当temp=10000000时,显示8位整数
long i ;
ClearAll();
i=m_lData/temp ;
while(i==0)
{
send_byte(0x00);
temp/=10 ;
i=m_lData/temp ;
}
while(temp)
{
send_byte(disp_table[(uchar)(m_lData/temp)]);
m_lData=m_lData%temp ;
temp/=10 ;
}
}
//用于显示8位以内的浮点数 ******************************************************
/*
void PrintFloat(float m_lData)
{
long temp=10000000 ;
uchar i,j=8,m,dot_position=0 ;
i=m_lData/temp ;
while(i==0)
{
temp/=10 ;
i=m_lData/temp ;
dot_position++;
if(dot_position==7) i=1 ;
}
for(m=0;m<dot_position;m++)
m_lData*=10 ;
temp=10000000 ;
while(temp)
{
if(j==dot_position+1)
dp=1 ;
j--;
send_byte(disp_table[(uchar)(m_lData/temp)]);
m_lData=(long)m_lData%temp ;
temp/=10 ;
dp=0 ;
}
}*/
void PrintFloat(float m_lData)
{
uchar i=8,j,dot_position,count=0 ;
long temp=10000000,dot_temp ;
//当temp=10000000时,显示8位整数
dp=0 ;
long integer ;
float dot ;
integer=(long)m_lData ;
dot=m_lData-(float)integer ;
if(integer==0)
{
integer=0 ;
count=7 ;
}
else
while(integer/10000000==0)
{
integer*=10 ;
count++;
}
for(j=0;j<count;j++)
dot=dot*10 ;
dot_temp=(long)dot ;
integer+=dot_temp ;
dot_position=count+1 ;
while(temp)
{
if(i==dot_position)
dp=1;
i--;
send_byte(disp_table[(uchar)(integer/temp)]);
integer=integer%temp ;
temp/=10 ;
dp=0 ;
}
}
/*void PrintFloat(long m_lData,uchar dot_position)
{
uchar i=3;
long temp=100; //当temp=10000000时,显示8位整数
dp=0;
while(temp)
{
if(i==dot_position)
dp=1;
i--;
send_byte(disp_table[m_lData/temp]);
m_lData=m_lData%temp;
temp/=10;
dp=0;
}
}*/
//用于显示字符******************************************************************
void PrintChar(uchar m_Char)
{
if((m_Char>='0')&&(m_Char<='9'))
send_byte(disp_table[m_Char-'0']);
else if((m_Char>='A')&&m_Char<='F')
send_byte(disp_table[m_Char-'A'+10]);
else if((m_Char>='a')&&m_Char<='f')
send_byte(disp_table[m_Char-'a'+10]);
}
//用于显示字符串****************************************************************
void PrintString(uchar *str)
{
uchar i=0,j=0 ;
ClearAll();
for(i=8;i>0;i--)
{
if(*(str+i-1))PrintChar(*(str+8-j-i));
else
{
send_byte(0x00);
j++;
}
}
}
/*
//显示程序 CONTROL为控制显示 BUFFER为显示数据
void disp_led(uchar buffer,uchar control)
{
uchar i,temp[6];
uint tempcount;
dp=0;
switch(control)
{
case 0: //CONTROL为零全部数码管显示buffer
{
for(i=0;i<11;i++)
send_byte(disp_table[buffer%10]);//显示数字
break;
}
case 1: //control为1,显示count中的数据为6位
{
tempcount=count;
for(i=0;i<6;i++) //取出每位中的数据
{
temp[i]=tempcount%10;
tempcount/=10;
}
send_byte(disp_table[buffer/10]); //最开始显示buffer数据
send_byte(disp_table[buffer%10]);
send_byte(0x00);
send_byte(0x00);
send_byte(0x00);
for(i=0;i<6;i++)
{
if(i==4)
dp=1; //小数点控制位
send_byte(disp_table[temp[5-i]]);
dp=0;
}
break;
}
}
sbi_data();
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -