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

📄 demo.c

📁 这是一个Keil MCB2148开发板上针对LPC2148的HID项目程序
💻 C
字号:
/*----------------------------------------------------------------------------
 *      Name:    DEMO.C
 *      Purpose: USB HID Demo
 *      Version: V1.00
 *----------------------------------------------------------------------------
 *      This file is part of the uVision/ARM development tools.
 *      Copyright (c) 2005 Keil Software. All rights reserved.
 *---------------------------------------------------------------------------*/

#include <LPC213X.H>                        /* LPC214x definitions */

#include "type.h"

#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"

#include "demo.h"


BYTE InReport;                              /* HID Input Report */
                                            /*   Bit0..2: Buttons */
                                            /*   Bit3..7: Reserved */

BYTE OutReport;                             /* HID Out Report */
                                            /*   Bit0..7: LEDs */


/*
 *  Get HID Input Report -> InReport
 */

void GetInReport (void) {
  DWORD key;

  key = IOPIN0;                             /* Read Pin Data */
  InReport = 0x00;
  if ((key & S2) == 0) InReport |= 0x01;    /* Check if S2 is pressed */
#ifndef MCB2140
  if ((key & S3) == 0) InReport |= 0x02;    /* Check if S3 is pressed */
  if ((key & S4) == 0) InReport |= 0x04;    /* Check if S4 is pressed */
#endif
}


/*
 *  Set HID Output Report <- OutReport
 */

void SetOutReport (void) {

  if (OutReport & 0x01) IOSET1 = LED1; else IOCLR1 = LED1;
  if (OutReport & 0x02) IOSET1 = LED2; else IOCLR1 = LED2;
  if (OutReport & 0x04) IOSET1 = LED3; else IOCLR1 = LED3;
  if (OutReport & 0x08) IOSET1 = LED4; else IOCLR1 = LED4;
  if (OutReport & 0x10) IOSET1 = LED5; else IOCLR1 = LED5;
  if (OutReport & 0x20) IOSET1 = LED6; else IOCLR1 = LED6;
  if (OutReport & 0x40) IOSET1 = LED7; else IOCLR1 = LED7;
  if (OutReport & 0x80) IOSET1 = LED8; else IOCLR1 = LED8;
}


/* Main Program */

int main (void) {

  IODIR1 = LED1 | LED2 | LED3 |             /* LED1, LED5..8 are Outputs */
           LED4 | LED5 | LED6 |
		   LED7 | LED8;
  

  USB_Init();                               /* USB Initialization */
  USB_Connect(TRUE);                        /* USB Connect */

  while (1);                                /* Loop forever */
}

⌨️ 快捷键说明

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