4bit hex decoder w/LCD


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    OK, pretty simple.
    I've renamed the label & removed "END" from the message routine. It compiles OK now. I'll build it on a breadboard and see how it works.

    Thanks for the help.

  2. #2
    Join Date
    Aug 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Once I changed to mode 8 instead of mode 4 for Serout, everything worked up to line 28 of the code below.
    It worked briefly, but begins to lag. Almost instantly, I notice a considerable delay in the response time between a hex value in and the coresponding ASCII display. The delay gets longer after several seconds, then crashes all together. I tried adding a 3 second delay to the loop of this function to reduce the number of serial transmissions to the lcd, but it still doesn't work. The display is erratic. Sometimes when going from bit 16 high to bit 32 high, it will briefly display the sum of the two & after a few seconds delay, then the proper value of "32" is displayed. And the lower 4 bits don't work at all. The display always reads "none" if any of the lower 4 bits is high.
    Do I need a debounce? Should I use a standard LCD instead of the Parallax serial LCD? Or am I likely to have the same problems with a 44780 controlled LCD also? Possibly I need to use interrupts instead of looping the same data over and over until there is a change in state?

    Here's a simplified version of the code with just the LCD functions:

    Code:
    'program for integrated firing panel
    'portA = hexadecimal rotary encoder input (value to be displayed as an ASCII on LCD)
    'portB.1 = serial Tx
    
    'initialize device
    @ device pic16f747, INTRC_OSC_NOCLKOUT, MCLR_OFF
    OSCCON =  $60			'4mhz internal oscillator
    
    'initialize variables
    TxPin var PORTB.1 		'alias pin B.1 to "TxPin"	
    
    'Initialize Display
    	Pause 1000		        'pause 1 sec to let LCD initialize
    	serout TxPin,8, [22]		'turn display on, no cursor
    	serout TxPin,8, [17]		'turn backlight on
    	serout TxPin,8, ["Firing Panel  v1"]
    	pause 5000			
    	serout TxPin,8, [22]	        'Clear LCD
    	serout TxPin,8, [128]	        'move cursor to beginning of first line
    	serout TxPin,8, ["Panel Selected:"]
    
    message:
    	
    	serout TxPin,8, [199]	        'cursor to line 1, position 8
                 IF PORTA = 0 then
                             serout TxPin,8, ["None"]
                 Else
    	serout TxPin,8, [#PORTA]  	'display ASCII of portA on LCD
                 Endif
                 pause 3000
    	goto message			        'loop LCD forever
    
    End

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    You might find something useful here:
    http://www.picbasic.co.uk/forum/showthread.php?t=7529
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Aug 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    OK, Thanks Joe,

    I finally got time to sit down and go through the post thoroughly. It makes sense, so I'll try to implement the code into my project.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rangerdoc View Post
    It worked briefly, but begins to lag. Almost instantly, I notice a considerable delay in the response time between a hex value in and the coresponding ASCII display.
    Maybe your serial LCD is getting bogged down, not enough time between individual characters.
    Try some character pacing. It's in the PBP manual.

  6. #6
    Join Date
    Aug 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    That did the trick Joe. Thanks.
    Here's the final product:

    Code:
    'initialize device
    @ device pic16f737, INTRC_OSC_NOCLKOUT, MCLR_OFF, WDT_OFF
    OSCCON = $60			'internal 4mHz oscillator
    
    'Initialize ports
    TRISA = 0	' RA0 to RA3 inputs for DIP switch, RA4 - RA7 for pushbuttons
    PORTA = 0
    TRISC = $FF 
    
    'initialize variables
    Tx var PORTB.1
    Index var byte
    X var word
    switches var byte  
    
    'Initialize LCD
    	Pause 1000			'pause 1/2 sec to let LCD initialize
    	serout Tx,10, [22]		'turn display on, no cursor
    	serout Tx,10, [17]		'turn backlight on
    	serout Tx,10, [12]		'Clear screen
    	pause 5
    	serout Tx,10, ["Panel Selected:"]
    	pause 1000
    
    loop:
        	Index = PORTc & $0F	 	' Read DIP switch AND mask lsb
      	LOOKUP2 Index,[1,3,3,4,5,6,7,8,9,10,11,12,13,14,15,16],X
    	serout Tx,10, [154,"  ",154]	' clear previous entry
        	serout Tx, 10, [#X]
    	pause 50
    
    LEDS:
    	switches = (PORTC>>4) & $0F	'take msb & save as "switches"
    	if switches > 0 then
    	porta = switches		'enter value "switches" to portA
    	endif
    
    Goto loop:
    
    END

Similar Threads

  1. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  2. Configuration bits in a HEX file gone missing?
    By grzes.r in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd February 2010, 01:10
  3. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  4. Reading from External Hex Address...
    By sbouda in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th October 2008, 06:33
  5. INH8XM HEX file structure
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 30th December 2006, 22:46

Members who have read this thread : 0

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