View previous topic :: View next topic |
Author |
Message |
jwolf
Joined: 18 Jan 2013 Posts: 24
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Oct 20, 2015 7:41 pm Post subject: Re: efficient programming of ports partly in use |
|
|
jwolf wrote: | For the output to PC0 to PC3 I just need to output a number 0 .. 7. |
I do not see use of the 4th bit, 0-7 needs only 3 bits.
Also it is not clear from this chunk of code, where Rowadr0 starts, is it PC0?
If yes and in case "Row" will only contain values 0-7, your whole code can be replaced by:
Code: | I = PORTC AND &h11111000
PORTC = I OR Row |
|
|
Back to top |
|
|
jwolf
Joined: 18 Jan 2013 Posts: 24
|
Posted: Tue Oct 20, 2015 8:20 pm Post subject: Re: efficient programming of ports partly in use |
|
|
Thank you for the reply,
sorry, I mixed up 1 .. 3 with 0 .. 2 - so of course 3 bits are sufficient to code 0 .. 7.
Your understanding is fully correct, Rowadr0 refers to port bit PC0.
I am aware of the possibility to write the entire port, but my fear was what would happen if I write to port bits that are used for other purposes and e.g. used as input?
So far I thought writing a 1 to a port bit that is configured as input would switch on the pull-up resistor?
Or is it only if I write the 1 to the port bit and when writing the entire port nothing would happen to the ports bits configured as input?
Best regards,
Johannes |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Oct 20, 2015 8:31 pm Post subject: Re: efficient programming of ports partly in use |
|
|
jwolf wrote: | Your understanding is fully correct, Rowadr0 refers to port bit PC0. |
Then my code fits.
Quote: | So far I thought writing a 1 to a port bit that is configured as input would switch on the pull-up resistor? |
An AND of &h11111000 with, for example bit 7 (input, no pullup, so content 0), still gives 0, so no modifications done.
Reading a bit with 0 and writing it to 0 doesn't change anything.
Quote: | Or is it only if I write the 1 to the port bit and when writing the entire port nothing would happen to the ports bits configured as input? |
There's one risk: if interrupts write to the same port, then my short code needs to be made atomar, which means encapsulated by a Disable/Enable Interrupts. |
|
Back to top |
|
|
olhexy
Joined: 03 Apr 2011 Posts: 192 Location: Tilburg, Netherlands
|
Posted: Tue Oct 20, 2015 9:08 pm Post subject: Re: efficient programming of ports partly in use |
|
|
jwolf wrote: | Dear forum community,
I have the following problem:
I need for controlling a dot matrix LED display 4 bits of one port (e.g. PC0 .. PC3 of an Atmega ,
whereas other bits of the port (PC4 and PC5) are already in use for I2C.
Any ideas?
(BASCOM-AVR version : 2.0.7.8 ) |
Code: | 'By specifying Wr the library lcd4busy_anypin (based on LUCIANO) will be used
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Wr = Portc.1 , Rs = Portc.0 |
Did you know that you can connect the LCDpins to every Port.bit as you wish?
For example:
Code: | Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Portb.5 , Db6 = Portc.6 , Db7 = Portd.7 , E = Portc.1 , Wr = Portb.2 , Rs = Porta.7 |
I am not sure if this goes for all versions of Bascom LCDlibraries, but if you do specify Wr, then you get lcd4busy_anypin
Wr is in many older Bascom examples connected to ground, not to a Port.
Edit: My comment is for a HD44780 LCDdisplay. May be that a LEDdot display is totally different.
Last edited by olhexy on Tue Oct 20, 2015 9:40 pm; edited 1 time in total |
|
Back to top |
|
|
jwolf
Joined: 18 Jan 2013 Posts: 24
|
Posted: Tue Oct 20, 2015 9:40 pm Post subject: Re: efficient programming of ports partly in use |
|
|
Thank you very much again.
This should solve my problem.
I will re-write my program accordingly and test it.
Best regards,
Johannes |
|
Back to top |
|
|
jwolf
Joined: 18 Jan 2013 Posts: 24
|
Posted: Tue Oct 20, 2015 9:50 pm Post subject: Re: efficient programming of ports partly in use |
|
|
Dear olhexy,
I am not using a LCD display and thus not using any Bascom LCD library,
what I have is a LED dotmatrix with some logic inside which I need to control on low level, selecting lines and writing character patterns digit per digit.
I was also using LCD displays and the related library from Bascom, but was not aware so far of the Wr.
How can you specify Wr then?
Cheers,
Johannes |
|
Back to top |
|
|
olhexy
Joined: 03 Apr 2011 Posts: 192 Location: Tilburg, Netherlands
|
Posted: Tue Oct 20, 2015 10:20 pm Post subject: Re: efficient programming of ports partly in use |
|
|
jwolf wrote: |
How can you specify Wr then?
|
You can just not mention Wr, or comment it out in de config , then it is not specified.
(But then Wr must be connected to GND, or you can also connect to a Port.bit that you set low. With this setting you can only write, reading is not possible. No big problem, because reading LCD is rare. But it (Wr = 1) is needed for reading the Busyflag. In LCDdocs Wr is the same as R/W; it is usually pin 5 at LCDconnection)
If you bring it up in the Config, like then it is specified. Simple! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|