looking for pointers, tips, etc...


Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Apr 2007
    Posts
    24

    Default looking for pointers, tips, etc...

    Hello all,

    What an adventure this has been! I have completely fallen for this enbedded coding stuff and in paticular PBP. Best money I have spent in a long time. More fun then I have had in a long time...I actully like my job again!

    Here is my little project so far...Just the keyboard scan part. Now I know of Mr._E's Keypad.bas include. But I wanted to write my own for educational purposes...

    Here is my code...I should mention that the the 3x4 keypad is NOT a standard keypad its custom made for my company. So ignore that there is not "#" or "*"

    Also, it is a neccessary for me to get the keypressed one at a time. This is so we can compare the entered code number by number and compare it to the stored number. Rather then using an array or for/next to gather a group of keypresses.

    Code:
    @ DEVICE HS_OSC             
    'SET OSC BIT TO HS 
    
    
    'Defines...
    
    '*lcd defines*
    DEFINE LCD_DREG	PORTD	'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT	4	'Define first pin of portd connected to LCD DB4
    DEFINE LCD_RSREG PORTD	'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 2	'Define Portd pin used for RS connection
    DEFINE LCD_EREG	PORTD	'Define PIC port used for E line of LCD
    DEFINE LCD_EBIT	3	'Define Portd pin used for E connection
    DEFINE LCD_BITS	4	'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 2		'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000	'Define delay time between sending LCD commands
    DEFINE LCD_DATAUS 50	             'Define delay time between data sent.
    
    '*other defines*
    DEFINE OSC 8          'DEFINE EXTERNAL OCS TO 8MHZ
    
    'setup ports...
    INIT:
    'TRISC = %00000000       'SETS PORTC TO ALL OUTPUTS (future use)
    'PORTC = %00000000      'TURNS ALL OF PORT C OFF (future use)
    'OPTION_REG.7=0           'Enable the internal PORTB pullups (this does nt wk)
    TRISB = %00001111       'Set Keypad I/O 1=input 0=output
    PORTB = 0                    'Set columns LOW 
    
    
    'setup variables...
    
    key var byte
    
    lcdout $fe, 1			' Clear LCD
    
    main: 'SCAN keypad for key press
    
    colum0:
    portb = %00010000   'turn on colum0 for row scan
    if portb.1 = 1 then key = 9: goto display
    if portb.2 = 1 then key = 6: goto display
    if portb.3 = 1 then key = 3: goto display
    
    
    
    colum1:
    portb = %00100000   'turn on colum1 for row scan
    if portb.0 = 1 then key = 0: goto display
    if portb.1 = 1 then key = 8: goto display
    if portb.2 = 1 then key = 5: goto display
    if portb.3 = 1 then key = 2: goto display
    
    
    
    colum2:
    portb = %01000000   'turn on colum2 for row scan
    if portb.1 = 1 then key = 7: goto display
    if portb.2 = 1 then key = 4: goto display
    if portb.3 = 1 then key = 1: goto display
    
    goto main
    
    
    DISPLAY:
    ' LCD Command codes
    '------------------
    ' $01       Clear Display
    ' $02       home
    ' $0C       Cursor off
    ' $0E       Underline cursor on
    ' $0F       Blinking cursor on
    ' $10       Move cursor left one character
    ' $14       Move cursor right one character
    ' $C0       Move cursor to begining of next line
    ' all commands must use the format LCDOUT $fe, XX
    
    'Setup LCD...
    
    	lcdout $fe, 1			' Clear LCD 
    	lcdout $fe, 2			' Position cursor at home
        lcdout "you pressed..", dec key
        
    goto main
    Everything works just fine. I am now trying to figure out a good way to debounce. But for now I would love to hear from some of you more advance coders as to how I could make this...Well....more eligante. I looked at the "lookup" command and many examples. I just cant seem to get my head wrapped around how I would impliment it. So if your idea has anything to do with that please include a small tutorial on lookup tables.

    I should also mention that this is just test code. I have broken down my project into several steps. I am making one step work then moving on to the next. Eventually, I will have the knowledge to pull them all together. For example, I figured out the LCD stuff....Moved on to the Scanning of the keypad....Next is reading and writing to the internal EEPROM...etc...


    Oh...I am using the following apps and chips just as a reference....

    PIC16f877a
    EasyPIC4 Dev. board (mikroelektronika)
    PBP 4.27
    PICFlash 4.07 (mikro again)
    pm.exe compiler

    Your thoughts please ladies and gentlemen...

    Best regards,
    Bill12780
    Last edited by bill12780; - 30th July 2007 at 03:21.

Similar Threads

  1. < We need hints and tips area of forum >
    By electroken in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th December 2009, 16:34
  2. Any tips for 4-layer boards?
    By Byte_Butcher in forum Off Topic
    Replies: 30
    Last Post: - 13th December 2009, 16:56
  3. 3 Volts Design Tips and Tricks
    By sougata in forum Documentation
    Replies: 1
    Last Post: - 5th October 2009, 18:51
  4. IDE with emulation!
    By T.Jackson in forum PBP Wish List
    Replies: 22
    Last Post: - 26th February 2008, 20:39

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