What I like about the coding style is the use of COMMENTS!!! Makes the code very readable to me. I've recently been struggling to port some code written for Windoze to C18. There's maybe 3 or 4 lines of comments per page, a 1 line comment at the top of a block of code with no comments on the lines of code. After several days of messing with it, I finally said, "I think this is what it's supposed to do" and wrote about 20 lines of commented C to replace the 7 pages of stuff. Seems to work. Also, years ago, I taught a class in PDP-8 assembly language programming (using Teletypes and punched tape!). I had students get their code working without comments, then add comments for my benefit (and for their grade's benefit). Unfortunately, by the time they added the comments, they forgot how the code worked, so the comments did not describe what the code was doing... So, THANKS FOR COMMENTING YOUR CODE! Harold > Rochester, 26 augustus 2005. > > Dear Lukas, > > I got it working on a PIC16F628... So it should be too difficult to > convert.. > I use RB0 for the clock, as it would (in the future) allow me to use > interrupts for the clock. I use RA6 for the data input. I know how risky > it > is to show code on this list, because one is bound to get comments on > coding > style, but it might be helpful. Here is the code to get the scancode (not > ASCII) from the keyboard, and store it in "Keyboard". > > getKeyboard > movlw 0x08 ; Eight bits to a keyboard byte > movwf t2 ; Store > KeyboardNextBit > btfsc PORTB,0 ; Wait for clock line to change > goto $-1 > bsf STATUS,C ; Assume a 1 > btfss PORTA,6 ; Check the data bit > bcf STATUS,C ; It wasn't 1, so 0 > rrf Keyboard,f ; Move the carry into the keyboard > btfss PORTB,0 ; Wait for the clock line to change > goto $-1 > decfsz t2,f ; Get the next bit > goto KeyboardNextBit > btfsc PORTB,0 ; Ignore the parity bit > goto $-1 > btfss PORTB,0 ; Make sure clock becomes high > goto $-1 > return > > Let me see... People will probably comment the use of goto $-1 (as it > isn't > compatible with >16F PICmicros) although it makes for very concise waits. > Then there are several hardcoded numbers (like the number of bits in a > scancode byte, and the location of the ports) that probably should become > defines in some way. Then there is the badly named "t2" from "teller > twee", > and there are various pieces of code that might be better if they were a > macro ("KB_WAIT(state)" is an idea). Of course, as said originally, the > whole thing would look much better in an interrupt on clock line change > anyway. One advantage of this code: I tested it and it works. > Greetings, > Maarten Hofman. > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- FCC Rules Updated Daily at http://www.hallikainen.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist