RS232 to LCD issue

Started by Chas Douvier July 17, 2003
I am making the code for a 18F452 "Dumb Terminal" like I previously
was working on. I'll post it on a page sometime or on the piclist
site after I am done. It's pretty close except I am having a problem.

My incoming RS232 is echoed back to the client (for a rough type of
software error correction) then It's written to the second line of a
2x16 LCD. The problem is copying the incoming RS232 to the LCD. I
know my LCD code works fine for writing things from a table, I do
that on initialization. I am having a weird output no matter what
key I press one character comes up The LCD Char Map 1100 0000 (this
is a 44780 based LCD) a forgien character. No matter what key I
press I get this character. I have 4 LED's to show me the LSB 4
digits of the character typed and it works fine. I send a "A" and I
get 0001 and the ASCII matches to 10000001 like it is suppose to
with the LCD 010000001

Does anyone with more technicial experence than me have an idea of
what I am doing wrong? I assume its the code that writes to the
LCD..

Any ideas greatly appericated.

This code is missing some due credit but when i post it, i'll
include proper credit to other people. I stole much of the code to
modify it for myself.

;here is the interupt when I get something on the serial port.

IntVector
; save context (WREG and STATUS registers) if needed.

btfss PIR1,RCIF ; Did USART cause interrupt?
goto OtherInt ; No, some other interrupt

movlw 06h ; Mask out unwanted bits
andwf RCSTA,W ; Check for errors
btfss STATUS,Z ; Was either error status bit set?
goto RcvError ; Found error, flag it

movf RCREG,W ; Get input data
movwf LATB ; Display on LEDs
movwf TXREG ; Echo character back
movwf ptr_pos
call mod_char_2
goto ISREnd ; go to end of ISR, restore context,
return ;----Input, Place characters on line-2--------------------------
mod_char_2
call LCDLine_2 ;move cursor to line 2
movf ptr_pos,W
clrf WREG
call d_write ;send character to LCD
return
;--------------------------------
--

LCDLine_2
movlw 0xC0
movwf temp_wr
rcall i_write
return ;write data
d_write
rcall LCDBusy
bsf STATUS, C
rcall LCDWrite
return

;write instruction
i_write
rcall LCDBusy
bcf STATUS, C
rcall LCDWrite
return

LCDWriteNibble
btfss STATUS, C ; Set the register select
bcf LCD_RS
btfsc STATUS, C
bsf LCD_RS

bcf LCD_RW ; Set write mode

bcf LCD_D4_DIR ; Set data bits to outputs
bcf LCD_D5_DIR
bcf LCD_D6_DIR
bcf LCD_D7_DIR

NOP ; Small delay
NOP

bsf LCD_E ; Setup to clock data

btfss temp_wr, 7 ; Set high nibble
bcf LCD_D7
btfsc temp_wr, 7
bsf LCD_D7
btfss temp_wr, 6
bcf LCD_D6
btfsc temp_wr, 6
bsf LCD_D6
btfss temp_wr, 5
bcf LCD_D5
btfsc temp_wr, 5
bsf LCD_D5
btfss temp_wr, 4
bcf LCD_D4
btfsc temp_wr, 4
bsf LCD_D4

NOP
NOP

bcf LCD_E ; Send the data

return
; ******************************************************************* ; *******************************************************************
LCDWrite
; rcall LCDBusy
rcall LCDWriteNibble
swapf temp_wr,F
rcall LCDWriteNibble
swapf temp_wr,F

return




It is a little too much code to digest at one glance but I would
certainly wonder about 'mod_char_2' and why after the position
pointer was put in W it was cleared by CLRF WREG. --- In , "Chas Douvier" <charles@k...> wrote:
> I am making the code for a 18F452 "Dumb Terminal" like I previously
> was working on. I'll post it on a page sometime or on the piclist
> site after I am done. It's pretty close except I am having a
problem.
>
> My incoming RS232 is echoed back to the client (for a rough type of
> software error correction) then It's written to the second line of
a
> 2x16 LCD. The problem is copying the incoming RS232 to the LCD. I
> know my LCD code works fine for writing things from a table, I do
> that on initialization. I am having a weird output no matter what
> key I press one character comes up The LCD Char Map 1100 0000 (this
> is a 44780 based LCD) a forgien character. No matter what key I
> press I get this character. I have 4 LED's to show me the LSB 4
> digits of the character typed and it works fine. I send a "A" and I
> get 0001 and the ASCII matches to 10000001 like it is suppose to
> with the LCD 010000001
>
> Does anyone with more technicial experence than me have an idea of
> what I am doing wrong? I assume its the code that writes to the
> LCD..
>
> Any ideas greatly appericated.
>
> This code is missing some due credit but when i post it, i'll
> include proper credit to other people. I stole much of the code to
> modify it for myself.
>
> ;here is the interupt when I get something on the serial port.
>
> IntVector
> ; save context (WREG and STATUS registers) if needed.
>
> btfss PIR1,RCIF ; Did USART cause interrupt?
> goto OtherInt ; No, some other interrupt
>
> movlw 06h ; Mask out unwanted bits
> andwf RCSTA,W ; Check for errors
> btfss STATUS,Z ; Was either error status bit set?
> goto RcvError ; Found error, flag it
>
> movf RCREG,W ; Get input data
> movwf LATB ; Display on LEDs
> movwf TXREG ; Echo character back
> movwf ptr_pos
> call mod_char_2
> goto ISREnd ; go to end of ISR, restore context,
> return > ;----Input, Place characters on line-2--------------------------
> mod_char_2
> call LCDLine_2 ;move cursor to line 2
> movf ptr_pos,W
> clrf WREG
> call d_write ;send character to LCD
> return
> ;-------------------------------
-
> --
>
> LCDLine_2
> movlw 0xC0
> movwf temp_wr
> rcall i_write
> return > ;write data
> d_write
> rcall LCDBusy
> bsf STATUS, C
> rcall LCDWrite
> return
>
> ;write instruction
> i_write
> rcall LCDBusy
> bcf STATUS, C
> rcall LCDWrite
> return
>
> LCDWriteNibble
> btfss STATUS, C ; Set the register select
> bcf LCD_RS
> btfsc STATUS, C
> bsf LCD_RS
>
> bcf LCD_RW ; Set write mode
>
> bcf LCD_D4_DIR ; Set data bits to outputs
> bcf LCD_D5_DIR
> bcf LCD_D6_DIR
> bcf LCD_D7_DIR
>
> NOP ; Small delay
> NOP
>
> bsf LCD_E ; Setup to clock data
>
> btfss temp_wr, 7 ; Set high nibble
> bcf LCD_D7
> btfsc temp_wr, 7
> bsf LCD_D7
> btfss temp_wr, 6
> bcf LCD_D6
> btfsc temp_wr, 6
> bsf LCD_D6
> btfss temp_wr, 5
> bcf LCD_D5
> btfsc temp_wr, 5
> bsf LCD_D5
> btfss temp_wr, 4
> bcf LCD_D4
> btfsc temp_wr, 4
> bsf LCD_D4
>
> NOP
> NOP
>
> bcf LCD_E ; Send the data
>
> return
> ;
*******************************************************************
>
>
> ;
*******************************************************************
> LCDWrite
> ; rcall LCDBusy
> rcall LCDWriteNibble
> swapf temp_wr,F
> rcall LCDWriteNibble
> swapf temp_wr,F
>
> return





rtsofer,
 
That was a modified version of the orginal LCD code, I commented the clrf WREG and it had no effect that I could determine.
 
It is a lot of code but if I didn't post it then I was sure someone would ask.  Thank heavens this list has you, I think you are pretty much the only person who answers questions that require a decent level of knowlege (besides Wouter).
 
I'll keep hacking away at it, but it's very difficult to undertsand why the character doesn't at least change.
 
Charkes
 
 
-----Original Message-----
From: rtstofer [mailto:r...@pacbell.net]
Sent: Thursday, July 17, 2003 10:05 AM
To: p...@yahoogroups.com
Subject: [piclist] Re: RS232 to LCD issue


It is a little too much code to digest at one glance but I would
certainly wonder about 'mod_char_2' and why after the position
pointer was put in W it was cleared by CLRF WREG.--- In p...@yahoogroups.com, "Chas Douvier" <charles@k...> wrote:
> I am making the code for a 18F452 "Dumb Terminal" like I previously
> was working on. I'll post it on a page sometime or on the piclist
> site after I am done. It's pretty close except I am having a
problem.
>
> My incoming RS232 is echoed back to the client (for a rough type of
> software error correction) then It's written to the second line of
a
> 2x16 LCD. The problem is copying the incoming RS232 to the LCD. I
> know my LCD code works fine for writing things from a table, I do
> that on initialization. I am having a weird output no matter what
> key I press one character comes up The LCD Char Map 1100 0000 (this
> is a 44780 based LCD) a forgien character. No matter what key I
> press I get this character. I have 4 LED's to show me the LSB 4
> digits of the character typed and it works fine. I send a "A" and I
> get 0001 and the ASCII matches to 10000001 like it is suppose to
> with the LCD 010000001
>
> Does anyone with more technicial experence than me have an idea of
> what I am doing wrong? I assume its the code that writes to the
> LCD..
>
> Any ideas greatly appericated.
>
> This code is missing some due credit but when i post it, i'll
> include proper credit to other people. I stole much of the code to
> modify it for myself.
>
> ;here is the interupt when I get something on the serial port.
>
> IntVector
>       ; save context (WREG and STATUS registers) if needed.
>
>       btfss      PIR1,RCIF      ; Did USART cause interrupt?
>       goto      OtherInt      ; No, some other interrupt
>
>       movlw      06h            ; Mask out unwanted bits
>       andwf      RCSTA,W            ; Check for errors
>       btfss      STATUS,Z      ; Was either error status bit set?
>       goto      RcvError      ; Found error, flag it
>
>       movf      RCREG,W            ; Get input data
>       movwf      LATB            ; Display on LEDs
>       movwf      TXREG            ; Echo character back
>       movwf      ptr_pos
>       call      mod_char_2
>       goto      ISREnd            ; go to end of ISR, restore context,
> return> ;----Input, Place characters on line-2--------------------------
> mod_char_2     
>       call      LCDLine_2            ;move cursor to line 2
>       movf      ptr_pos,W
>       clrf      WREG                   
>       call      d_write                  ;send character to LCD
>       return
> ;-------------------------------
-
> --
>
> LCDLine_2
>       movlw      0xC0
>       movwf      temp_wr
>       rcall      i_write
>       return
>      
>
>       ;write data
> d_write
>       rcall      LCDBusy
>       bsf      STATUS, C     
>       rcall      LCDWrite
>       return
>      
>       ;write instruction
> i_write
>       rcall      LCDBusy
>       bcf      STATUS, C
>       rcall      LCDWrite
>       return
>       
> LCDWriteNibble
>       btfss      STATUS, C            ; Set the register select
>       bcf      LCD_RS
>       btfsc      STATUS, C     
>       bsf      LCD_RS
>
>       bcf      LCD_RW                  ; Set write mode
>
>       bcf      LCD_D4_DIR            ; Set data bits to outputs
>       bcf      LCD_D5_DIR
>       bcf      LCD_D6_DIR
>       bcf      LCD_D7_DIR
>
>       NOP                        ; Small delay
>       NOP
>
>       bsf      LCD_E                  ; Setup to clock data
>      
>       btfss      temp_wr, 7                  ; Set high nibble
>       bcf      LCD_D7     
>       btfsc      temp_wr, 7
>       bsf      LCD_D7
>       btfss      temp_wr, 6
>       bcf      LCD_D6     
>       btfsc      temp_wr, 6
>       bsf      LCD_D6
>       btfss      temp_wr, 5
>       bcf      LCD_D5     
>       btfsc      temp_wr, 5
>       bsf      LCD_D5
>       btfss      temp_wr, 4
>       bcf      LCD_D4
>       btfsc      temp_wr, 4
>       bsf      LCD_D4     
>
>       NOP
>       NOP
>
>       bcf      LCD_E                  ; Send the data
>
>       return
> ;
*******************************************************************> ;
*******************************************************************
> LCDWrite
> ;      rcall      LCDBusy
>       rcall      LCDWriteNibble
>       swapf      temp_wr,F
>       rcall      LCDWriteNibble
>       swapf      temp_wr,F
>
>       return



to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

">Yahoo! Terms of Service.




The incoming char was put in 'ptr_pos' but LCDWriteNibble expects it
to be in temp_wr.

The char you are seeing b'11000000' is really the residue of 0xC0
from LCDLine_2. --- In , "Charles Douvier" <charles@k...>
wrote:
> rtsofer,
>
> That was a modified version of the orginal LCD code, I commented
the clrf
> WREG and it had no effect that I could determine.
>
> It is a lot of code but if I didn't post it then I was sure someone
would
> ask. Thank heavens this list has you, I think you are pretty much
the only
> person who answers questions that require a decent level of knowlege
> (besides Wouter).
>
> I'll keep hacking away at it, but it's very difficult to undertsand
why the
> character doesn't at least change.
>
> Charkes > -----Original Message-----
> From: rtstofer [mailto:rstofer@p...]
> Sent: Thursday, July 17, 2003 10:05 AM
> To:
> Subject: [piclist] Re: RS232 to LCD issue >
> It is a little too much code to digest at one glance but I would
> certainly wonder about 'mod_char_2' and why after the position
> pointer was put in W it was cleared by CLRF WREG. > --- In , "Chas Douvier" <charles@k...>
wrote:
> > I am making the code for a 18F452 "Dumb Terminal" like I
previously
> > was working on. I'll post it on a page sometime or on the
piclist
> > site after I am done. It's pretty close except I am having a
> problem.
> >
> > My incoming RS232 is echoed back to the client (for a rough
type of
> > software error correction) then It's written to the second line
of
> a
> > 2x16 LCD. The problem is copying the incoming RS232 to the LCD.
I
> > know my LCD code works fine for writing things from a table, I
do
> > that on initialization. I am having a weird output no matter
what
> > key I press one character comes up The LCD Char Map 1100 0000
(this
> > is a 44780 based LCD) a forgien character. No matter what key I
> > press I get this character. I have 4 LED's to show me the LSB 4
> > digits of the character typed and it works fine. I send a "A"
and I
> > get 0001 and the ASCII matches to 10000001 like it is suppose to
> > with the LCD 010000001
> >
> > Does anyone with more technicial experence than me have an idea
of
> > what I am doing wrong? I assume its the code that writes to the
> > LCD..
> >
> > Any ideas greatly appericated.
> >
> > This code is missing some due credit but when i post it, i'll
> > include proper credit to other people. I stole much of the code
to
> > modify it for myself.
> >
> > ;here is the interupt when I get something on the serial port.
> >
> > IntVector
> > ; save context (WREG and STATUS registers) if needed.
> >
> > btfss PIR1,RCIF ; Did USART cause interrupt?
> > goto OtherInt ; No, some other interrupt
> >
> > movlw 06h ; Mask out unwanted bits
> > andwf RCSTA,W ; Check for errors
> > btfss STATUS,Z ; Was either error status bit
set?
> > goto RcvError ; Found error, flag it
> >
> > movf RCREG,W ; Get input data
> > movwf LATB ; Display on LEDs
> > movwf TXREG ; Echo character back
> > movwf ptr_pos
> > call mod_char_2
> > goto ISREnd ; go to end of ISR, restore
context,
> > return
> >
> >
> > ;----Input, Place characters on line-2--------------------------
> > mod_char_2
> > call LCDLine_2 ;move cursor to line 2
> > movf ptr_pos,W
> > clrf WREG
> > call d_write ;send character to LCD
> > return
> > ;---------------------------
----
> -
> > --
> >
> > LCDLine_2
> > movlw 0xC0
> > movwf temp_wr
> > rcall i_write
> > return
> >
> >
> > ;write data
> > d_write
> > rcall LCDBusy
> > bsf STATUS, C
> > rcall LCDWrite
> > return
> >
> > ;write instruction
> > i_write
> > rcall LCDBusy
> > bcf STATUS, C
> > rcall LCDWrite
> > return
> >
> > LCDWriteNibble
> > btfss STATUS, C ; Set the register select
> > bcf LCD_RS
> > btfsc STATUS, C
> > bsf LCD_RS
> >
> > bcf LCD_RW ; Set write mode
> >
> > bcf LCD_D4_DIR ; Set data bits to outputs
> > bcf LCD_D5_DIR
> > bcf LCD_D6_DIR
> > bcf LCD_D7_DIR
> >
> > NOP ; Small delay
> > NOP
> >
> > bsf LCD_E ; Setup to clock data
> >
> > btfss temp_wr, 7 ; Set high nibble
> > bcf LCD_D7
> > btfsc temp_wr, 7
> > bsf LCD_D7
> > btfss temp_wr, 6
> > bcf LCD_D6
> > btfsc temp_wr, 6
> > bsf LCD_D6
> > btfss temp_wr, 5
> > bcf LCD_D5
> > btfsc temp_wr, 5
> > bsf LCD_D5
> > btfss temp_wr, 4
> > bcf LCD_D4
> > btfsc temp_wr, 4
> > bsf LCD_D4
> >
> > NOP
> > NOP
> >
> > bcf LCD_E ; Send the data
> >
> > return
> > ;
>
*******************************************************************
> >
> >
> >
> >
> >
> > ;
>
*******************************************************************
> > LCDWrite
> > ; rcall LCDBusy
> > rcall LCDWriteNibble
> > swapf temp_wr,F
> > rcall LCDWriteNibble
> > swapf temp_wr,F
> >
> > return >
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the
> instructions
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.


Chas,

I would be interested in your dumb terminal code when you get it finished.

I want to display text messages on an LCD sent over the phone line from a
PIC at the far end.

I already have the far end PIC sending messages using a software modem
technique, and I have managed to get a F84 to decode Caller ID. All I need
now is a serial display terminal Thanks in advance, Ken Boak



> I already have the far end PIC sending messages using a software modem
> technique, and I have managed to get a F84 to decode Caller
> ID. All I need
> now is a serial display terminal

[AD]
I sell a 24x8 LCD with serial interface for E 23. see
http://www.voti.nl/shop/products.html#LCD-4
[/AD]

Wouter van Ooijen

-- -------
Van Ooijen Technische Informatica: www.voti.nl
consultancy, development, PICmicro products



If you try to use PIC18, the code in mcc18 document: MPLAB-C18-
Libraries.pdf, 3.2.2 example (page 69) is for this use. Can someone
verify if the code works? --- In , "Wouter van Ooijen" <wouter@v...>
wrote:
> > I already have the far end PIC sending messages using a software
modem
> > technique, and I have managed to get a F84 to decode Caller
> > ID. All I need
> > now is a serial display terminal
>
> [AD]
> I sell a 24x8 LCD with serial interface for E 23. see
> http://www.voti.nl/shop/products.html#LCD-4
> [/AD]
>
> Wouter van Ooijen
>
> -- -------
> Van Ooijen Technische Informatica: www.voti.nl
> consultancy, development, PICmicro products