Hi DarreL
Thanks for Your help
Here is a short code that work in the shiftout version, can you see why the
spi variant not work, i never used spi before.
The pic is 18F452 and the osc is 16Mhz
The data i sent to a little TFT display and with the Shiftout it works fine but a little slow
"Are you connected to the SDO/SCK pins of the pic?
SDO(PIC) to SDI(slave), AND SCK(PIC) to SCK(slave)."
Yes
Lcd_port var PORTC 'Using Port C in the program with the command
Rs var lcd_port.1
Cs var lcd_port.2
Sdata var Lcd_port.5 'spi out pin
Sclk var Lcd_port.3 'spi clk pin
DEFINE OSC 16
TRISC = 0
contrast var byte
lcd_out var byte
contrast = 1
'spi setup
SSPEN VAR SSPCON1.5 'SSP Enable bit
CKP VAR SSPCON1.4 'Clock Polarity Select
SMP VAR SSPSTAT.7 'Data input sample phase
CKE VAR SSPSTAT.6 'Clock Edge Select bit
SSPIF VAR PIR1.3 'interrupt flag - last bit set
CKP = 0 'clock idle low
CKE = 0 'transmit on idle to active transition
SSPIF = 0 'clear SPI interrupt
SMP = 0
main:
gosub adj_contrast
contrast = contrast + 1
pause 1000
goto main
adj_contrast:
Command = 0 'command
Lcd_out = $25 'comand contrast setting
Gosub Lcd_sendbyte
Command = 1 'Parameter
Lcd_out = contrast '..adjust contrast from 0...127
Gosub Lcd_sendbyte
return
Lcd_sendbyte:
SSPEN = 0 'desable SPI pins
cs = 0 'Cs = 0 to start of sequence
sclk = 0 'Clock line to 0
sdata = 1 '1 = parameter
If Command = 0 Then
sdata = 0 '0 = cmd
Endif
sclk = 1
'9 bit ' set it manual to indicate if the next byte is command or parameter
'----------------------------------------------------------------------
SSPEN = 1 'enable SPI pins
SSPBUF = lcd_out 'send variable
''''' Shiftout sdata , sclk ,MSBFIRST, [Lcd_out]' 'send bit after bit of the
'value of variable "Output"
cs = 1 'Cs to 1 at end of sequence
Return
Best regards
Pedro
Bookmarks