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

📄 lio.c

📁 UCOS-II ATMEGA128 移殖
💻 C
字号:
#include <mega8.h>
#include "lio.h"
// I2C Bus functions
#asm
   .equ __i2c_port=0x15
   .equ __sda_bit=4
   .equ __scl_bit=5
#endasm
#include <i2c.h>
//#include "lcd.h"
//#include "pic_db.h"

void Hardware_init(void)
{	
	// Declare your local variables here

	// Input/Output Ports initialization
	// Port B initialization
	// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=In Func7=In
	// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=T State7=T
	PORTB=0x00;
	DDRB=0x3F;

	// Port C initialization
	// Func0=In Func1=In Func2=In Func3=Out Func4=In Func5=In Func6=In
	// State0=T State1=T State2=0 State3=0 State4=T State5=T State6=T
	PORTC=0x00;
	DDRC=0x08;

	// Port D initialization
	// Func0=In Func1=In Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out
	// State0=T State1=T State2=0 State3=0 State4=0 State5=0 State6=0 State7=0
	PORTD=0x00;
	DDRD=0xFC;

	// Timer/Counter 0 initialization
	// Clock source: System Clock
	// Clock value: Timer 0 Stopped
	TCCR0=0x05;
	TCNT0=0xDC;

	// Timer/Counter 1 initialization
	// Clock source: System Clock
	// Clock value: Timer 1 Stopped
	// Mode: Normal top=FFFFh
	// OC1A output: Discon.
	// OC1B output: Discon.
	// Noise Canceler: Off
	// Input Capture on Falling Edge
	TCCR1A=0x00;
	TCCR1B=0x00;
	TCNT1H=0x00;
	TCNT1L=0x00;
	OCR1AH=0x00;
	OCR1AL=0x00;
	OCR1BH=0x00;
	OCR1BL=0x00;



	// External Interrupt(s) initialization
	// INT0: Off
	// INT1: Off
	MCUCR=0x80;

	// Timer(s)/Counter(s) Interrupt(s) initialization
//	TIMSK=0x01;

	// Analog Comparator initialization
	// Analog Comparator: Off
	// Analog Comparator Input Capture by Timer/Counter 1: Off
	// Analog Comparator Output: Off
	ACSR=0x80;
	SFIOR=0x00;
//	Timer0_init();
	i2c_init();
	ADC_init();

}

void Software_init(void)
{                       

//	Lcd_init();

//	menu_init();
//	#asm("sei");
}
  
  
/********************************************************************************************/
/*				ADC初始化	
/********************************************************************************************/
void ADC_init(void)
{
 	ADMUX = ADC_KEY_CHANNEL;    		//ADC1            
	ADCSRA = 0xc7;  
}


/********************************************************************************************/
//			写显示     
//
//闪烁某一位只要置位:
//	LED_twinkle_bits; 
//闪烁要配合主程序用;
//
/********************************************************************************************/

unsigned char flash seg_tbl[] = 
{                              
//ASCII:SPACE HEX:0x20
0x0,			//SPACE	   
0x0,   
0x0,   
0x0,   
0x0,   
0x0,   
0x0,   
0x0,   

0x0,   
0x0,   
0x0,   
0x0,   
0x0,   
0x0,   
0x0,   
0x0,   


0x3f,			//0
0x06,
0x5b,
0x4f,
0x66,
0x6d,
0x7d,
0x07,
0x7f,
0x6f,                   //9
				           
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,		      	//  7个符号	                    
		                        			
 	           0x77,		//a
 	           0x7c,		//b
 	           0X39,
 	           0x3f,		//d
 	           0x79,
 	           0x71,             	//  A,B,C,D,E,F
				           
 	           0x6f,		//"g"
 	           0x76,
 	           0x06,
 	           0x0e,		//"j"
 	           0x70,
 	           0x38,             	//  G,H,I,J,K,L
				           
 	           0x37,		//m->"n"
 	           0x37,        	//n
 	           0x3f,
 	           0x73,
 	           0x67,                //'q'
 	           0x77,             	//  M,N,O,P,Q,R
				           
 	           0x6d,
 	           0x07,
 	           0x3e,
 	           0x3e,		//"V"
 	           0x00,
 	           0x76,             	//   S,T,U,V,W,X
           
 	           0x6e,		//y
 	           0x01,             	//   Y,Z
				           
 	           0x00,
 	           0x00,
 	           0x00,
 	           0x00,
 	           0x00,
	           0x00,             	//    6个符号
				           
	           0x5f,
	           0x7c,
	           0x58,
	           0x5e,
	           0x7b,
	           0x71,             	//    a,b,c,d,e,f
				           
	           0x6f,
	           0x74,
	           0x06,     		//"i"
	           0x0e,
	           0x70,
	           0x38,             	//    g,h,i,j,k,l
				           
	           0x54,
	           0x54,
	           0x5c,    		//"o"
	           0x73,
	           0x67,
	           0x31,             	//    m,n,o,p,q,r
				           
	           0x6d,
	           0x78,
	           0x1c,
	           0x1c,
	           0x00,
	           0x00,             	//    s,t,u,v,w,x
				           
	           0x6e,
	           0x08             	//    y,z
    
};

#define SAA1064_1_ADDR 	0x70
#define SAA1064_2_ADDR 	0x76

#define ERROR_SAA1064_1
//#define ERROR_SAA1064_2   	//小板2
//#define EEROR_SAA1064_3         //4.00板


#ifdef EEROR_SAA1064_3
flash unsigned char twinkle_swip_tbl[8]={7,6,5,4,2,3,0,1};
#endif

//bit = 1,twinkle the bit LED
unsigned char LED_twinkle_bits;
//bit = 1,dot the bit LED
unsigned char LED_dot_bits;

void LED_display( unsigned char *disp_buf_ptr ,unsigned char blank_bits )
{
	
	unsigned char i,ii,iii;

	
	#ifdef	ERROR_SAA1064_1
	//for bad wiring
	unsigned char *temp_disp_buf_ptr;
	unsigned char temp_disp_buf[8];
	
	//test	
	
	temp_disp_buf_ptr=disp_buf_ptr;
	
	temp_disp_buf[3]=*temp_disp_buf_ptr++;	
	temp_disp_buf[2]=*temp_disp_buf_ptr++;		
	temp_disp_buf[1]=*temp_disp_buf_ptr++;		
	temp_disp_buf[0]=*temp_disp_buf_ptr++;	
		
	temp_disp_buf[3+4]=*temp_disp_buf_ptr++;		
	temp_disp_buf[2+4]=*temp_disp_buf_ptr++;		
	temp_disp_buf[1+4]=*temp_disp_buf_ptr++;		
	temp_disp_buf[0+4]=*temp_disp_buf_ptr++;		
	
	disp_buf_ptr = temp_disp_buf;
	//for bad wiring
	#endif
	
	#ifdef	ERROR_SAA1064_2
	//for bad wiring
	unsigned char *temp_disp_buf_ptr;
	unsigned char temp_disp_buf[8];
	
	temp_disp_buf_ptr=disp_buf_ptr;
	
	temp_disp_buf[3+4]=*temp_disp_buf_ptr++;	
	temp_disp_buf[2+4]=*temp_disp_buf_ptr++;		
	temp_disp_buf[1+4]=*temp_disp_buf_ptr++;		
	temp_disp_buf[0+4]=*temp_disp_buf_ptr++;	
		
	temp_disp_buf[3]=*temp_disp_buf_ptr++;		
	temp_disp_buf[2]=*temp_disp_buf_ptr++;		
	temp_disp_buf[1]=*temp_disp_buf_ptr++;		
	temp_disp_buf[0]=*temp_disp_buf_ptr++;		
	
	disp_buf_ptr = temp_disp_buf;
	//for bad wiring
	#endif

	#ifdef	EEROR_SAA1064_3
       	unsigned char *temp_disp_buf_ptr;
	unsigned char temp_disp_buf[8];
	
	temp_disp_buf_ptr=disp_buf_ptr;
       
        temp_disp_buf[1]=*temp_disp_buf_ptr++; 
        temp_disp_buf[0]=*temp_disp_buf_ptr++;
        temp_disp_buf[3]=*temp_disp_buf_ptr++; 
        temp_disp_buf[2]=*temp_disp_buf_ptr++;  
  	
  		temp_disp_buf[1+4]=*temp_disp_buf_ptr++;
       	temp_disp_buf[0+4]=*temp_disp_buf_ptr++;	
        temp_disp_buf[3+4]=*temp_disp_buf_ptr++;
        temp_disp_buf[2+4]=*temp_disp_buf_ptr++;  
        
        disp_buf_ptr = temp_disp_buf;      
        #endif	
    
	iii=0;
	for(ii=0;ii<2;ii++)
	{
		i2c_start();	
		if(ii==0)
			i2c_write(SAA1064_1_ADDR);
		else	
			i2c_write(SAA1064_2_ADDR);
		i2c_write(0x0);
		i2c_write(0b00010111); 
	           
		for(i=0;i<4;i++)
		{       
			#ifdef	EEROR_SAA1064_3
	 		if(blank_bits & (1 << twinkle_swip_tbl[iii]) )
	 		#else
	 		if(blank_bits & (1 << iii))
	 		#endif
        		{
				i2c_write(0x0);        			
        		}
        			
        		else
        		{
				i2c_write(seg_tbl[ *disp_buf_ptr - 0x20 ]); 
			}

			disp_buf_ptr++;  
			iii++;
		}
	     		     
		i2c_stop();	        
	}
}   
       
  
/********************************************************************************************/
//			HEXtoDEC adjust             
//
//USED:
//
//INPUT:
//	(1)unsigned char type;
//	(2)unsigned int  H_value;
//	(3)unsigned char position;
//OUTPUT:
//      (1)disp_buf[];
//
//**PASS**
/********************************************************************************************/

void HEXtoDEC(unsigned char type, unsigned int H_value, unsigned char position)
{	   
	if (type == 5)
	{
		disp_buf[position ++] = H_value / 10000 + 0x30;
		disp_buf[position ++] = (H_value % 10000)/1000 + 0x30;
		disp_buf[position ++] = (H_value % 1000) / 100 + 0x30;
		disp_buf[position ++] = (H_value % 100) / 10 + 0x30;
		disp_buf[position ++] = H_value % 10 + 0x30;	
	}
	if (type == 4)
	{
		disp_buf[position ++] = H_value / 1000 + 0x30;
		disp_buf[position ++] = (H_value % 1000) / 100 + 0x30;
		disp_buf[position ++] = (H_value % 100) / 10 + 0x30;
		disp_buf[position ++] = H_value % 10 + 0x30;	
	}	
	if (type == 3)
	{
		disp_buf[position ++] = H_value / 100 + 0x30;
		disp_buf[position ++] = (H_value % 100) / 10 + 0x30; 
		disp_buf[position ++] = H_value % 10 + 0x30;
	}
	if (type == 2)
	{
		disp_buf[position ++] = H_value / 10 + 0x30;
		disp_buf[position ++] = H_value % 10 + 0x30;
	} 
	if (type == 1)
	{
		disp_buf[position ++] = H_value +0x30;
	}
}  

   

⌨️ 快捷键说明

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