#include <mega16.h>
#include <stdio.h>
#include <delay.h>
#include <stdlib.h>
#include <string.h>
#include <lcd.h>
#asm
.equ __lcd_port=0x18; PORTB
#endasm
bit h2=0,y=0;
unsigned int count=0;
unsigned char a,x,h1=0,out=0,bitcount=11,data;
unsigned char str[20];
char str2[20];
flash unsigned char s0[]="ESC",s1[]="F1",s2[]="F2",s3[]="F3",s4[]="F4";
flash unsigned char s5[]="F5",s6[]="F6",s7[]="F7",s8[]="F8",s9[]="F9";
flash unsigned char s10[]="F10",s11[]="F11",s12[]="F12",s13[]="~",s14[]="!";
flash unsigned char s15[]="@",s16[]="#",s17[]="$",s18[]="%",s19[]="^";
flash unsigned char s20[]="&",s21[]="*",s22[]="(",s23[]=")",s24[]="_";
flash unsigned char s25[]="+",s26[]="/",s27[]=" ",s28[]="Q",s29[]="W";
flash unsigned char s30[]="E",s31[]="R",s32[]="T",s33[]="Y",s34[]="U";
flash unsigned char s35[]="I",s36[]="O",s37[]="P",s38[]="{",s39[]="}";
flash unsigned char s40[]="A",s41[]="S",s42[]="D",s43[]="F",s44[]="G";
flash unsigned char s45[]="H",s46[]="J",s47[]="K",s48[]="L",s49[]=";";
flash unsigned char s50[]="'",s51[]=" ",s52[]="SHIFT",s53[]="Z",s54[]="X";
flash unsigned char s55[]="C",s56[]="V",s57[]="B",s58[]="N",s59[]="M";
flash unsigned char s60[]="<",s61[]=">",s62[]="?",s63[]="shift",s64[]="ctrl";
flash unsigned char s65[]="Win",s66[]="Alt",s67[]=" ",s68[]="Win",s69[]="0";
flash unsigned char s70[]=".",s71[]="1",s72[]="2",s73[]="3",s74[]="4";
flash unsigned char s75[]="5",s76[]="6",s77[]="7",s78[]="8",s79[]="9";
flash unsigned char s80[]="+",s81[]="-",s82[]="*";
interrupt [EXT_INT0] void ext_int0_isr(void){
count++;
if (h2==0)
{
if(bitcount < 11 && bitcount > 2)
{
data=(data >> 1);
if(PIND.7==1)data=(data|0b10000000);
}
MCUCR=3;
h2=1;
}
if(h2==1){
MCUCR=2;
h2=0;
if(--bitcount==0)
{
out=data;
bitcount=11;
}
}
}
void key(unsigned char in){
switch (in)
{
case 0x76:
strcatf(str,s0);
break;
case 0x05:
strcatf(str,s1);
break;
case 0x06:
strcatf(str,s2);
break;
case 0x04:
strcatf(str,s3);
break;
case 0x0c:
strcatf(str,s4);
break;
case 0x03:
strcatf(str,s5);
break;
case 0x0b:
strcatf(str,s6);
break;
case 0x83:
strcatf(str,s7);
break;
case 0x0a:
strcatf(str,s8);
break;
case 0x01:
strcatf(str,s9);
break;
case 0x09:
strcatf(str,s10);
break;
case 0x78:
strcatf(str,s11);
break;
case 0x07:
strcatf(str,s12);
break;
case 0x0e:
strcatf(str,s13);
break;
case 0x16:
strcatf(str,s14);
break;
case 0x1e:
strcatf(str,s15);
break;
case 0x26:
strcatf(str,s16);
break;
case 0x25:
strcatf(str,s17);
break;
case 0x2e:
strcatf(str,s18);
break;
case 0x36:
strcatf(str,s19);
break;
case 0x3d:
strcatf(str,s20);
break;
case 0x3e:
strcatf(str,s21);
break;
case 0x46:
strcatf(str,s22);
break;
case 0x45:
strcatf(str,s23);
break;
case 0x4e:
strcatf(str,s24);
break;
case 0x55:
strcatf(str,s25);
break;
case 0x5d:
strcatf(str,s26);
break;
case 0x0d:
lcd_clear();
strcpy(str,str2);
break;
case 0x15:
strcatf(str,s28);
break;
case 0x1d:
strcatf(str,s29);
break;
case 0x24:
strcatf(str,s30);
break;
case 0x2d:
strcatf(str,s31);
break;
case 0x2c:
strcatf(str,s32);
break;
case 0x35:
strcatf(str,s33);
break;
case 0x3c:
strcatf(str,s34);
break;
case 0x43:
strcatf(str,s35);
break;
case 0x44:
strcatf(str,s36);
break;
case 0x4d:
strcatf(str,s37);
break;
case 0x54:
strcatf(str,s38);
break;
case 0x5b:
strcatf(str,s39);
break;
case 0x1c:
strcatf(str,s40);
break;
case 0x1b:
strcatf(str,s41);
break;
case 0x23:
strcatf(str,s42);
break;
case 0x2b:
strcatf(str,s43);
break;
case 0x34:
strcatf(str,s44);
break;
case 0x33:
strcatf(str,s45);
break;
case 0x3b:
strcatf(str,s46);
break;
case 0x42:
strcatf(str,s47);
break;
case 0x4b:
strcatf(str,s48);
break;
case 0x4c:
strcatf(str,s49);
break;
case 0x52:
strcatf(str,s50);
break;
case 0x5a:
y=~y;
strcpy(str,str2);
break;
case 0x12:
x--;
break;
case 0x1a:
strcatf(str,s53);
break;
case 0x22:
strcatf(str,s54);
break;
case 0x21:
strcatf(str,s55);
break;
case 0x2a:
strcatf(str,s56);
break;
case 0x32:
strcatf(str,s57);
break;
case 0x31:
strcatf(str,s58);
break;
case 0x3a:
strcatf(str,s59);
break;
case 0x41:
strcatf(str,s60);
break;
case 0x49:
strcatf(str,s61);
break;
case 0x4a:
strcatf(str,s62);
break;
case 0x59:
x++;
break;
case 0x14:
strcatf(str,s64);
break;
case 0x27:
strcatf(str,s65);
break;
case 0x11:
strcatf(str,s66);
break;
case 0x29:
strcatf(str,s67);
break;
case 0x1f:
strcatf(str,s68);
break;
case 0x70:
strcatf(str,s69);
break;
case 0x71:
strcatf(str,s70);
break;
case 0x69:
strcatf(str,s71);
break;
case 0x72:
strcatf(str,s72);
break;
case 0x7a:
strcatf(str,s73);
break;
case 0x6b:
strcatf(str,s74);
break;
case 0x73:
strcatf(str,s75);
break;
case 0x74:
strcatf(str,s76);
break;
case 0x6c:
strcatf(str,s77);
break;
case 0x75:
strcatf(str,s78);
break;
case 0x7d:
strcatf(str,s79);
break;
case 0x79:
strcatf(str,s80);
break;
case 0x7b:
strcatf(str,s81);
break;
case 0x7c:
strcatf(str,s82);
break;
case 0x66:
a=strlen(str);
str[a-1]=0;
break;
}
if(out!=0)h1++;
out=0;
}
void main(void)
{
GICR|=0x40;
MCUCR=0x02;
MCUCSR=0x00;
GIFR=0x40;
ACSR=0x80;
DDRD.7=0;
lcd_init(16);
#asm("sei")
while(1)
{
key(out);
lcd_clear();
delay_ms(10);
lcd_gotoxy(x,y);
delay_ms(10);
lcd_puts(str);
delay_ms(500);
};}