Compatibility BV4618 with PIC18 January 29, 2014 10:11PM |
Registered: 9 years ago Posts: 5 |
Re: Compatibility with PIC18 January 30, 2014 12:23PM |
Admin Registered: 11 years ago Posts: 351 |
fputc(0x1b);printf("[42k"); // set ACK to be 42 - only needs doing once at setup char c = 0, count=0, buf[5]; while(c != 42) { // key() should wait until a key is available and then return it c = key(); if(c !=42) // don't want 42 to be part of input buf[count++]=c; }
Re: Compatibility with PIC18 January 30, 2014 11:07PM |
Registered: 9 years ago Posts: 5 |
Re: Compatibility with PIC18 January 31, 2014 08:35AM |
Admin Registered: 11 years ago Posts: 351 |
Re: Compatibility with PIC18 January 31, 2014 11:44AM |
Registered: 9 years ago Posts: 5 |
Re: Compatibility with PIC18 February 01, 2014 07:30AM |
Admin Registered: 11 years ago Posts: 351 |
Re: Compatibility with PIC18 February 04, 2014 10:02AM |
Registered: 9 years ago Posts: 5 |
Re: Compatibility with PIC18 February 04, 2014 01:36PM |
Admin Registered: 11 years ago Posts: 351 |
{ char c, buffer[20], count =0; while(1) { // loop forever while(no_keys_in_UART); // wait until a key comes in c = get_byte_from_uart(); if( c == 42) break; buffer[count++]=c; } // buffer now contains a string of bytes }For a PIC32 the code would look like this:
{ char c, buffer[20], count =0; while(1) { while(!U2STAbits.URXDA); // wait for char c = U2RXREG; if( c == 42) break; buffer[count++]=c; } }
Re: Compatibility BV4618 with PIC18 February 09, 2014 09:28PM |
Registered: 9 years ago Posts: 5 |
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #define BUFFER_SIZE 32 BYTE KeyBuffer[BUFFER_SIZE]; BYTE next_in = 0; BYTE next_out = 0; #int_rda void serial_isr() { int t; KeyBuffer[next_in]=getc(); t=next_in; next_in=(next_in+1) % BUFFER_SIZE; if(next_in==next_out) next_in=t; // Buffer full !! } #define bkbhit (next_in!=next_out) BYTE bgetc() { BYTE c; while(!bkbhit) ; c=KeyBuffer[next_out]; next_out=(next_out+1) % BUFFER_SIZE; return(c); } void KeyPadControl() { char c=0, count=0, nCarBuffer=0, buf[]="XXXXX"; fputc(0x1b);printf("[n"); // asks how many keys in the buffe delay_ms(10); while(bkbhit) { c=bgetc(); nCarBuffer=c-48; count++; if (count>4) break; } if (NcarBuffer>0){ count=0; c=0; fputc(0x1b);printf("[k"); // Reads the key from buffer delay_ms(10); while (bkbhit){ c=bgetc(); buf[count]=c; count++; if (count>5) break; } } // decoding the key pressed if (buf[0]!='X'){ if (buf[0]=='1'){ if (buf[1]=='1'){ if (buf[2]=='9'){keypressed='D';} } if (buf[1]=='2'){ if (buf[2]=='3'){keypressed='C';} if (buf[2]=='5'){keypressed='B';} if (buf[2]=='6'){keypressed='A';} } if (buf[1]=='8'){ if (buf[2]=='3'){keypressed='#';} if (buf[2]=='7'){keypressed='9';} if (buf[2]=='9'){keypressed='6';} } if (buf[1]=='9'){ if (buf[2]=='0'){keypressed='3';} } } if (buf[0]=='2'){ if (buf[1]=='1'){ if (buf[2]=='5'){keypressed='0';} if (buf[2]=='9'){keypressed='8';} } if (buf[1]=='2'){ if (buf[2]=='1'){keypressed='5';} if (buf[2]=='2'){keypressed='2';} } if (buf[1]=='3'){ if (buf[2]=='1'){keypressed='*';} if (buf[2]=='5'){keypressed='7';} if (buf[2]=='7'){keypressed='4';} if (buf[2]=='8'){keypressed='1';} } } } }
Re: Compatibility BV4618 with PIC18 February 10, 2014 08:20AM |
Admin Registered: 11 years ago Posts: 351 |