Shop OBEX P1 Docs P2 Docs Learn Events
LCD in 4 bit mode!! Bit level manipulation — Parallax Forums

LCD in 4 bit mode!! Bit level manipulation

Sabre00Sabre00 Posts: 30
edited 2008-09-16 09:52 in Propeller 1
I was doing some reading on the Propeller chip and it seems very interesting. My university supervisor introduced me to the chip and said to give is a try. I am working on a project that needs an LCD screen attached to it and I to conserve I/O pins I am using it in 4-bit mode. I was searching through the manual looking for bit level manipulation for a byte. Since there is a byte level manipulation for a word I saw that bit wasn't a predefined word. So I Came up with the following code taking the example from the outa and dira command;

*note* LCD_DATA is the byte variable that holds the data to be sent to the LCD

outa[noparse][[/noparse]D4] := 0
if LCD_Data [noparse][[/noparse]7]== 1
outa[noparse][[/noparse]D4] := 1
outa[noparse][[/noparse]D3] := 0
if LCD_Data [noparse][[/noparse]6]== 1
outa[noparse][[/noparse]D3] := 1
outa[noparse][[/noparse]D2] := 0
if LCD_Data == 1
outa[noparse][[/noparse]D2] := 1
outa[noparse][[/noparse]D1] := 0
if LCD_Data == 1
outa[noparse][[/noparse]D1] := 1

outa[noparse][[/noparse]D4] := 0
if LCD_Data == 1
outa[noparse][[/noparse]D4] := 1
outa[noparse][[/noparse]D3] := 0
if LCD_Data == 1
outa[noparse][[/noparse]D3] := 1
outa[noparse][[/noparse]D2] := 0
if LCD_Data == 1
outa[noparse][[/noparse]D2] := 1
outa[noparse][[/noparse]D1] := 0
if LCD_Data [noparse][[/noparse]0]== 1
outa[noparse][[/noparse]D1] := 1

I have compiled it but I haven't physically gotten around to connecting it to the LCD as yet. Am I going the right way or is there a bit level manipulator that I overlooked.

Post Edited (Sabre00) : 9/16/2008 10:10:09 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-15 20:41
    Please read the Propeller Manual sections on DIRA and OUTA. You'll find that you can access individual bits and groups of bits like OUTA[noparse][[/noparse] 3..0 ] which accesses bits 3 through 0 with bit 3 as the most significant bit. You could simply assign LCD_Data as in: OUTA[noparse][[/noparse] 3..0 ] := LCD_Data
    All other bit manipulation in Spin is done using logical operations on bytes, words, and long words including | for OR, & for AND, ! for NOT, and various shifts (see the Manual). Note that this special bit string access notation only applies to certain special I/O variables.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-15 20:43
    Bit manipulations can be done via ~ (clear) and ~~ (set), each are postfix operators, so outa[noparse][[/noparse] 0 ]~ is the same as outa[noparse][[/noparse] 0 ] := 0. You can also do sub-field assignments as Mike has pointed out. If your project is using the LCD as part of a larger project, and not to create the driver, you should check out the LCD drivers on the object exchange: http://obex.parallax.com search: LCD. I count at least 3 LCD driver objects, one of them should fit your needs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Sabre00Sabre00 Posts: 30
    edited 2008-09-16 09:52
    Thanks guys. I Wasn't sure which nibble would be assigned with I assigned a byte to a nibble. I guess I could have checked it. In my Object I didn't want to limit the user ( which is myself really, but I since realised that there is an object exchange "centre") of the object to 7 consecutive I/O pins so there is an LCD.init (1,2,-1,4,6,8,19) where the numbers correspond to the Enable, Data/instruction, Read/Write and the four data pins corresponding to data pin 5- 8 on the LCD. Once initialized the user would just then have a LCD.write(1,8,"M") where 1 is the line 8 is the position from 0-15 and M is the character to print to screen. I just wanted to make the object as versatile as possible so if I have to use it in future projects I am not limiting myself to those particular I/O pins or have to change the pins within the object.

    Thanks again guys. I noticed that there are I2C objects in there as well so I would see if I can use any of those in my project.
Sign In or Register to comment.