- 打卡等级:偶尔看看I
- 打卡总天数:16
- 最近打卡:2025-03-02 11:27:25
已绑定手机
注册会员
- 积分
- 111
|
发表于 2025-1-12 14:45:17
|
显示全部楼层
第九课,数码管
#include "hc595.h"
/*====================================================================================================
函 数 :void HC595_Write(unsigned char dat)
参 数 :
返回值 :
描 述 :
======================================================================================================
备 注 HC595写数据
======================================================================================================*/
void HC595_Write(unsigned char dat)
{
unsigned char temp = 0X80;
HC595_SCK = 0;
HC595_SCK = 0;
for(temp = 0X80;temp != 0;temp >>= 1)
{
if(dat & temp)
HC595_SER = 1;
else
HC595_SER = 0;
HC595_SCK = 0;
HC595_SCK = 1;
}
}
/*====================================
函 数 :unsigned char Display_8_we[]
参 数 :
返回值 :
描 述 :8位共阴级数码管位选
====================================
====================================*/
unsigned char Display_8_we[]={~0x80,~0x40,~0x20,~0x10,~0x08,~0x04,~0x02,~0x01};
/*====================================
函 数 :unsigned char Display_8_du[]
参 数 :
返回值 :
描 述 :8位共阳级数码管段选
====================================
====================================*/
unsigned char Display_8_du[]={
0x3F, //"0"
0x06, //"1"
0x5B, //"2"
0x4F, //"3"
0x66, //"4"
0x6D, //"5"
0x7D, //"6"
0x07, //"7"
0x7F, //"8"
0x6F, //"9"
0x77, //"A"
0x7C, //"B"
0x39, //"C"
0x5E, //"D"
0x79, //"E"
0x71, //"F"
0x76, //"H"
0x38, //"L"
0x37, //"n"
0x3E, //"u"
0x73, //"P"
0x5C, //"o"
0x40, //"-"
0x00, //熄灭
0x00 //自定义
};
/*====================================
函 数 :unsigned char LedDisplay[]
参 数 :
返回值 :
描 述 :数码管显示缓存
====================================
====================================*/
unsigned char LedDisplay[] = {0,1,2,3,4,5,6,7};
/*====================================
函 数 :void HC595_Drive(unsigned char we,unsigned char du)
参 数 :unsigned char we 数码管位选 unsigned char du 数码管段选
返回值 :
描 述 :
====================================
74HC595是从高位开始传输
====================================*/
void HC595_Drive(unsigned char we,unsigned char du)
{
HC595_Write(du);
HC595_Write(we);
//上升沿 数据从移位寄存器 转移至储存寄存器 这里要看OE的引脚 如果是低电平就输出了 如果不是后面则要加上OE = 0;
HC595_RCK = 0;
HC595_RCK = 1;
}
/*====================================
函 数 :void Display_Show()
参 数 :
返回值 :
描 述 :数码管显示函数
====================================
====================================*/
void Display_Show()
{
static unsigned char i = 0;
// HC595_Drive(0X00,0Xff);//消隐 共阳极数码管 段:0 位:1 是关闭
//分别依次扫描8位8段数码管显示 &0X7F是显示小数点
switch(i)
{
case 0:HC595_Drive(Display_8_we[i],Display_8_du[LedDisplay[0]]); break;
case 1:HC595_Drive(Display_8_we[i],Display_8_du[LedDisplay[1]]); break;
case 2:HC595_Drive(Display_8_we[i],Display_8_du[LedDisplay[2]]); break;
case 3:HC595_Drive(Display_8_we[i],Display_8_du[LedDisplay[3]]); break;
case 4:HC595_Drive(Display_8_we[i],Display_8_du[LedDisplay[4]]); break;
case 5:HC595_Drive(Display_8_we[i],Display_8_du[LedDisplay[5]]); break;
case 6:HC595_Drive(Display_8_we[i],Display_8_du[LedDisplay[6]]); break;
case 7:HC595_Drive(Display_8_we[i],Display_8_du[LedDisplay[7]]); break;
default:break;
}
i++;
if(i > 7)
i = 0;
} |
|