Sunteți pe pagina 1din 3

Hardware Connections: I connected the Keypad to the Port B (0-7) not sure about which pins were rows

and which were colums but I changed connections to take care of both cases. Now the LCD reaches "TESTING Keypad" and then nothing happens when I press a Key upon the dispay message " Press Key Now" I am wondering if theres anything wrong in the Keypad routine.. Any help would be greatly appreciated.. since the next step of my project depends greatly on getting this working and understand whats happening..in this code Thank you -----------------------------------The .BAS Code

Define LOADER_USED 1 Define OSC 4 'Define LCD registers and bits 'Define LCD registers and bits DEFINE LCD_DREG PORTC 'Define PIC port used for LCD Data lines DEFINE LCD_DBIT 0 'LCD Data Starting Bit = Bit 0 or 4 DEFINE LCD_EREG PORTE 'Define PIC port used for E line of LCD DEFINE LCD_EBIT 2 'Define Port pin used for E connection 'DEFINE LCD_RWREG PORTD 'Define PIC port used for RW line of LCD 'DEFINE LCD_RWBIT 0 'Define Port pin used for RW connection DEFINE LCD_RSREG PORTD 'Define PIC port used for RS line of LCD DEFINE LCD_RSBIT 1 'Define Port pin used for RS connection DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD DEFINE LCD_LINES 4 'Define using a 4 line LCD DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands DEFINE LCD_DATAUS 50 'Define delay time between data sent. DEFINE DEFINE DEFINE DEFINE DEFINE DEFINE DEFINE DEFINE KEYPAD_ROW 4 ' 4 ROW keypad KEYPAD_ROW_PORT PORTB ' ROW port = PORTB KEYPAD_ROW_BIT 4 ' ROW0 = PORTB.4 KEYPAD_COL 4 ' 4 COL keypad KEYPAD_COL_PORT PORTB ' COL port = PORTB KEYPAD_COL_BIT 0 ' COL0 = PORTB.0 KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature

'*********Port Assignments*************************************** ************** ******************************** LED var PortB.2 ' Variable so we don't have to remember what port and bit i t is on ' -----[ Initialize Hardware ]-----------------------------------------------TRISA = %00001111 ' Set PORTA to all input (Thermistor is on A.1) ADCON1 = %10000100 ' Set PORTA analog and right justify result

TRISB = %00000000 ' PortB are all outputs PORTB = %00000000 ' TRISC = %10010000 PORTC = %00000000 TRISD = %00000000 PortD = %00000000 TrisE.0 TrisE.1 PortE.1 TrisE.2 PortE.2 = = = = = 1 0 0 0 0 ' ' ' LCD '

'Program Definitions col Var Byte ' Keypad column row Var Byte ' Keypad row key Var Byte ' Key value OPTION_REG.7 = 0 ' Enable PORTB pullups ADCON1 = 7 ' Make PORTA and PORTE digital 'Low PORTE.2 ' LCD R/W low (write) Pause 1000 LCDOut $FE,1,"TESTING",$FE,$C0,"KEYPAD DISPLAY" Pause 2000 LCDOut $FE,1,"CLICK ANY KEY",$FE,$C0,"NOW..." loop: Gosub getkey ' Get a key from the keypad Lcdout $fe, 1, #key ' Display ASCII key number Goto loop ' Do it forever ' SubRoutines placed after the END statement ' Subroutine to get a key from keypad getkey: Pause 50 ' Debounce getkeyu: ' Wait for all keys up PORTB = 0 ' All output pins low TRISB = $f0 ' Bottom 4 pins out, top 4 pins in If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop Pause 50 ' Debounce getkeyp: ' Wait for keypress 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 Goto getkeyp ' No keys down, go look again gotkey: ' Change row and column to key number 1 - 16 key = (col * 4) + (ncd (row ^ $f))

Return ' Subroutine over End ' Subroutine over

S-ar putea să vă placă și