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

📄 main.c

📁 上学时做的一个51单片机按键显示程序
💻 C
字号:
/*
* Copyright(c)2005 - 2009 周建勇 .China
  jsn_ze@yahoo.com.cn
  arcbravezhou@yahoo.com.cn

* All rights reserved.
* Redistribution and use in source and bianry forms
* with or without modification ,are permitted provided
* that following conditions are met:
* 
* 1.Redistrubution of source code must retain the 
* above copyright notice,this list of conditions and
* following disclaimer.
* 
* 2.Redistributions in binary form must reproduce the 
* above copyright notice,this list of conditions and 
* following disclaimer in the documentation and /or other
* materials provided with the distribution.
* 
* Alternately, this acknowledgment may appear in the software
* itself,if and wherever such third-party acknowledgements
* normally appear.
*
* This software is designed for key board and led display.
* 
	
*/
#include "./include/datatypes.h"
#include "./include/init.h"
#include "./include/global.h"
#include "./include/display.h"
#include "./include/system.h"
#include "./include/i2c.h"

/*************************************************\
*a global variable for system events control.
*some event constants are define in file system.h
**************************************************/
UINT8 volatile event_word = 0;


void Initialize_ISP();
void SystemEventsAnalyse();
void main()
{
	
	
	/* system initialization */
	/* 932 ports initalization */
	CP932PortInit();
	
	
	/**************   ISP  ******************\
    \****************dangerous***************/
	PIN_ISP=1;
	if(PIN_ISP==0)    				
	{
		RxD=0;
		Initialize_ISP();
	}
	
	/******************  ********************/
	/* i2c intialization */
	InitIIC();

    /* Timer0 initialization ,timer0 will produce
	   interruptions for scaning keyboard*/
	CP932Timer0Init();
    /* Timer1 init.for system clock */
	CP932Timer1Init();
    
	CP932ISRInit();
	InitSysData();
	CheckLeds();
	CkeckLights();
	RegisterMachine();
    sreensaveclk =0;
	while( 1 )
	{
		CheckSreenSave();
		ProcessI2cRecvFrame();
		SystemEventsAnalyse();
	}

}

void Initialize_ISP()
{
	SCON = 0x50; /* select the Baud Rate Generator as UART baud rate source*/
	BRGR1 = 0x04; /* 9600 BAUD at 11.0592 MHz*/
	BRGR0 = 0x70;
	BRGCON = 0x03; /* enable BRG */
	AUXR1 |= 0x40; /* enable reset on break detect by setting EBRR */

}
/*
* Analyse system events ,and to do the specified process.
*/
void SystemEventsAnalyse()
{
	UINT8 event_word_copy;	
	event_word_copy = event_word ;   
    
	if( event_word_copy & EVENT_SCREEN_SAVE ){
		Enter_Critical_OS();
		event_word &=( ~EVENT_SCREEN_SAVE );
		Exit_Critical_OS();
		SaveSreen();
	}
	
	if( event_word_copy & EVENT_LED_DOWN_UPDATE ){
		Enter_Critical_OS();
		event_word &=( ~EVENT_LED_DOWN_UPDATE );
		Exit_Critical_OS();
		/* invoke led show  function UpateLeds() */
		UpateDownLeds();
	} 

	if(event_word_copy & EVENT_I2C_DATA_SEND ){
		Enter_Critical_OS();
		event_word &=( ~ EVENT_I2C_DATA_SEND );
		Exit_Critical_OS();	
		/*invoke i2csend */
		I2cSendFrame( 0x0c );
	}

	

}

⌨️ 快捷键说明

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