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

📄 stled316_driver.c

📁 包含了8位CRC算化程序
💻 C
字号:
/**************** (c) 2008 ****************************************************   
COMPILER : 		C compiler
FILE     : 		StLed316_Driver.c
DESCRIPTION :	STLed316(led drive chip ) drive program for C language.
VERSION  :  	1.0
DATE	 : 		2008/4/8
Author   : 		Flydragon
*******************************************************************************/
/******************************************************************************
Function:		DelayTime
Description:	Delay time 
Arguments:		time	is delay clock counter
Returns:		none
Notes:			none
*******************************************************************************/
void DelayTime(unsigned char time)
{
	unsigned char i;
	for(i = 0; i< time;i ++)
		{;}
}
/******************************************************************************
Function:		WriteByteData
Description:	write one byte data
Arguments:		data	is write data/command
Returns:		none
Notes:			none
*******************************************************************************/
void WriteByteData(unsigned char data)
{
	unsigned char i;
	
	unsigned char temp;
	
	for(i = 0; i < 8 ;i ++)
		{
		CLK(LOW);
		
		temp =  data & (0x1 << i);
		
		if(temp)
			DATA_OUT(HIGH);
		else
			DATA_OUT(LOW);
		
		CLK(HIGH);
		
		DelayTime(1);
					
		}			
}	  
/******************************************************************************
Function:		ReadByteData
Description:	read one byte data
Arguments:		none
Returns:		read data(byte)
Notes:			none
*******************************************************************************/
unsigned char ReadByteData(void)
{
	unsigned char i;
	unsigned char temp = 0;
	
	for(i = 0; i< 8; i ++)
		{
			
		CLK(LOW);
		
		DelayTime(1);
		
		CLK(HIGH);
		
		DelayTime(1);
		
		if(DATA_IN)
			temp |= 1<< i;
		}
		
	return (temp);
}	
/****************************************************************************
Function:		WriteSTLed316Driver
Description: 	Write data to STLed316 driver	
Arguments:		dataaddress     is stled316 display data address
				sourcaddress 	is  output data start address ;
				byte 			is  data bytes;
Returns:		none
Notes:		
******************************************************************************/
void WriteSTLed316Driver(unsigned char dataaddress ,unsigned char *sourcaddress,unsigned char byte)
{
	unsigned char i;
	
	STB(HIGH);													
	
	STB(LOW);							/* const/vriable brightness,number of digits  congfig */ 
	
	SETDATA(OUT);
	
	WriteByteData(CHIP_CONFIG_ADDRESS + CHIP_CONFIG_PAGE + FIXD_ADDRESS + WRITE_COMMAND);
	
	STB(HIGH);
	
	STB(LOW);
	
	WriteByteData(CHIP_CONFIG_ADDRESS + CHIP_CONFIG_PAGE + FIXD_ADDRESS + WRITE_COMMAND);
		
	WriteByteData(CHIP_CONFIGURATION);
	
	STB(HIGH);
	
	
	STB(LOW);															/* brightness config */
	
	WriteByteData(DIGIT_BRIGHTNESS_PAGE + DIGIT_BRIGHTNESS_ADDRESS + INCREMENT_ADDRESS + WRITE_COMMAND);
	
	STB(HIGH);
	
	STB(LOW);
	
	WriteByteData(DIGIT_BRIGHTNESS_PAGE + DIGIT_BRIGHTNESS_ADDRESS + INCREMENT_ADDRESS + WRITE_COMMAND);
	
	WriteByteData(DIGIT_BRIGHTNESS);
	
	WriteByteData(DIGIT_BRIGHTNESS);
	
	WriteByteData(DIGIT_BRIGHTNESS);
	
	STB(HIGH);
	
																	
	STB(LOW);														/*start write display data */	
	
	WriteByteData(dataaddress + SEGMENT_DATA_PAGE + INCREMENT_ADDRESS + WRITE_COMMAND);
	
	STB(HIGH);
	
	STB(LOW);
	
	WriteByteData(dataaddress + SEGMENT_DATA_PAGE + INCREMENT_ADDRESS + WRITE_COMMAND);
	
	for(i = 0; i < byte ;i ++)
		WriteByteData(*(sourcaddress + i));
		
	STB(HIGH);
	
	STB(LOW);												/* write display on command */ 
	
	WriteByteData(DISPLAY_ON);
	
	CLK(HIGH);
	
	STB(HIGH);	
		
}
/****************************************************************************
Function:		ReadSTLed316Driver
Description: 	Read data from STLed316 driver	
Arguments:		none
Returns:		read data(two bytes,KEY2 DATA is HIGH BYTE,KEY1 DATA is LOW BYTE)
Notes:		
******************************************************************************/
unsigned int ReadSTLed316Driver(void)
{
	
	unsigned char temp1,temp2;
			
	STB(HIGH);
	
	STB(LOW);
	
	SETDATA(OUT);
	
	WriteByteData(KEY_DATA1_ADDRESS + KEY_DATA_PAGE + INCREMENT_ADDRESS + READ_COMMAND);
	
	CLK(LOW);
	
	SETDATA(IN);
	
	temp1 = ReadByteData();
	
	temp2 = ReadByteData();
	
	SETDATA(OUT);
		
	CLK(HIGH);
	
	STB(HIGH);
	
	return (temp1 + (temp2 << 8));
		
				
}

/******2008/4/8*(c)* ******End of file*************************************************/	

⌨️ 快捷键说明

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