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

📄 main.c

📁 全国电子设计大赛:智能电动车的设计.实现功能:以AT89C52单片机为核心
💻 C
📖 第 1 页 / 共 5 页
字号:
//*************************************************************************************************
//  Module Name :  Main.C
//  CreateDate  :  2005-05-03
//  ModifData   :  2005-07-18
//  Description :  ( C8051F022 )
//  Author      :  李远正
//  Version     :  V3.0
//*************************************************************************************************

#include <C8051F020.H> 
#include <intrins.h> 
#include <absacc.h>
#include <string.h>
#include <stdio.h>
#include <math.h> 
#include "chinese.H"
#include "Initializes.H"
#include "Function.H"
#include "KS0108.H"
#include "12C887.H"
#include "WriteFile.H" 
#include "Driver.H" 

//=================================================================================================
// Global CONSTANTS
//=================================================================================================
// Key value
//
sfr KEY_PORT =  0x85;

#define	KEY1		0x7E
#define	KEY2		0x7D
#define	KEY3		0x7B
#define	KEY4		0x77
#define	KEY5		0x6F
#define	KEY6		0x5F
#define	KEY7		0x3F

//-------------------------------------------------------------------------------------------------
//
#define	qudou			8 	 // 按键去抖间隔	

//*************************************************************************************************
//*************************************************************************************************
// Global VARIABLES 
//*************************************************************************************************
//*************************************************************************************************
// 
//=================================================================================================
// SMBus.C 
//=================================================================================================
// 
unsigned char xdata COMMAND;              // Holds the slave address + R/W bit for
                                          // use in the SMBus ISR.
unsigned char xdata DATA;                 // Holds data to be transmitted by the SMBus
                                          // OR data that has just been received.

//-----------------------------------------------
// Device : 24AA512 
unsigned char xdata HIGH_ADDR,LOW_ADDR;   // The address 
unsigned char xdata STEP;                 // 
unsigned char xdata MODE;                 // The mode of operation: sigle or sequential data
unsigned char xdata *DATUM;               // Holds sequential data to be transmitted by the SMBus
                                          // OR sequential data that has just been received.
unsigned char xdata NUMBER;               // Read the number of bytes 

unsigned char xdata AA512_BUF[128];       // The sequential data from/to the slave device ( 24AA512 ).

//-----------------------------------------------
// MCU : C8051F022 
unsigned char xdata OP_CODE;              // Holds an op code to be sent or one
                                          // that has just been received.
unsigned char xdata LOST_COMMAND;         // Used to hold relevant data after a lost arbitration. 
unsigned char xdata LOST_DATA; 
unsigned char xdata LOST_CODE; 

unsigned char xdata C8051F_DATA_BUF[16];  // Data buffer accessed by OP_CODE_HANDLER 

bit LOST;                                 // Arbitration lost flag, set when 
                                          // arbitration is lost while in master mode.
                                          // Used to resume a failed transfer.
bit VALID_OP;                             // Flag used to determine if byte received
                                          // as a slave is an OP_CODE or data.
bit DATA_READY;                           // Used by OP_CODE handler to flag when
                                          // valid data has been received from the master

//-----------------------------------------------
bit WorkBusy;                             // Waiting before write/read data cycle completed 

//=================================================================================================
// USP.C 
//=================================================================================================
// 
CMD_PARAM		mCmdParam;				// 默认情况下该结构将占用64字节的RAM,可以修改MAX_PATH_LEN常量,当修改为32时,只占用32字节的RAM 

unsigned char xdata mIntStatus;			// CH375模块的中断状态或者操作完成状态 

//=================================================================================================
// WriteFile.C 
//=================================================================================================
// 
// 假定文件数据缓冲区: ExtRAM: 4000H-7FFFH  [ 16KB ]
// 外部RAM的文件数据缓冲区,从该单元开始的缓冲区长度不小于一次读写的数据长度,最少为512字节 
unsigned char xdata DATA_BUF[ 512 * 32 ] _at_ 0x4000; // 
unsigned char xdata LAST_BUF[ 512 ]      _at_ 0x3E00; // 用来读取原文件尾部不足一个扇区的零碎数据 
unsigned char xdata *buffer;	    // 数据缓冲区指针,用于读写数据块 

unsigned char  superaddition;       // 追加数据次数 

unsigned int   WriteFileSize;       // 一次写入文件的大少 
unsigned long  TotalFileSize;       // 文件总大小 

//=================================================================================================
// Driver.C 
//=================================================================================================
// 
// speed configure 
unsigned char xdata SPEED, SPEED1; // The speed of the CAR 
unsigned char xdata FREQUENCY;     // The frequency of PWM 

bit SPEED_modify,FREQUENCY_modify;
//-------------------------------------------------------------------------------------------------
// distance 
unsigned char xdata SECTION;         // The section of the way: A,B,C
unsigned int  xdata SECTION_BPoint, SECTION_CPoint, SECTION_BCPoint;   

bit SECTION_BPoint_modify, SECTION_BCPoint_modify; 

unsigned int  xdata DistanceCount = 0;          // The counts of the loops 
unsigned int  xdata DISTANCE = 0, DISTANCE_C;   // The distance of the way ( 17cm/loop )

bit Flag_CArea;

//-------------------------------------------------------------------------------------------------
// time 
unsigned char xdata JourneyTime, TimeBPoint, TimeCPoint;

bit Start, Stop; 

//-------------------------------------------------------------------------------------------------
// The flag of operation 
unsigned char xdata CarStatus;

bit B_SECTION; 

bit forward, backward, turnright, turnleft;
bit Flag_LeftOver0, Flag_LeftOver1, Flag_RightOver0, Flag_RightOver1, Flag_Center; 
bit Flag_Barrier;

//-------------------------------------------------------------------------------------------------
// The operation of Metal 
unsigned char xdata MetalNumber;   // 1--3 
unsigned int  xdata MetalDistance1, MetalDistance2; 
unsigned int  xdata MetalStartPoint, MetalEndPoint; 

bit Flag_Metal;  

//-------------------------------------------------------------------------------------------------
// The photoelectric cell 
unsigned int  xdata LightLeft, LightCenter, LightRight; 
unsigned char xdata INTENSITY;

bit INTENSITY_modify;

//-------------------------------------------------------------------------------------------------
// Write file to USB 
bit Write; 


//=================================================================================================
// Main.C 
//=================================================================================================
// 
//-------------------------------------------------------------------------------------------------
// The location of Screen
unsigned char xdata SCREEN=0;
unsigned char xdata vertical,horizontal;

//unsigned char xdata test1,test2;                    // Just for test 

// The operation of key
bit confirm_down,up,down;
bit modifying;

// Key 
unsigned char xdata keycode;
unsigned char xdata	k1_count,k2_count,k3_count,k4_count,k5_count,k6_count,k7_count;

//-------------------------------------------------------------------------------------------------
// Time Setting
unsigned char xdata time_buf[7],setup_time[7];	
unsigned char xdata delay_time,time_now,time_old,time_old1;

bit time_modify;

unsigned char xdata second_count,halfsecond_count;
bit flag_s;

//-------------------------------------------------------------------------------------------------
// Temperature of Chip
unsigned int xdata TEMPER;

//-------------------------------------------------------------------------------------------------
// ADC
unsigned int xdata Voltage,DriverVoltage;

//-------------------------------------------------------------------------------------------------
// DAC
int xdata DAC0datum,DAC1datum;

bit DAC0_modify,DAC1_modify;
bit DAC0Enable,DAC1Enable;

//-------------------------------------------------------------------------------------------------
// Alarm Setting
char xdata alarm_range;

bit alarm_modify;

bit LED_Glitter_Enable, LED_Glitter_Disable; 

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
// The global temporary variable  
unsigned char temp; 
unsigned int  tempshort;

bit flag;

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
// USB 模块 
unsigned char GUAGE;        // 进度指示 


//=================================================================================================
// Function PROTOTYPES
//=================================================================================================
// 
//=================================================================================================
//							  	      Delay Procedure 
//=================================================================================================
// 1 ms 延时子程序, Fosc =12MHz 
void mDelaymS( unsigned int msecond )
{
	unsigned char i,j;

	while( msecond-- )
	{
        for( j=0; j<8; j++ )
		for( i=0; i<125; i++) {;}
	}
}

//=================================================================================================
//                                    KeyBoard Procedure
//=================================================================================================

//                             KEY7
//         KEY6      KEY5      KEY4       KEY3       KEY1
//                             KEY2

//                              up
//                    left    confirm     right      modify
//                             down

void KeyProcess( void )
{
	unsigned char KeyValue;

	KeyValue = KEY_PORT&0x7F;   // 查询按键

    switch( KeyValue )
	{
		case KEY1:	if(k1_count==qudou){keycode=1;k1_count=0;}
					k1_count++;
					k2_count=k3_count=k4_count=k5_count=k6_count=k7_count=0;
					break;
		case KEY2:	if(k2_count==qudou){keycode=2;k2_count=0;}
					k2_count++;
					k1_count=k3_count=k4_count=k5_count=k6_count=k7_count=0;
					break;
		case KEY3:	if(k3_count==qudou){keycode=3;k3_count=0;}
					k3_count++;
					k1_count=k2_count=k4_count=k5_count=k6_count=k7_count=0;
					break;
		case KEY4:	if(k4_count==qudou){keycode=4;k4_count=0;}
					k4_count++;
					k1_count=k2_count=k3_count=k5_count=k6_count=k7_count=0;
					break;
		case KEY5:	if(k5_count==qudou){keycode=5;k5_count=0;}
					k5_count++;
					k1_count=k2_count=k3_count=k4_count=k6_count=k7_count=0;
					break;
		case KEY6:	if(k6_count==qudou){keycode=6;k6_count=0;}
					k6_count++;
					k1_count=k2_count=k3_count=k4_count=k5_count=k7_count=0;
					break;
		case KEY7:	if(k7_count==qudou){keycode=7;k7_count=0;}
					k7_count++;
					k1_count=k2_count=k3_count=k4_count=k5_count=k6_count=0;
					break;
		default:	k1_count=k2_count=k3_count=k4_count=k5_count=k6_count=k7_count=0;

⌨️ 快捷键说明

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