Not exactly sure what you mean by "I have 40x1 and outputs are going to short."have that axe033 module and is it possible to change display like Nokia 3310 glcd?
The idea is to drive glcd as simple is possible. I have 40x1 and outputs are going to short.
That code didn't work for me for some reason. However, I did stumble across this code, also from the yahoo group and same author - not too sure if it is a later version, but it works for me. I did need to tailor it to my needs regarding output pins used (I,m also using the i2c outputs, etc)And here are the other files from the post on Yahoo forum:
....not supported by the 18X, so the manual suggests some code...which is being used hereAlthough the code has symbols with the names SCLK and SDA infering i2c comms, at first glance it looks more like basic (no pun) serial bit banging.
Try the SHIFTOUT command (see manual 2 page 159). This certainly works with my 40X1 to shift data into a 74HC595.
in the subroutine WriteToLCD:
In place of the for Loop2 = 1 to 8 . . . . Next Loop2
try:
SHIFTOUT SCLK, SDA, MSBFIRST_L, (Value / 8)
Not sure why you wouldn't want to use 8MHz. I use it whenever I can, it's as reliable as 4MHz, gives faster execution and adds only a minimal increase in current consumption.as you can see from the original authers code, he is forcing the 18x to 8meg. I,d prefer not to do that in my final code, but hey.
It's not the most efficient code ...The original author has used the bit-banging examples from manual 2 - is there a quicker way to push out the serial data? I,m wondering if the maths used is slowing the whole process down.
WriteToLCD:
high DC 'Data mode
If Command = 0 Then DataMode
low DC 'Command mode
DataMode:
low CS
For Loop2 = 1 To 8
low SCLK
Mask = Value & 128
low SDA
If Mask = 0 Then Skiphigh
high SDA
Skiphigh:
high SCLK
Value = Value * 2
Next Loop2
high CS
Return
WriteToLCD:
high DC 'Data mode
If Command = 0 Then DataMode
low DC 'Command mode
DataMode:
low CS
For Loop2 = 1 To 8
low SCLK
[b]SDA_PIN = bit7[/b]
high SCLK
Value = Value * 2
Next Loop2
high CS
Return
WriteToLCD:
high DC 'Data mode
If Command = 0 Then DataMode
low DC 'Command mode
DataMode:
low CS
For Loop2 = 1 To 8
SDA_PIN = bit7
[b]PulsOut SCLK,1[/b]
Value = Value * 2
Next Loop2
high CS
Return
[b]WriteCommandToLCD:
Low DC
WriteDataToLCD:[/b]
Low CS
For Loop2 = 1 To 8
SDA_PIN = bit7
PulsOut SCLK,1
Value = Value * 2
Next Loop2
High CS
[b]High DC[/b]
Return
WriteCommandToLCD:
Low DC
WriteDataToLCD:
Low CS
[b]SDA_PIN = bit7 : PulsOut SCLK,1
SDA_PIN = bit6 : PulsOut SCLK,1
SDA_PIN = bit5 : PulsOut SCLK,1
SDA_PIN = bit4 : PulsOut SCLK,1
SDA_PIN = bit3 : PulsOut SCLK,1
SDA_PIN = bit2 : PulsOut SCLK,1
SDA_PIN = bit1 : PulsOut SCLK,1
SDA_PIN = bit0 : PulsOut SCLK,1[/b]
High CS
High DC
Return
Mmmmm...nor do I - the speed is there, so why not use it?Not sure why you wouldn't want to use 8MHz. I use it whenever I can, it's as reliable as 4MHz, gives faster execution and adds only a minimal increase in current consumption.
....yep I already done that bitIt's not the most efficient code ...
There's plenty of scope for optimisation there. The use of MASK can be avoided by making 'value' to be b0 or b1 then using bit7 or bot15 for fast access to the msb. Note 'command' is bit0 so that may need to be moved. With that done, SDA can be SYMBOL SDA_PIN = pin1 and SDA_PIN = value giving ...Code:WriteToLCD: high DC 'Data mode If Command = 0 Then DataMode low DC 'Command mode DataMode: low CS For Loop2 = 1 To 8 low SCLK Mask = Value & 128 low SDA If Mask = 0 Then Skiphigh high SDA Skiphigh: high SCLK Value = Value * 2 Next Loop2 high CS Return
If it's not necessary to lower SCLK before setting the data ( I'm not familiar with ths LCD ) the LOW/HIGH SCLK can become a fast PULSOUT ...Code:WriteToLCD: high DC 'Data mode If Command = 0 Then DataMode low DC 'Command mode DataMode: low CS For Loop2 = 1 To 8 low SCLK [b]SDA_PIN = bit7[/b] high SCLK Value = Value * 2 Next Loop2 high CS Return
The routine can be split into two, one to write data, the other to write commands. Data is sent more frequently so that should be the fastest ...Code:WriteToLCD: high DC 'Data mode If Command = 0 Then DataMode low DC 'Command mode DataMode: low CS For Loop2 = 1 To 8 SDA_PIN = bit7 [b]PulsOut SCLK,1[/b] Value = Value * 2 Next Loop2 high CS Return
THAT is a good idea - I will try that next!Finally, for maximum speed the FOR-NEXT loop should be unrolled, which also removes the time taking multiply ...Code:[b]WriteCommandToLCD: Low DC WriteDataToLCD:[/b] Low CS For Loop2 = 1 To 8 SDA_PIN = bit7 PulsOut SCLK,1 Value = Value * 2 Next Loop2 High CS [b]High DC[/b] Return
All untested, but that's how I'd approach it.Code:WriteCommandToLCD: Low DC WriteDataToLCD: Low CS [b]SDA_PIN = bit7 : PulsOut SCLK,1 SDA_PIN = bit6 : PulsOut SCLK,1 SDA_PIN = bit5 : PulsOut SCLK,1 SDA_PIN = bit4 : PulsOut SCLK,1 SDA_PIN = bit3 : PulsOut SCLK,1 SDA_PIN = bit2 : PulsOut SCLK,1 SDA_PIN = bit1 : PulsOut SCLK,1 SDA_PIN = bit0 : PulsOut SCLK,1[/b] High CS High DC Return
I will look into that, although I,m already using the I2C bus.To get maximum speed, using the on-chip SPI hardware where available is the best approach. The 28X1 and 40X1 support that and the 18X can be coerced into doing it with a bit of SFR jiggery-pokery. It may mean having to re-allocate your I/O lines to do that but the speed gains will be quite phenomenal.
--.--
.|.
.-------. |_|
| | |
| SCK |----.----|>|----.-----^-----> I2C SCK
| | | ___ |
| | `---|___|---|-----.-----> SPI CLK
| | | |
| SEL |----.----|>|----' |
| | | |
`-------' `----|<|----------'
Well all of the above code tips have helped to make things noticeably faster and 'good enough' for me, so I,m not planning on any hardware changes.HSPIOUT can be faked on the 18X by poking the right SFR's. There's a post somewhere about doing that. Using I2C does present a problem though as SPI and I2C both use the same I/O pins. Some diode mixing / clamping to select between I2C and SPI could work there; force I2C SCK high and it'll never see a Start Bit, clamp SPI CLK low and the LCD will never clock data in. Both are uni-directional lines so should work ...
SEL = 1, SPI EnabledCode:--.-- .|. .-------. |_| | | | | SCK |----.----|>|----.-----^-----> I2C SCK | | | ___ | | | `---|___|---|-----.-----> SPI CLK | | | | | SEL |----.----|>|----' | | | | | `-------' `----|<|----------'
SEL = 0, I2C Enabled
Maybe not ... The diode from SCK to I2C SCK is the wrong way round, but there's probably some solution to be had along those lines.
[B][COLOR=#ff0000]I2CChip.com: [/COLOR]Mixing I2C and SPI on the same pins:[/B]
[B]Contents[/B]
[LIST]
[*][URL="http://www.i2cchip.com/mix_spi_i2c.html#Summary"][COLOR=#0000ff]Summary[/COLOR][/URL]
[*][URL="http://www.i2cchip.com/mix_spi_i2c.html#Other Serial Devices for Expansion"][COLOR=#0000ff]Other Devices[/COLOR][/URL]
[*][URL="http://www.i2cchip.com/digital_display_module.html#contents"][COLOR=#0000ff]4 Digit Display Modules[/COLOR][/URL]
[*][URL="http://www.i2cchip.com/index.html"][COLOR=#0000ff]Back to Home[/COLOR][/URL][/LIST]Graham North wrote "[I]Is there such a thing as an SPI port expander?
I know there [/I][I]is such an I2C > device (I2C Parallel port). As I am
running out of I/O and the [/I][I]design uses > SPI peripherals[/I]"
[B]You can normally mix I2C and SPI on the [/B][B]same pins with
no problems.[/B]
You can normally mix I2C and SPI on the same pins. I2C only
does something [I][B]between[/B][/I] START and STOP.
START is when SCL is HI, SDA goes to HI->LO.
STOP is when SCL is HI and SDA goes LO->HI.
So if you arrange your code such that SDA only changes value
when SCL is LO, there will be no problems. The I2C will not
notice any SPI transactions. Of course all the SPI devices have
thier own individual CS pin, but this is the disadvantage of SPI.
So to spell it out.
[LIST]
[*]You can use I2C devices on an SPI bus. Just connect SCL to
SCLK and SDA to SDIO.
[*]You can use SPI devices on an I2C bus, just give each chip
its own CS signal.
[*]Between START and STOP you can only do I2C transactions.
[*]The bit timing will be set by the I2C bus,even when doing SPI,
ie use 100 or 400kHz
[*]Write your routines so that SCL and SDA don't change at the
same time. This also removes the problem of SPI devices with
rising vs falling clock
[*]The "SPI" type devices do have to have a common-able data
in and out pins.
[*]You can use the same routines for both if you are short of code
space. Some SPI devices will need non 8 bit sized transfers.
[*]I2C devices have noise filters on the input. SPI devices don't.
Bear this in mind if you have long cable runs.
[*]You will need to have a reset function that makes sure everything
is in the correct state. In particular, some non-I2C serial devices
needs some clocks to bring them into a defined state.[/LIST]
Four for £4 ? Blimey, I paid £3 for 1 off ebay a couple of months back.For any Brits that may be interested,
now that the hard work on the code has been done!
I've just received four Nokia LCD's, from an ebay seller.
£4.02, including postage.
Brass(?) springy-legs on the back. I've bent back four of the legs,
to make soldering a bit easier.
One day, I might finish it.
e