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

📄 gvgledtest.c

📁 建立在AVR基础上的测试LED数码管电压表
💻 C
字号:
/******************************************************************************
*	Compiler:		WinAVR(GCC)
*	Device:			ATtiny13
*	File name:		GvgLedTest.c
*	Description:		Main Program

*	Programmer:		Liansen Wang
*	Revision:			1.0
*	Modification time:	2005-08-21	10:11
		
******************************************************************************/

#include "general.h"

//#define ADCEN


unsigned char 	Display_data[Display_bit];
unsigned char		Key_data,Key_data_back;
unsigned char		ADC_value;
unsigned char		IR_Value;

unsigned char		Bit_make;
	#define 		Bit_make_ADC 0x00
	#define 		Bit_make_Display 0x01
	#define		Bit_make_Key	0x02

/*****************************************************************************/
/*============================================================
FUNCTION: 

============================================================*/
void INIT(void)
{
	//Settings DATA\ SCK\ STB\ LED is OUTPUT and IR\ RESET is INPUT
	DDRB = (1<<DATA)|(1<<SCK)|(1<<STB)|(1<<LED);
	
	PORTB = 0xFF;
	
	TIMSK0 = (1<<TOIE0);				//T/C0 
	TCCR0B = (1<< CS02)|(1<<CS00);
	TCNT0 =  0x41;
	sei();							// all interrupt is enabled
#ifdef ADCEN
	ADMUX = (1<<ADLAR)|(1<<MUX1)|(1<<MUX0);
#else
	GIMSK = (1<<PCIE);				// pin change interrupt is enabled 
	PCMSK = (1<<PCINT3);			// select I/O pin of pin chang interrupt	
#endif

}
//*****************************************************************************

/*============================================================

============================================================*/
#ifdef ADCEN
void Voltage_detect(void)
	{
	 unsigned char i;
	 
	ADCSRA = (1<<ADEN)|(1<<ADSC);
	while(ADCSRA & (1<<ADSC))
		{
		;
		}
	
//	for(i=0;i<30;i++);
	Display_All_Bit(0x00);
	Display_data[2]=ADCH;
	if(ADCH & 0x80)	
		{
		Display_data[1] = 0x01;
		}
	else 	
		{
		Display_data[1] =0x00;
		}
	if(ADCH >= 0xA5)
		{
		if(ADCH <= 0xC6)
			{
			if(ADC_value<= 255)	
				{
				ADC_value++;
				}
			}
		else ADC_value= 0;
	
		}
	if(ADC_value>= 1)	
		{
		PORTB &= ~(1<<LED);
		}
	else 
		{
		PORTB |= (1<<LED);
		}
	}

#endif

/*============================================================

============================================================*/
void Key_Prog(void)
{
//if(Key_data == 0x00)
//	PORTB |= LED;
//else
//	PORTB &= ~LED;	

/////////////////////////////////////////////////////////////////
if(Key_data != 0xFF)
	{
	if(Bit_make&(1<<Bit_make_Key) )
		{
//		Display(Key_data);
		switch(Key_data)
			{
			case 00:
				Display(":OFF::::8");
				break;
//			case 02:
//				Display("2");
//				break;
			case 03:
				Display("OPEN:::8:");
				break;
//			case 05:
//				Display("5");
//				break;
			case 010:
				Display("NODISC8::");
				break;
//			case 012:
//				Display("A");
//				break;
			default:
				break;
			}
		}
	Bit_make&= ~(1<<Bit_make_Key);	
	}

else		
	Bit_make|=(1<<Bit_make_Key);
}

/*===========================================================


===========================================================*/
SIGNAL(SIG_PIN_CHANGE0)
	{
	IR_Value=IR_Value_Read();
	Display_data[2]=IR_Value;
	GIFR|=(1<<PCIF);
	}
/*============================================================


============================================================*/

SIGNAL(SIG_OVERFLOW0)
	{
	TCNT0 =  0x41;
	Bit_make|=(1<<Bit_make_Display);
	}

/*============================================================


============================================================*/
int main(void)
{
INIT();
while(1)
	{
	if(Bit_make&(1<<Bit_make_Display))
		{	
		PORTB ^=(1<<LED);
		Key_data=V_Kay_Scan();
		V_DISPLAYDATA_SEND(); 
		Key_Prog();


		#ifdef ADCEN
			if(Bit_make & (1<<Bit_make_ADC))
				{
				Voltage_detect();
				}
		#endif;
		
		PORTB ^=(1<<LED);		
		Bit_make&=~(1<<Bit_make_Display);		
		}

	}
}

⌨️ 快捷键说明

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