51单片机各类源程序集锦

源代码在线查看: kernel.c

软件大小: 3620 K
上传用户: leihongcetc
关键词: 51单片机 源程序 集锦
下载地址: 免注册下载 普通下载 VIP

相关代码

				//***********************************************************************
				//									     								                  *
				//                P H I L I P S   P R O P R I E T A R Y          		   *
				//                                                                      *
				//          COPYRIGHT (c)   1999 BY PHILIPS SINGAPORE (APIC).    		   *
				//                    --  ALL RIGHTS RESERVED  --                 		*	
				//                                                                      *
				// 	File Name	:       Kernel.c                                      *
				// 	Author		:       Albert Goh					 					      *
				// 	Created		:      	3 March 2000                               	*
				//                  	                                                   *
				//***********************************************************************
				//***********************************************************************
				//                                                                      *
				// Kernel.c is the control centre for this evaluation firmware. It will *
				// control where should the firmware branch through via the selection 	*
				// of the UART port of the 8051. if not via the UART, it will be from 	*
				// the selection of the code defintion                                  *
				//                                                                      *
				//***********************************************************************
				//***********************************************************************
				//                                                                      *
				//  Module History														            *  
				//  **************														            *
				//																		                  *
				//  Date   	Version			Author				Changes					      *
				//  ====	=======			======				=======					         *
				//  030300	  0.1 			Albert				Created    				      *
				//                                                                      *
				//                                                                      *
				//***********************************************************************
				//***********************************************************************
				//*																		               *
				//*	                     Include Files Definition						   *
				//*																		               *
				//***********************************************************************
				
				#include "standard.h"
				#include "Kernel.h"
				#include "D14.h"
				#include "zlg7290.h"
				#include "VIIC_C51.h"
				
				#define uchar unsigned char
				
				//***********************************************************************
				//*																		               *
				//*	                 External routine Definition					 	      *
				//*																		               *
				//***********************************************************************
				
				extern Init_Main();
				extern USB_Debug_Mode();
				extern DMA_Debug_Mode();
				extern USB_INT_FLAG USB_Int_Flag;
				extern DMA_INT_FLAG DMA_Int_Flag;
				extern USB_DEVICE USB_Device;
				extern volatile D14_CNTRL_REG	xdata	D14_Cntrl_Reg;
				extern void Check_Busy(void);
				extern void Init_D14(void);
				extern void Init_Endpoint(void);
				extern void Init_Device(void);
				extern void Get_PIDVID(void);
				extern unsigned int read_endpoint(unsigned char endp,unsigned int len,unsigned char *buf);
				extern unsigned int write_endpoint(unsigned char endp,unsigned int len,unsigned char *buf);
				extern UC VID[2],PID[2];
				extern UC	idata Endpt_FIFO[MAX_BUF];
				extern Set_USB(void);
				extern TIMER	Timer;
				extern UC 	timecouter;
				//***********************************************************************
				//*																		               *
				//*	                 Prototype routine Definition					 	   *
				//*																		               *
				//***********************************************************************
				
				void Start_mSEC_Timer(Data);
				void Start_SEC_Timer(Data);
				uchar DelayNS(uchar no);
				
				//***********************************************************************
				//*																		               *
				//*	                     Variable Definition 							      *
				//*																		               *
				//***********************************************************************
				
				UI	Temp;
				KERNEL Kernel_Flag;
				uchar code td[5]={0x00,0x12,0x48,0x30,0x12};   //8563初始化值
				uchar code disp_buf[8]={0,0,0,0,0,0,0,0};		//LED初始化值
				//UC key=0xff;
				//***********************************************************************
				//*																		               *
				//*	                     Routine Definition								   *
				//*																		               *
				//***********************************************************************
				
				//***********************************************************************
				//*										    							               *
				//*	Routine 	:  Main                                          		   *
				//*	Input		:  None            									            *
				//*	Output   :	None                                  					   *
				//*	Function	:	main loop                                			      *
				//*																		               *
				//***********************************************************************
				
				void Main(void)
				{
					
					//ISendStr(0xa2,0,td,0x5);
					//ZLG7289_Rest();		// 复位ZLG7289
				    DelayNS(5);
					//Initialization routine
					//初始化子程序
					ZLG7290_SendBuf(disp_buf,8);
					Init_Main();			
					
					//enable device and reset the device address
					D14_Cntrl_Reg.D14_MODE.BITS.SOFTCT = 1;	
					
					do
					{		
						//USB routine
						USB_Debug_Mode();
						
						//Generic DMA routine
						DMA_Debug_Mode();	
						if(	USB_Int_Flag.BITS.EP1RX==1)    //接受数据并显示
						{
							read_endpoint(2,8,Endpt_FIFO);
							DelayNS(1);
							ZLG7290_SendBuf(Endpt_FIFO,8);
							USB_Int_Flag.BITS.EP1RX=0;
						}
						if(timecouter==30 )                //定时读取键值,并发送时间(82ms,12MHz,6CLOCK)
						{	
							DelayNS(1);
							Endpt_FIFO[0]=ZLG7290_GetKey();
							if(Endpt_FIFO[0]==0) Endpt_FIFO[0]=0xff;
							else Endpt_FIFO[0]--;
							DelayNS(1);
							IRcvStr(0xa2,0x02,&Endpt_FIFO[1],0x3);
							Endpt_FIFO[3]=Endpt_FIFO[3]&0x3f;
							write_endpoint(3,4,Endpt_FIFO);
							timecouter=20;	
						}
					}
					while(1);
				}
				
				/*********************************************************************************************************
				** 函数名称: 	DelayNS
				** 功能描述: 	长软件延时
				** 输 入: no :	延时参数,值越大时延时越久
				**         
				** 输 出: 0 :	OK;
				**         1 :	FAIL;
				** 全局变量:	无
				** 调用模块: 	无
				**
				** 作 者: 叶皓贲
				** 日 期: 2003-3-4
				**-------------------------------------------------------------------------------------------------------
				** 修改人:
				** 日 期:
				**------------------------------------------------------------------------------------------------------
				********************************************************************************************************/
				uchar DelayNS(uchar no)
				{ 
					uchar i,j;					//延时参数
				
				  	for(; no>0; no--)
				  	{ 
						for(i=0; i				     		for(j=0; j				  	}
				  	return 0; 
				}
				
				//***********************************************************************
				//*										    							               *
				//*	Routine 	: Start_mSEC_Timer(Delay)                          		*
				//*	Input		: Delay in milli second									         *  
				//*	Output		: Start timer operation               					   *
				//*	Function	: To start the timeout operation based on the delay i/p  *
				//*																		               *
				//***********************************************************************
				
				void Start_mSEC_Timer(Data)
				{
					
				   	
					do
					{
						
						//calculate timer value
						Temp = Timer.mSEC_Scale;		
						Temp = 0xffff - Temp;
						
						ET0 = 1;
						
						//calculate timer value
						//initialize timer 0 counter
						Temp >>= 8;
						TH0 = (UC) Temp;
						Temp = Timer.mSEC_Scale;		
						Temp = 0xffff - Temp;
						TL0 = (UC) Temp;
						
						//start timer count
						TR0 = 1;							
						
						Kernel_Flag.BITS.Timer_Expired = 0;
						while(!Kernel_Flag.BITS.Timer_Expired);
						Kernel_Flag.BITS.Timer_Expired = 0;
						
						
						//stop timer
						TR0 = 0;							
						ET0 = 0;
						
						Data--;
					}
					while(Data != 0);
				}
				
				
							

相关资源