Shop OBEX P1 Docs P2 Docs Learn Events
sending character to lcd 2x16 parallax the lcd giving incorrect characters to input — Parallax Forums

sending character to lcd 2x16 parallax the lcd giving incorrect characters to input

cc_buildercc_builder Posts: 12
edited 2013-10-16 10:43 in General Discussion
I have to use basic assembler language to send characters to LCD,

I have got a code written , but i don't get the correct symbol back. I keep getting '/' symbol for all spaces

the lcd is connected to portb7

I'm using of baud 9600,
Therefore the delay is 104us

code is attached

Any advice greatly appreciated




lcd2.asm

Comments

  • whickerwhicker Posts: 749
    edited 2013-10-13 21:41
    It probably wouldn't hurt to remove the extra MOV data_temp, data instructions as pointed out.
    MOV data_temp, data        <----- this makes sense, data_temp = data
    ldi r24, 0x01             //r24 = 1
    and data_temp,r24         //r24 and 1 = the lsb of data
    out PORTB, data_temp
    
    call delay_100us
    
    lsr data_temp              <---- shift right to get to the next bit, but...
    MOV data_temp,data         <---- you're going back to using the lsb of data
    and data_temp,r24
    out PORTB, data_temp
    
    call delay_100us
    
    lsr data_temp
    MOV data_temp,data         <---- now instead of the 3rd bit, we're still at the lsb
    and data_temp,r24
    out PORTB, data_temp
    
  • cc_buildercc_builder Posts: 12
    edited 2013-10-13 22:32
    i changed it but now i get nothing from the lcd
  • whickerwhicker Posts: 749
    edited 2013-10-13 22:53
    is this the first time you've tried to write a serial shift out routine? or is this tried and true code?


    I think that if you aren't inverting, a start bit is actually a "1", and then a stop bit is a "0"


    and is the DDRB being set properly? you're setting the MSB of Port B to output, if 1 means output for that register.
    basically DDRB = 0B10000000 (same as 0x80), as in bit 7 of that port's direction register is being set to 1.

    but then comes the "OUT PORTB, data_temp", in which the data is being ANDed with 0x01 from r24
    this is setting B0 to the present bit, but setting all the other bits in the output register (B1 thru B7) to 0.

    so what I'm saying is, first determine what bit of PORTB you want to be using, B0 or B7?
  • cc_buildercc_builder Posts: 12
    edited 2013-10-13 22:59
    My understanding of it is that we are sending information out of PortB7,

    we are sending bit 0 first

    therefore portb7 would be a output.

    what the program is suppose to:
    for take the char '1' which 00110001

    we want to send either 1 or 0 each time to the lcd.

    so therefore we AND 0000 0001
    so the bit 0 is going to be sent first.

    then shift right so you get 00011000
    and 000000001 giving you 0 and send it out

    and repeat for each bit.

    therefore your sending 0000 0000 or 00000001

    I'm keep getting ' \' which is decimal 92, doesn't matter what data i put
  • whickerwhicker Posts: 749
    edited 2013-10-13 23:13
    \ is on the ascii sheet as character 92. but on your LCD it might be character 127 = 0x7F, which would make some sense (kind of). again take a look at my last post, you're almost there.

    also look at this diagram:
    http://en.wikipedia.org/wiki/File:Rs232_oscilloscope_trace.svg
  • whickerwhicker Posts: 749
    edited 2013-10-13 23:32
    > therefore your sending 0000 0000 or 00000001

    yes, correct. but that rightmost bit is typically the LSB, which will be B0 of Port B on any processor that I know of, and not B7.
  • cc_buildercc_builder Posts: 12
    edited 2013-10-13 23:49
    yes that's correct, but changing the input character has no effect on the output i still get ' \ '
  • whickerwhicker Posts: 749
    edited 2013-10-14 00:06
    A serial device is going to interpret any bit toggling pattern as data.

    looking here, where you had set r1 to 0xFF way earlier (clr r1 ; dec r1):
    out PORTB,r1
    
    call delay_100us
    
    ret
    

    is causing B7 to be set to 1, the bit being driven as output because of how DDRB was set. (ldi temp,0B10000000 ; out DDRB, temp)
    then sometime later port B is being set back to 0.

    This signal transition is enough for a serial device connected to B7 to interpret it as some sort of data. Some kind of 0->1->0 transition shorter than 9 bits will make a serial device think it's receiving a character.
  • cc_buildercc_builder Posts: 12
    edited 2013-10-14 00:18
    So to fix this i should increase the delay, to 500 or 10 ms ?
    so it doesn't have any effect or find ldi 225 to a register than out it
  • whickerwhicker Posts: 749
    edited 2013-10-14 00:29
    No, to start you would need to set DDRB to 1, not 0B10000000
    and then wire the portB0 pin to the LCD 2x16, not portB7.


    if you are required to use portB7 you will need to rewrite all of "serial_out:"
  • cc_buildercc_builder Posts: 12
    edited 2013-10-14 01:02
    I need to write for PORTB7, how would i do it portb7 would I send the MSB first
  • GenetixGenetix Posts: 1,754
    edited 2013-10-14 02:04
    Is this a Parallax Serial LCD?

    Custom Character 0 for the Parallax Serial LCD is backslash or \. If you send a code 0 to the LCD then backslash will appear.

    Also, the Parallax LCD uses true serial (0 is a 0, 1 is a 1), not inverted voltages such as in RS-232.
  • cc_buildercc_builder Posts: 12
    edited 2013-10-14 02:54
    Yes it is parallax serial lcd,
    So therefore i have to bit 0 put in bit 7,
    then and it with 1000 0000
    then send it ?
  • cc_buildercc_builder Posts: 12
    edited 2013-10-14 04:28
    This is what i'm think ror making the number carry
    then rotating the carry in bit7
    but how do i move the carry to bit7
  • cc_buildercc_builder Posts: 12
    edited 2013-10-14 05:43
    Attachment not found.

    I got it working, now im getting the wrong characters i'm tried fixing it i either get the incorrect high or lower bits.
    In the code below

    when i put 00110010 suppose to be 2 i get 9.
    any suggestion on fixing , i'm assuming i'm loading a bit wrong but i'm can't figure it out any help
    greatly appreciated
  • Mike GreenMike Green Posts: 23,101
    edited 2013-10-14 07:51
    Please do not start another thread for essentially the same topic. It's against forum guidelines.
  • cc_buildercc_builder Posts: 12
    edited 2013-10-14 08:09
    I figured it out but i getting problems getting wrong characters any help appreciatedmy_idea-2.asm
  • whickerwhicker Posts: 749
    edited 2013-10-14 10:54
    in RS232, a start bit is a bit that is always 1 and a stop bit is always 0.
    for 9600 8N1 you need to send 10 total bits.

    a start bit of "1" comes before bit 0 of data
    a stop bit of "0" comes after bit 7 of data
  • cc_buildercc_builder Posts: 12
    edited 2013-10-14 13:54
    I did what you still not getting the correct characters what a wrote is below
    when i put hexadecimal 32, i get 34 instead of2
    when i put 33 i get 3C
  • whickerwhicker Posts: 749
    edited 2013-10-14 23:34
    okay, let's back up.


    it looks like you had it right with the start bit being "0", and then the stop bit being "1"

    start out at the "1" level like this:
    ldi temp,$FF
    out DDRB, temp
    out PORTB,temp
    

    then start bit is:
    out PORTB,r0

    then stop bit is:
    out PORTB,r1


    does it still display characters close to what you want with it this way?
  • cc_buildercc_builder Posts: 12
    edited 2013-10-15 23:50
    Now I get nothing on the LCD
  • whickerwhicker Posts: 749
    edited 2013-10-16 10:43
    I guess I'm out of ideas.

    maybe it has to do with the clock frequency source... is it a resonator, crystal, or internal RC oscillator?

    maybe it has to do with adjusting the 100us wait. for 9600 baud it's really something more like 104us, but over ten bits that would only be off by 4 * 10 = 40 us


    if its just a wire out from a pin on port B7 to RX on the LCD, with nothing in between like an inverter or RS232 signal chip, then according to the documentation, the signal line should be normally at "1" level, then dip down to 0 for a start bit, then send 8 bits, then go back up to 1 for the stop bit. This is what you're doing.

    I am pretty confident your Carry bit isn't getting overwritten by any instructions in-between the ROR's in the code you've posted.
Sign In or Register to comment.