PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 27, 2004 4:04 pm |
|
|
Analog Devices has ASM code for a 16F873 here:
http://www.analog.com/UploadedFiles/Associated_Docs/317740795RMS_CODE.txt
You could translate it to C.
For example, this section of the ASM code sets up the SPI module:
Code: | ;---------setup spi port for 7756 communication-------------------
; movlw B'00000010' ;set up spi as master fos/64 idle state high
movlw B'00000001' ;set up spi as master fos/16 idle state high
; movlw B'00000000' ;set up spi as master fos/4 idle state high
movwf SSPCON ; mov w to spi control register
movlw B'00000000'
bsf STATUS,5 ;set to bank 1
movwf SSPSTAT ;set up clk edges
bcf STATUS,5 ;set to bank 0
; movlw B'00100000' ;set up spi as master fos/4 idle state high
; movlw B'00100001' ;set up spi as master fos/16 idle state high
; movwf SSPCON ;mov w to spi control register
bsf SSPCON,5 |
If you study that code, and then also study the ASM code generated
by the CCS compiler for the setup_spi() library function, then you
can see that this line of C code does the same thing:
Code: | setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16); |
That's probably the easy part. If I was writing the driver, I would look
at page 5 of the ADE7756 data sheet which shows the SPI read and
write timing diagrams. I would use CCS library functions to do the
same thing as shown in the diagrams. |
|