void i2c() { comm_init(); init_24c02(); while(temp!='#') { temp=_getkey(); if(temp=='&') { while(temp!='$') { temp=_getkey(); write_add(i++,temp); } i=0; } if(temp=='^') { while(read_add(t++)!='$') { printf("%c",read_add(t-1)); } t=0; } } }
void led() { unsigned char i; int s; while(i!='!') { i=_getkey(); if(i=='d') { P2=0xff; while(i!='^') { i=_getkey(); switch(i) { case '1' : led1=~led1; break; case '2' : led2=~led2; break; case '3' : led3=~led3; break; case '4' : led4=~led4; break; case '5' : led5=~led5; break; case '6' : led6=~led6; break; case '7' : led7=~led7; break; case '8' : led8=~led8; break; default : break; } } } if(i=='f') { P2=0xff; while(i!='#') { i=_getkey(); if(i!='#') { s=ssscanf(); } if(i=='u') { flow(s,1); } if(i=='b') { flow(s,2); } } } } }
void main (void) { unsigned int i; char ch; P2M1 = 0; P1M1 = 0; BRGR0 = 0xF0; /* 9600 baud, 8 bit, no parity, 1 stop bit */ BRGR1 = 0x02; BRGCON = 0x03; SCON = 0x52; /* enable serial uart & receiver */ EA = 1; /* Enable global interrupt flag */ //TestSerial (); // uncomment this function to verify serial communication #if 0 // init ISD51 and start user program until the uVision2 Debugger connects ISDinit (); // initialize uVision Debugger and continue program run #endif #if 0 // init ISD51 and wait until the uVision Debugger connects ISDwait (); // wait for connection to uVision2 Debugger #endif for (i = 0; i < sizeof (testarray); i++) { j = testarray[i]; } while (1) { #if 1 // init ISD51 only when the uVision Debugger tries to connect ISDcheck(); // initialize uVision Debugger and continue program run #endif _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); P2 ^= 0x10; if (_iskey ()) { // check if a charcter has been received ch = _getkey (); // get the received character putchar (ch); // echo the received character } _nop_(); _nop_(); _nop_(); #if 0 // you may use ISDbreak when ISD51 is started with ISDcheck or ISDwait ISDbreak (); // hard coded stop (breakpoint) #endif delay(); _nop_(); _nop_(); _nop_(); } }
int ssscanf() { unsigned char buf[7],i,t=0; int s; while(i!='%') { i=_getkey(); buf[t++]=i; } buf[strlen(buf)-1]='\0'; sscanf(buf,"%d",&s); for(i=0;i<7;i++) { buf[i]='\0'; } return(s); }
chtype tgetch(int interpret) { int i = 0, j, collapse = 1; #define WAIT3 333 chtype inp; chtype *inputQ = cur_term->_input_queue; char *chars_onQ = &(cur_term->_chars_on_queue); #ifdef SYSV /* * Register the fact that getch is being used so * that typeahead checking can be done. * This code should GO AWAY when a poll() or FIONREAD can * be done on the file descriptor as then the check * will be non-destructive. */ cur_term->fl_typeahdok = TRUE; #endif /* SYSV */ /* ask for input */ if (cur_term->_ungotten > 0) { cur_term->_ungotten--; /* decode an ungetch()'d character */ inp = -inputQ[0]; } else { /* Only read a character if there is no typeahead/peekahead. */ if (*chars_onQ == 0) { /* (*chars_onQ)++; MR */ #ifdef FIONREAD inp = _readchar(); #else /* FIONREAD */ inp = (chtype) _pk(); if ((int)inp == ERR) { /* * interpret is set to 0 so that down below we don't * drop into getkey since we already know there can't be * a key that starts with -1. Also, we don't want to * access funckeystarter[-1]. */ interpret = FALSE; } #endif /* FIONREAD */ (*chars_onQ)++; } else inp = inputQ[0]; #ifdef DEBUG if (outf) fprintf(outf, "TGETCH read '%s'\n", unctrl(inp)); #endif /* DEBUG */ /* Check for arrow and function keys */ if (interpret && cur_term->funckeystarter[inp]) collapse = _getkey(interpret - 1, &inp); } /* Collapse the input queue to remove the escape */ /* sequence from the stack. */ j = *chars_onQ; (*chars_onQ) -= collapse; while (collapse < j) inputQ[i++] = inputQ[collapse++]; return (inp); }