/*---------------------------------------------------------------------------- * Name: DEMO.C * Purpose: USB HID Demo * Version: V1.10 *---------------------------------------------------------------------------- * This software is supplied "AS IS" without any warranties, express, * implied or statutory, including but not limited to the implied * warranties of fitness for purpose, satisfactory quality and * noninfringement. Keil extends you a royalty-free right to reproduce * and distribute executable files created using this software for use * on Philips LPC2xxx microcontroller devices only. Nothing else gives * you the right to use this software. * * Copyright (c) 2005-2006 Keil Software. *---------------------------------------------------------------------------*/ #include /* LPC214x definitions */ #include "type.h" #include "usb.h" #include "usbcfg.h" #include "usbhw.h" #include "usbcore.h" #include "demo.h" BYTE InReport[8]; /* HID Input Report */ /* Bit0,1,2: Button */ BYTE OutReport; /* HID Out Report */ /* Bit0,1,2: LEDs */ keyboard_st key; /* * Get HID Input Report -> InReport * SW1, SW2, SW3 are pressed in a mutually exclusive manner. */ int i; int fla; char que=0x1A; int buttonPress(void); void boom(char temp) // to print in keyboard { if (fla == 0) { que=temp; fla = 1; } } int buttonPress(void) { T0PR = 0X0016E360;//For 15 Mhz clock, this value ensures a time interval of 1 second. T0MCR = 0X0004; T0MR0 = 0X000A; T0TCR = 0X02; T0TCR= 0X01; while((T0TCR & 0X01)==0X01) { if((IO0PIN | 0XFFFFBFFF) == 0XFFFFBFFF ) { T0TCR = 0X02; T0MCR = 0X0004; T0MR0 = 0X0003; T0TCR = 0X02; T0TCR= 0X01; while((T0TCR & 0X01)==0X01); if((IO0PIN | 0XFFFFBFFF) == 0XFFFFBFFF) //dash is pressed { return 2; } else { return 1; } } } return 0; } void Convert (char Morsecode,char length) { // ASCII character set const char ascii[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;=.,?-: "; //Querty keycode set const char keyCode[]={0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E, 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19, 0x1A,0x1B,0x1C,0x1D,0x27,0x1E,0x1F,0x20,0x21,0x22,0x23, 0x24,0x25,0x26,0x33,0x2E,0x37,0x36,0x36,0x2D,0x2D,0x2C,0x28}; // Morse Code Set const char morse[] = { 0x42,0x81,0x85,0x61,0x20,0x84,0x63,0x80,0x40,0x8E,0x65, 0x82,0x43,0x41,0x67,0x86,0x8B,0x62,0x60,0x21,0x64,0x88, 0x66,0x89,0x8D,0x83,0xBF,0xBE,0xBC,0xB8,0xB0,0xA0,0xA1, 0xA3,0xA7,0xDF,0xB5,0xB1,0xEA,0xF3,0xCC,0xE1,0xC7,0x01,0x01 }; char temp = 0; temp = length << 5; temp = temp | Morsecode; for(i = 0; i < 45;i++) { if(morse[i] == temp) break; } if(i == 45) return ; boom(keyCode[i]); } void GetInReport (void) { //This is for Device(LPC2148) to Host PC reporting if (fla==1) { key.modifier=0; key.keycode[0] = que; fla=0; } else { key.modifier=0; key.keycode[0] = 0x00; } memcpy(InReport,&key,sizeof key); } /* * Set HID Output Report <- OutReport * LED1,2 and 3 will turn ON in a mutually exclusive manner. */ void SetOutReport (void) { //This is for Host PC to Device(LPC2148) reporting if(OutReport==0x01) { IOCLR0 = LED1; IOSET0 = LED2; IOSET0 = LED3; } else if(OutReport==0x02) { IOSET0 = LED1; IOCLR0 = LED2; IOSET0 = LED3; } else if(OutReport==0x04) { IOSET0 = LED1; IOSET0 = LED2; IOCLR0 = LED3; } else { IOSET0 = LED1; IOSET0 = LED2; IOSET0 = LED3; } } /* Main Program */ int main (void) { int n; char Morsecode = 0; char length = 0; int temp; int dash = 0x01; IODIR0 = LED1|LED2|LED3; PINSEL0 = 0X00000005; key.modifier=0; key.reserved=0; key.keycode[0]=0; key.keycode[1]=0; key.keycode[2]=0; key.keycode[3]=0; key.keycode[4]=0; key.keycode[5]=0; fla=0; USB_Init(); /* USB Initialization */ USB_Connect(TRUE); /* USB Connect */ while (1) { dash = 0x00000001; temp = buttonPress(); while ((IO0PIN | 0XFFFFBFFF) == 0XFFFFBFFF ); if(temp == 0) { Convert(Morsecode,length); boom(Morsecode); Morsecode = 0; length = 0; } else { if(temp == 2) { dash = dash << length; Morsecode = Morsecode | dash; } length++; } } }