4bit hex decoder w/LCD


Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Aug 2007
    Posts
    11

    Default 4bit hex decoder w/LCD

    I'm trying to write code for some hardware I'm going to build. With two purposes:
    1) I have a 4-bit hex rotary encoder that will be inputs to the lower 4 bits of portA. I want the LCD to display an ASCII of the HEX encoder value.
    2) I also have 4 momentary switches. They will be the lower 4 bits of portB. I have 4 LEDs on portC. When I press a momentary switch on portB, I want the cooresponding LED on portC to light & latch. When any other button is pressed, I want the first LED to go low and the new LED to go high and latch. Basically, I want portC to output & latch any value of portB other than 0.
    All MCU inputs are optically isolated from the hardware they are operating.

    I'm really new at this & this is my first code other than simple LED out type programs. Here is what I have:

    Code:
    'program for integrated firing panel
    'portA = hexadecimal rotary encoder input (value to be displayed as an ASCII on LCD)
    'portB = 4bit bank select momentary switches input
    'portC = 4bit output to bank LEDs
    'message = LCD display of portA (hex switch) value
    
    'initialize device
    @ device pic16f737, INTRC_OSC_NOCLKOUT, MCLR_OFF
    OSCCON =  $60			'4mhz internal oscillator
    
    'initialize ports
    TRISB = $10			'make all portB pins outputs except B.4
    TRISC = 0			'Make portC outputs
    PORTC = 0			'Make sure portC pins start low
    
    'initialize variables
    TxPin var PORTB.4 		'alias pin B.4 to "TxPin"
    rotary_in var word		'create variable "rotary_in"
    banks var word			'create variable "banks"
    rotary_in = PORTA & $0f	        'isolate lower 4 bits of portA & write to "rotary_in"
    banks = PORTB & $0f		'isolate lower 4 bits of portB & write to "banks"
    LEDs var PORTC			'alias PORTC as "LEDs"		
    
    'Initialize Display
    	Pause 1000		        'pause 1 sec to let LCD initialize
    	serout TxPin,4, [22]		'turn display on, no cursor
    	serout TxPin,4, [17]		'turn backlight on
    	serout TxPin,4, ["Firing Panel  v1"]
    	serout TxPin,4, [148]	        'move to line 2
    	serout TxPin,4, [2]		'display custom character 3
    	pause 5000			
    	serout TxPin,4, [22]		'clear the screen
    	pause 2000
    
    message:
    	serout TxPin,4, [22]	        'Clear LCD
    	serout TxPin,4, [128]	        'move cursor to beginning of first line
    	serout TxPin,4, ["Panel Selected:"]
    	serout TxPin,4, [199]	        'cursor to middle of second line
    	serout TxPin,4, [#rotary_in]	'display ASCII of portA lower 4 bits on LCD
    	END
    
    leds:
    	If banks > 0 Then		'for all port B.0 thru B.3 values, except 0,
    		banks = PORTC 	        'write value of portB to portC
    	Endif
    
    goto message			        'loop LCD forever
    
    End
    The whole thing compiles fine except for Error Line 44: Syntax Error. Is this line 44 of the PBP or the ASM code? Does that include blank lines and comments as a line? In other words: which is line 44?
    Any help would be appreciated. I know most of you could find much better ways of writing this, but I need to keep it simple, even if it isn't the most efficient way of doing this. That way I can continue to work with it and learn from it in the future. The inputs and outputs will be so slow that speed isn't an issue.
    One thing I don't like is that in the "leds:" routine, I'm writing a binary value to the whole portC when portC.4 is TxPin. Not sure if this will create problems.
    Attached is the assembly file created by PBP.

    Thanks
    Attached Files Attached Files
    Last edited by rangerdoc; - 10th May 2008 at 03:07.

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