[sdiy] Keyboard with PIC microcontroller
simon.oo.o at xs4all.nl
simon.oo.o at xs4all.nl
Fri Aug 26 09:18:06 CEST 2005
Hi Stefano,
kernel255\.mailinglis zei:
> Hi all,
> I have developed a small circuit to read keys of a keyboard with a PIC
> microcontroller. I have already developed the hardware, but I have some
> problem in developing the software with Assembler. I checked the PIC's CPU
> instructions and I haven't found any instruction to do indirect addressing
> or indexed addressing; I explain it by a simple C example:
>
> #define BufferSize 5
>
> char buffer[BufferSize],data,i;
> char *bufferPtr = buffer;
>
> for(i=0;i<BufferSize;i++)
> {
> data = *(bufferPtr+i);
> /* ... do something on data ... */
> }
>
> What I'm not able to do with PIC Assembler is to have a pointer to memory,
> increment it, and read or write the memory location pointed by it. I
> searched for a special register to do stuff like these (as append for
> other CPUs) but I haven't found it.
The index register in a PIC is called FSR.
The data it points to can be read and written via INDF.
Example:
movlw bufstart ; bufstart defined as start address of buffer
movwf FSR ; SFR now points to start of buffer
movlw d'5'
movwf count
Loop:
movfw INDF ; get next byte
call Putchar ; (or something)
incf FSR ; increase pointer
decfsz count
goto Loop
Vriendelijke groet,
Simon Brouwer
--> nl.openoffice.org <--
More information about the Synth-diy
mailing list