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

📄 main.c

📁 pcmouse.rar PS/2键盘接收代码
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2004-09-16
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"



/****************************************************************************
* 名    称:I2C_Init()
* 功    能:主模式I2C初始化,包括初始化其中断为向量IRQ中断。
* 入口参数:fi2c		初始化I2C总线速率,最大值为400K
* 出口参数:无
****************************************************************************/
void  I2C_Init(uint32 fi2c)
{  
    if(fi2c>400000) fi2c = 400000;

    PINSEL0 = (PINSEL0&0xFFFFFF0F) | 0x50; 	// 设置I2C控制口有效

    I2SCLH = (Fpclk/fi2c + 1) / 2;			// 设置I2C时钟为fi2c
    I2SCLL = (Fpclk/fi2c) / 2;
    I2CONCLR = 0x2C;
    I2CONSET = 0x40;						// 使能主I2C
   
    /* 设置I2C中断允许 */
    VICIntSelect = 0x00000000;				// 设置所有通道为IRQ中断
    VICVectCntl0 = 0x29;					// I2C通道分配到IRQ slot 0,即优先级最高
    VICVectAddr0 = (int)IRQ_I2C;	    	// 设置I2C中断向量地址	
    VICIntEnable = 0x0200;           		// 使能I2C中断 
}


  void Mouse_Init(void)
  {
    SendMouseCmd(0xF6);
    
    SendMouseCmd(0xF4);
    
    }



  int main (void)
{// add user source code 
    uint8  k;
    uint8  data_buf[10];
        
    IRQEnable();

    PINSEL0 = 0x00000000;			
    PINSEL1 = 0x00000000;
    
    I2C_Init(30000);                      		// I2C初始化
    
    Mouse_Init();
    
    for(k=0; k<3; k++)
    {
       data_buf[k]= My_GetDat();
     }
    
    
    
    return 0;
}
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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