Hserin/Hserout question


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2007
    Posts
    5

    Default Hserin/Hserout question

    What I'm trying to do is use Hyperterminal to send keys pressed from the computer keyboard to the Lab x-1 LCD but only on the first line of the LCD and to hyperterminal, also send the keys from the Lab x-1 keyboard to Hyperterminal and also to line 2 of the LCD. The code I have below does that but I want to be able to see all the keys I've been pressing and not have them be cleared each time I press a key on either keyboard so in other words have them saved on their corresponding lines. Any help or pointing in the right direction would be helpful.

    Code:
    Define	LOADER_USED	1
    
    ' Define LCD registers and bits
    Define  LCD_DREG        PORTD
    Define  LCD_DBIT        4
    Define  LCD_RSREG       PORTE
    Define  LCD_RSBIT       0
    Define  LCD_EREG        PORTE
    Define  LCD_EBIT        1
    
    
    char    var     byte            ' Storage for serial character
    col     var     byte            ' Keypad column
    row     var     byte            ' Keypad row
    key     var     byte            ' Key value
    lastkey var     byte            ' Last key storage
    
    
            ADCON1 = 7              ' Set PORTA and PORTE to digital
            Low PORTE.2             ' LCD R/W line low (W)
    	Pause 500		' Wait for LCD to startup
    
            OPTION_REG.7 = 0        ' Enable PORTB pullups
    
            key = 0                 ' Initialize vars
            lastkey = 0
    
    
            Lcdout $fe, 1           ' Initialize and clear display
    
    loop:   Hserin 1, tlabel, [char]        ' Get a char from serial port
            LCDOUT $fe, $80, char           ' Send char to display
    		HSEROUT [char]					' Send char to Hyperterminal	
    tlabel: Gosub getkey            ' Get a keypress if any
            If (key != 0) and (key != lastkey) Then
                    LCDOUT $fe, $C0, key   ' Send key out serial port
            		HSEROUT [key]			'Send key to hyperterminal
    		Endif
            lastkey = key           ' Save last key value
            Goto loop               ' Do it all over again
    
    ' Subroutine to get a key from keypad
    getkey:
            key = 0                 ' Preset to no key
            For col = 0 to 3        ' 4 columns in keypad
                    PORTB = 0       ' All output pins low
                    TRISB = (dcd col) ^ $ff ' Set one column pin to output
                    row = PORTB >> 4        ' Read row
                    If row != $f Then gotkey        ' If any keydown, exit
            Next col
    
            Return                  ' No key pressed
    
    gotkey: ' Change row and column to ASCII key number
            key = (col * 4) + (ncd (row ^ $f)) + "0"
            Return                  ' Subroutine over
    
            End

  2. #2
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    You forgot to define hserin and hserout.
    like this !
    DEFINE HSER_TXSTA 20H
    DEFINE HSER_RCSTA 90H
    DEFINE HSER_SPBRG 4
    DEFINE HSER_CLROERR 1

  3. #3
    Join Date
    Apr 2007
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Sorry but why would I need to use those defines when it's already sending and receiving from the Hyperterminal and the keys on the LabX-1 with the code I've displayed in the first post? Unless that will help my situation of savin gthe keys pressed on the LCD instead of them being cleared each time I press another key.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Philley View Post
    Sorry but why would I need to use those defines when it's already sending and receiving from the Hyperterminal and the keys on the LabX-1 with the code I've displayed in the first post? Unless that will help my situation of savin gthe keys pressed on the LCD instead of them being cleared each time I press another key.
    I'm guessing here, but I'd bet the 'DEFINE LOADER_USER 1' might have already set up the serial port for use with the bootloader. Check your .asm & .lst file for anything relating to setting the serial port registers. Either that or PBP used some default values for the serial port, kinda like a 'run home to momma' mode.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    NOPE... nothing to do with the Bootloader, if you use HSERIN/HSEROUT without DEFINEs, it use the default setting : 2400 Baud
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    LCDOUT $FE, $C0
    sure, this always set the cursor at the begining of the 2nd line. You could use another variable to keep the current LCD position offset and increment it each time you have a successful keypress.
    Code:
            If (key != 0) and (key != lastkey) Then
                    LCDOUT $fe, ($C0+Line2Position), key   ' Send key out serial port
          		HSEROUT [key]			'Send key to hyperterminal
                    Line2Position=Line2Position+1
                    If Line2Position=17 then
                            Line2Position = 0
                            LCDOUT $FE,$C0,rep " "\16 ' clear line 2
                            HSEROUT [13,10]
                            ENDIF
    
    		Endif
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    NOPE... nothing to do with the Bootloader, if you use HSERIN/HSEROUT without DEFINEs, it use the default setting : 2400 Baud
    Well, the reason I mentioned the Bootloader doing the setup for the serial port registers was that when I start up HyperTerminal, it comes up at 9600/8/N/1, Xon/Xoff. I know the HSerIn/Out defaults are 2400, but that would mean that you'd have to change the HyperTerminal settings. The original poster never mentioned anything about baud rate or anything on either side, so I'm just guessing...

  8. #8
    Join Date
    Apr 2007
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Thanks mister_e I'll try that out and get back to ya on my progress.

Similar Threads

  1. Timer0 Instant Interrupts Question
    By wmarchewka in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2009, 05:29
  2. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14:30
  3. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  4. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49
  5. Timer / CCP Question
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd November 2005, 08:22

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts