www.pudn.com > 74hc595-STM8.rar > hC595-drive.c, change:2015-04-01,size:1834b


#include "type_def.h" 
#include "hc595-drive.h" 
 
/*************	本地常量声明	**************/ 
u8  t_display[]={ 
//	 0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F   消隐 
	0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x00};	//段码 
 
u8  T_COM[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};		//位码 
 
 
 
 
u8 	LED8[8];		//显示缓冲 
u8	display_index;	//显示位索引 
 
 
void H595_Init() 
{ 
   //SER 推挽输出 
  PC_DDR_DDR2 =1;       
  PC_CR1_C12 =1; 
  PC_CR2_C22 =0; 
  //RCLk推挽输出 
  PC_DDR_DDR3 =1;       
  PC_CR1_C13 =1; 
  PC_CR2_C23 =0; 
  //SRCLK 推挽输出 
  PC_DDR_DDR4 =1;       
  PC_CR1_C14 =1; 
  PC_CR2_C24 =0; 
 
} 
 
 
 
/**** 
void main(void) 
{ 
	unsigned char	i,k; 
	unsigned int	j; 
	 
	 
 
	for(i=0; i<8; i++)	LED8[i] = 0x10;	//上电消隐 
	j = 0; 
	k = 0; 
 
	 
	while(1) 
	{ 
		while(!B_1ms)	;	//等待1ms到 
		B_1ms = 0; 
		if(++j >= 500)		//500ms到 
		{ 
			j = 0; 
			for(i=0; i<8; i++)	LED8[i] = k;	//刷新显示 
			if(++k > 0x10)	k = 0;				//8个数码管循环显示0,1,2...,A,B..F,消隐. 
		} 
	} 
}  
**/ 
 
 
 
/**********************************************/ 
void Send_595(unsigned char dat)	//发送一个字节 
{		 
	unsigned char	i; 
	for(i=0; i<8; i++) 
	{ 
		if(dat & 0x80)	P_HC595_SER = 1; 
		else			P_HC595_SER = 0; 
		P_HC595_SRCLK = 1; 
		P_HC595_SRCLK = 0; 
		dat = dat << 1; 
	} 
} 
 
/**********************************************/ 
void DisplayScan(void)	//显示扫描函数 
{	 
	Send_595(~T_COM[display_index]);			//共阴	输出位码 
	Send_595(t_display[LED8[display_index]]);	//共阴	输出段码 
	//Send_595(T_COM[display_index]);				//共阳	输出位码 
	//Send_595(~t_display[LED8[display_index]]);	//共阳	输出段码 
	P_HC595_RCLK = 1; 
	P_HC595_RCLK = 0;							//锁存输出数据 
	if(++display_index >= 8)	display_index = 0;	//8位结束回0 
}