View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 589 Location: Des Moines, Iowa, USA
|
Arduino digitalWrite() (or 8-bit output_x() call?) |
Posted: Wed Apr 08, 2020 11:18 am |
|
|
I inherited some code for an LCD display. It has an 8-bit parallel interface using I/O lines.
The existing code was using:
...to blast out the data, which was fine when only those first PIN_C0-PIN_C7 were being used. But the latest hardware revision is using some other pins, and this output_c() messes things up.
In an Arduino sound project I have, I had to do something similar like this:
Code: | /* Set 8 pins to the bits of the byte. */
digitalWrite(SN76489_D0, (b & bit(0)) ? HIGH : LOW);
digitalWrite(SN76489_D1, (b & bit(1)) ? HIGH : LOW);
digitalWrite(SN76489_D2, (b & bit(2)) ? HIGH : LOW);
digitalWrite(SN76489_D3, (b & bit(3)) ? HIGH : LOW);
digitalWrite(SN76489_D4, (b & bit(4)) ? HIGH : LOW);
digitalWrite(SN76489_D5, (b & bit(5)) ? HIGH : LOW);
digitalWrite(SN76489_D6, (b & bit(6)) ? HIGH : LOW);
digitalWrite(SN76489_D7, (b & bit(7)) ? HIGH : LOW); |
Not nearly as nice as a PORT command.
Is there a digitalWrite() equivalent in CCS? I ended up doing this, but it's very slow:
Code: | // Yuck.
if (command & bit(0)) { output_high(LCD0_PIN); }else{ output_low(LCD0_PIN); }
if (command & bit(1)) { output_high(LCD1_PIN); }else{ output_low(LCD1_PIN); }
if (command & bit(2)) { output_high(LCD2_PIN); }else{ output_low(LCD2_PIN); }
if (command & bit(3)) { output_high(LCD3_PIN); }else{ output_low(LCD3_PIN); }
if (command & bit(4)) { output_high(LCD4_PIN); }else{ output_low(LCD4_PIN); }
if (command & bit(5)) { output_high(LCD5_PIN); }else{ output_low(LCD5_PIN); }
if (command & bit(6)) { output_high(LCD6_PIN); }else{ output_low(LCD6_PIN); }
if (command & bit(7)) { output_high(LCD7_PIN); }else{ output_low(LCD7_PIN); } |
Or maybe there is an 8-bit output_x() equivalent?
Thanks... _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19591
|
|
Posted: Wed Apr 08, 2020 12:05 pm |
|
|
OK. You must get into the habit of telling people that you are talking
about 16bit PIC's. You know you are, but a casual poster coming in
is going to be totally puzzled....
Now two choices:
First you could just write to the low byte of port C with:
Code: |
#byte LATCL=getenv("SFR:LATC")
LATCL=value;
|
Will write the byte to just C0 to C7. However it will not change the
TRIS. So you would need to set this yourself.
This then won't change the other bits on PORTC.
Output_bit will do the equivalent to the digital_write, but in fact the
output_high/low that you have will be more efficient.
However your 'if' would be more efficient if you use bit_test, rather
that the &.
If you manually set the tris before starting, the direct write to the
LATC low byte will be the most efficient code. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 589 Location: Des Moines, Iowa, USA
|
|
Posted: Wed Apr 08, 2020 2:23 pm |
|
|
Ttelmah wrote: | OK. You must get into the habit of telling people that you are talking
about 16bit PIC's. You know you are, but a casual poster coming in
is going to be totally puzzled....
|
Noted! This is the only PIC I have ever worked with so I keep thinking "PIC is PIC"
Quote: |
Now two choices:
First you could just write to the low byte of port C with:
Code: |
#byte LATCL=getenv("SFR:LATC")
LATCL=value;
|
Will write the byte to just C0 to C7. However it will not change the
TRIS. So you would need to set this yourself.
This then won't change the other bits on PORTC.
|
Ah, just like the manual accesses of bits I used when I was doing my own I2C code. That's exactly what I was hoping to find. Our screen refresh is retro-slow right now.
I'll give it a shot! And thanks for the bit test note. I was not aware of that. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 589 Location: Des Moines, Iowa, USA
|
|
Posted: Wed Apr 08, 2020 2:42 pm |
|
|
Thank you so much! It's nice to have my faster LCD screen back.
I was hoping #USE_FIXED_IO might be taking care of TRISx for me, but no luck.
Code: |
// Lower 8-bits of the 16-bit PORT C output state
#byte TRISCL=getenv("SFR:TRISC")
// Lower 8-bits of the 16-bit PORT C
#byte LATCL=getenv("SFR:LATC")
...
//output_c (data); //Send the command to the LCD port
TRISCL = 0x0;
LATCL = data;
|
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19591
|
|
Posted: Thu Apr 09, 2020 12:45 am |
|
|
Historically, the 'PIC' was originally chips like the PIC16F87x. So 8bit
internal architecture. 98%+ of the people here are still using derivatives
of this.
The DsPIC's are by comparison a relatively 'recent' development.
Glad to have given you back your speed. |
|
|
microjack64
Joined: 10 Apr 2020 Posts: 7
|
my suggestion |
Posted: Fri Apr 10, 2020 4:34 am |
|
|
one of the best microcontroller is pic16f676
pic 16f676 is small on chip oscillator
its price is very low
it is easy to understand
thanks _________________ mini engineer at https://projectiot123.com |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19591
|
|
Posted: Fri Apr 10, 2020 5:15 am |
|
|
On a scale of 1.10 for 'sensible recommendations', this is about a -5....
This is an old chip. One step away from eventually being withdrawn
(though Microchip do keep selling old chips for a long time).
There are newer chips that are:
1) Cheaper.
2) More powerful.
3) Faster.
4) Have cleaner internal architectures (The PIC18's are a lot easier to
work with than PIC16 devices).
5) Have more peripherals and flexibility in how the peripherals are used.
6) Have a more accurate oscillator.
7) Draw less power.
Unless you have a drawer full of these you want to use. Look at one of the
more modern replacements... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9272 Location: Greensville,Ontario
|
|
Posted: Fri Apr 10, 2020 7:52 am |
|
|
re: Unless you have a drawer full of these you want to use.
..I've still got a tube or 2 of PIC16C71 and PIC16C84 here.....
Now as to WHERE my UV eraser is... that's the 64KB question !
I've kinda settled on the 18F46K22 and smaller 26k22 for 99% of my projects. Seems to have lots of internal peripherals, esp. 2 HWUARTS and 2 HW I2C. I know there are newer, 'better' PICs but these work for me....
Jay |
|
|
|