Försöker göra en ny grej nu. Ska få gubben som jag höll på med innan att flytta sig på LCDn med hjälp av knappar. Men det var lite klurigare än jag trodde. Just nu har jag iallafall lyckats definera knapparna. Men jag får inte gubbjäveln att röra sig... Undrar om någon kanske fattar bättre.
Såhär långt har jag kommit:
Kod: Markera allt
' PicBasic Pro program to display key number on LCD
' Define LOADER_USED to allow use of the boot loader.
' This will not affect normal program operation.
DEFINE LOADER_USED 1
' Define LCD connections
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
' Define program variables
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 100 ' Wait for LCD to start
LCDOut $fe, 1
LCDOut $FE, 64, $8e, $8e, $84, $8e, $95, $84, $8a, $91
loop: GoSub getkey ' Get a key from the keypad
GoTo loop ' Do it forever
' 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 + row
IF key = 15 Then
LCDOut $FE, $0
LCDOut $FE, $14
Pause 500
EndIF
key = col * 4 + row
IF key = 26 Then
LCDOut $FE, $0
LCDOut $FE, $10
Pause 500
EndIF
Return ' Subroutine over
End
Mvh
/Mathias