#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,Display_8_du]);break;
case 1:HC595_Drive(Display_8_we,Display_8_du]); break;
case 2:HC595_Drive(Display_8_we,Display_8_du]); break;
case 3:HC595_Drive(Display_8_we,Display_8_du]);break;
case 4:HC595_Drive(Display_8_we,Display_8_du]);break;
case 5:HC595_Drive(Display_8_we,Display_8_du]);break;
case 6:HC595_Drive(Display_8_we,Display_8_du]); break;
case 7:HC595_Drive(Display_8_we,Display_8_du]); break;
default:break;
}
i++;
if(i > 7)
i = 0;
} #ifndef __HC595_H__
#define __HC595_H__
#include "all.h"
sbit HC595_SER = P3^4;//数据输入
sbit HC595_RCK = P3^5;//锁存寄存器时钟
sbit HC595_SCK = P3^2;//数据输入时钟
extern unsigned char LedDisplay[];
void Display_Show();
#endif 第十二课,开门狗 外部中断
页:
1
[2]