Tahmid
Advanced Member level 6
- Joined
- Jun 17, 2008
- Messages
- 4,764
- Helped
- 1,799
- Reputation
- 3,590
- Reaction score
- 1,662
- Trophy points
- 1,413
- Location
- Berkeley, California
- Activity points
- 30,716
Tahmid said:Hi,
I added 48 to convert it to ASCII. This only works for numbers between 0 to 9.
Now I just provided ASCII without complicating matters.
Anyway, here's the new code:
Hope you notice the difference and understand it.Code:program calculator dim LCD_RS as sbit at RB4_bit LCD_EN as sbit at RB5_bit LCD_D4 as sbit at RB0_bit LCD_D5 as sbit at RB1_bit LCD_D6 as sbit at RB2_bit LCD_D7 as sbit at RB3_bit LCD_RS_Direction as sbit at TRISB4_bit LCD_EN_Direction as sbit at TRISB5_bit LCD_D4_Direction as sbit at TRISB0_bit LCD_D5_Direction as sbit at TRISB1_bit LCD_D6_Direction as sbit at TRISB2_bit LCD_D7_Direction as sbit at TRISB3_bit dim keypadPort as byte at PORTD dim kp as byte dim ky as char dim key as byte[20] dim ks as string[20] dim temp as word sub procedure GlobInit TRISA = 0 TRISB = 0 LCD_Init LCD_Cmd(_LCD_CLEAR) LCD_Cmd(_LCD_CURSOR_OFF) Keypad_Init ADCON1 = 7 end sub main: GlobInit for temp = 0 to 3 kp = 0 while (kp = 0) kp = Keypad_Key_Click wend select case kp case 1 ky = "1" case 2 ky = "4" case 3 ky = "7" case 4 ky = "*" case 5 ky = "2" case 6 ky = "5" case 7 ky = "8" case 8 ky = "0" case 9 ky = "3" case 10 ky = "6" case 11 ky = "9" case 12 ky = "#" case 13 ky = "A" case 14 ky = "B" case 15 ky = "C" case 16 ky = "D" end select ks[temp] = ky LCD_Out(1,1,ks) next temp while true wend end.
And also that it came to help you.
Let me know how it works.
Tahmid.
dim key as byte[20]
dim ks as string[20]
char ks[10];
'*******************************************************************
'* Name : Handheld.BAS *
'* Author : Chris Bezuidenhout *
'* Notice : Copyright (c) 2005 Micro Developments *
'* : All Rights Reserved *
'* Date : 2005/04/13 *
'* Version : 2.13 *
'* Notes : Micro Developments is the sole owner of This Software*
'* Device :PIC16F628 *
'*******************************************************************
INCLUDE "Modedefs.Bas"
' ** Setup the Crystal Frequency, in Mhz **
DEFINE CHAR_PACING 3000 'Serout character pacing in us
define SER2_BITS 8
DEFINE OSC 4 ' Set Xtal Frequency
' Set LCD Data port
DEFINE LCD_DREG PORTA
' Set starting Data BIT (0 OR 4) IF 4-BIT bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTA
' Set LCD Register Select BIT
DEFINE LCD_RSBIT 4
' Set LCD Enable port
DEFINE LCD_EREG PORTA
' Set LCD Enable BIT
DEFINE LCD_EBIT 7
' Set LCD bus size (4 OR 8 bits)
DEFINE LCD_BITS 4
' Set number of lines ON LCD
DEFINE LCD_LINES 4 '********************************
DEFINE NO_CLRWDT 1 ' Don’t insert CLRWDTs
' ** Declare the Variables **
K_Flag VAR bit
Key VAR BYTE
LKey VAR BYTE
KeyVal VAR BYTE
Debounce VAR BIT ' Flag to indicate a keypress.
D_Flag VAR BIT ' Debounce flag used by Inkeys.
Counter VAR BYTE
Len1 VAR BYTE
Len2 VAR BYTE
Len3 VAR BYTE
Len4 VAR BYTE
X VAR BYTE
Y VAR BYTE
L VAR BYTE
D0 VAR BYTE
D1 VAR BYTE
D2 VAR BYTE
D3 VAR BYTE
B0 VAR BYTE '/
LFL VAR BYTE 'LINE FLAG
FL0 VAR LFL.BIT0 'LINE FLAG BITS
FL1 VAR LFL.BIT1
FL2 VAR LFL.BIT2
FL3 VAR LFL.BIT3
L1 VAR BYTE[20] BANK1
L2 VAR BYTE[20] BANK1
L3 VAR BYTE[20] BANK1
L4 VAR BYTE[20] BANK1
' FlagS var BYTE[10]
HID VAR BYTE
Q1 VAR BYTE
Q2 VAR BYTE
ID VAR BYTE
Sum VAR WORD
D_Flag=0 ' Reset the debounce flag, prior to calling the subroutine
OPTION_REG.7 = 0
CMCON = 7
TRISA=%00100000
TRISB = %00001111
low PORTA.6
READ 0,Q1
READ 1,Q2
READ 2,ID
READ $78,HID
Pause 500
GOSUB CHECK
' ADCON1 = 7
' ANSEL =0
Start:
' LCDOut $fe, 1,"Micro Developments"
' LCDOut $fe,$c0,"Cell.+27-72-7950107"
' high porta.6
' pause 5000
lcdout $fe,$0e
x=0
FOR Y=0 TO 19
L1[Y]=" "
L2[Y]=" "
L3[Y]=" "
L4[Y]=" "
NEXT Y
Main: 'Main loop to select key[Q1,Q2], 200,GK,
L=1
Y=0
LEN1=0
LEN2=0
' LEN3=0
' LEN4=0
FOR Y=0 TO 19
L1[Y]=" "
L2[Y]=" "
' L3[Y]=" "
' L4[Y]=" "
NEXT Y
LCDOut $fe,1
Luister:
SERIN2 PORTA.5,16780,50,SEND,[WAIT(Q1,Q2),ID,D0,STR L1\20,D1,STR L2\20,D2]',STR L3\20,D3,STR L4\20
gosub print
' PAUSE 500
' SerOut2 PORTA.6,16780,1,[Q1,q2,ID,"L","O"]
' NEXT Y
' for y = 0 to 19 'STOOR ONTVANGDE DATA IN MEMMORY
' write y+8,L1[Y]
' write y+28,L2[Y]
' write y+48,L3[Y]
' write y+68,L1[Y]
' NEXT Y
WHILE KEY<>"#"
GOSUB KEYSCAN
WEND
LCDOUT $FE,1
gosub rmem
GOTO Luister
Resend: PAUSE 200'FOR Y=1 TO 3
SerOut2 PORTA.6,16780,1,[Q1,q2,ID,"L","R"] 'REQ. RESEND ON BAD PARITY
'NEXT Y
'LCDOUT $FE,$D4,"BAD PARITY"
GOTO Luister
INCLUDE "Key16627.bas" '4x4 kEYPAD
Print: lcdout $FE,1
LCDOUT $FE,$80,STR L1\20
lcdout $fe,$C0,STR L2\20
' lcdout $fe,$94,STR L3\20
' lcdout $fe,$D4,STR L4\20
return
Send:
GoSub Keyscan
IF K_FLAG = 0 THEN Luister
K_FLAG=0
LCDOUT $FE,$D4,#KEY',"L=",#L,"X=",#X,#LEN1
SELECT CASE KEY
CASE "#"
goto Transmit
CASE "*"
GOTO Backsp
END SELECT
SELECT CASE L
CASE 1
if x=0 then
lcdout $fe,1
gosub cmem
endif
L1[x]=key
write X+8,L1[X]
LEN1=LEN1+1
lcdout $FE,$80,STR L1\LEN1
CASE 2
if x=0 then lcdout $fe,$c0
L2[x]=key
write X+28,L2[X]
LEN2=LEN2+1
lcdout $FE,$C0,STR L2\LEN2
' CASE 3
' if x=0 then lcdout $fe,$94
' L3[x]=key
' write X+48,L3[X]
' LEN3=LEN3+1
' lcdout $FE,$94,STR L3\LEN3
' CASE 4
' if x=0 then lcdout $fe,$d4
' L4[x]=key
' write X+68,L1[X]
' LEN4=LEN4+1
' lcdout $FE,$D4,STR L4\LEN4
CASE else
'GOTO TMODE
END SELECT
x=x+1
if x=20 then
x=0
l=l+1
endif
IF X=0 AND L>2 THEN
X=20
L=2
ENDIF
' WEND
GOTO Luister
Backsp: lcdout $fe,$10
x=x-1
SELECT CASE L
CASE 1
LEN1=LEN1-1
L1[LEN1]=" "
CASE 2
LEN2=LEN2-1
L2[LEN2]=" "
' CASE 3
' LEN3=LEN3-1
' L3[LEN3]=" "
' CASE 4
' LEN4=LEN4-1
' L4[LEN4]=" "
END SELECT
key=0
gosub print
GOTO Luister
Transmit: 'Send caracters on display
IF LEN1<20 THEN 'VUL DIE LYNE MET SPASIES VOOR STUUR
FOR Y=LEN1 TO 19
L1[Y]=" "
NEXT Y
ENDIF
IF LEN2<20 THEN
FOR Y=LEN2 TO 19
L2[Y]=" "
NEXT Y
ENDIF
' IF LEN3<20 THEN
' FOR Y=LEN3 TO 19
' L3[Y]=" "
' NEXT Y
' ENDIF
' IF LEN4<20 THEN
' FOR Y=LEN4 TO 19
' L4[Y]=" "
' NEXT Y
' ENDIF
'
PAUSE 100
RSLoop: LCDOUT $fe,$94,"TRANSMITING"
for y = 1 to 10
SerOut2 PORTA.6,16780,1,[Q1,Q2,ID,1,STR L1\20,2,STR L2\20] ',3,STR L3\20,4,STR L4\20
PAUSE 100
NEXT Y
'SERIN2 PORTA.5,16780,[WAIT(Q1,Q2),ID,L,B0] 'RECIEVE RESEND B0="R" /AKN B0="O"
' PAUSE 500
' NEXT Y
' IF B0="R" THEN
' LCDOUT $FE,$D4,B0
' GOTO RSLOOP
' ENDIF
'clear line data
X=0
l=1
'LCDOut $fe, 1 'clear display
GoTo MAIN
RMEM:
FOR Y=8 TO 28
READ Y,L1[Y-7]
NEXT Y
FOR Y=29 TO 49
READ Y,L2[Y-7]
NEXT Y
' FOR Y=50 TO 70
' READ Y,L3[Y-7]
' NEXT Y
' FOR Y=71 TO 91
' READ Y,L4[Y-7]
' NEXT Y
Gosub print
ESub: Return
Cmem: for y=8 to 88
write y," "
next y
return
Return
CHECK:HID=HID+1
FOR X = 0 TO 6
READ X+$79,D0
LOOKUP X,["C","A","B","D","4","1","7"],D1
' LCDOUT D0,D1
IF D1<>D0 THEN EINDE
NEXT X
RETURN
EINDE:IF HID<32 THEN
WRITE $78,HID
RETURN
ENDIF
LCDOUT $fe,$94,"ENTER YOUR RELEASE CODE"
FOR X=$79 TO $7F
KG: GOSUB KEYSCAN
IF K_FLAG=0 THEN GOTO KG
K_FLAG=0
WRITE X,KEY
LCDOUT KEY
NEXT X
' PAUSE 2000
GOTO CHECK
End
DATA @0,"C","B","B"
'DATA @$78,30
Keyscan:
'FlagS[0]="C"
Debounce=1 ' Setup the initial value for Debounce
Key=0 ' Clear the variable KEY, prior to scanning
' TRISA=%00100000
' TRISB = %00001111
' Option_Reg.7=0 ' Enable Internal PortB Pullup Resistors
PORTB.4=0
PORTB.5=1
PORTB.6=1
PORTB.7=1 ' Pull the fourth Row line LOW
GoSub Scancol ' Scan the columns
IF K_Flag=1 Then GoTo Map ' If a key is pressed then map it
PORTB.4=1
PORTB.5=0
PORTB.6=1
PORTB.7=1 ' Pull the fourth Row line LOW
GoSub Scancol ' Scan the columns
IF K_Flag=1 Then GoTo Map ' If a key is pressed then map it
PORTB.4=1
PORTB.5=1
PORTB.6=0
PORTB.7=1 ' Pull the fourth Row line LOW
GoSub Scancol ' Scan the columns
IF K_Flag=1 Then GoTo Map ' If a key is pressed then map it
PORTB.4=1
PORTB.5=1
PORTB.6=1
PORTB.7=0 ' Pull the fourth Row line LOW
GoSub Scancol ' Scan the columns
IF K_Flag=1 Then GoTo Map ' If a key is pressed then map it
D_Flag=0 ' No key pressed, so Reset debounce flag
Debounce=0 ' No key pressed, so Reset key Debounce flag
GoTo Exit ' Exit from the subroutine
' Do the following code if a key has been pressed
Map: IF D_Flag=1 Then Exit ' Already responded to this press, so exit
D_Flag=1 ' Set Debounce flag
Debounce=0 ' Reset key Debounce flag
LookUp Key,[68,67,66,65,35,9,6,3,0,8,5,2,43,7,4,1,128],Keyval ' Map of the keypad legends for numeric output
' **To convert the output to an ascii value comment the line above and uncomment the line below
LookUp Key,["D","C","B","A","#","9","6","3","0","8","5","2","*","7","4","1",32],Key ' Map of the keypad legends for ascii output
' This subroutine scans the columns
' The bit, K_Flag returns a 1 if a key is pressed, and 0 if no key pressed
' Also, if no key is pressed the variable KEY will return with the value of 16
Exit: Return
Scancol:
K_Flag=1 ' Set K_Flag initially to 1
IF PORTB.0=0 Then DEB_release 'S_Exit ' Return if a key on the first column is pressed
Key=Key+1 ' Else increment KEY, and try another row
IF PORTB.1=0 Then DEB_release 'S_Exit ' Return if a key on the second column is pressed
Key=Key+1 ' Else increment KEY, and try another row
IF PORTB.2=0 Then DEB_release 'S_Exit ' Return if a key on the third column is pressed
Key=Key+1 ' Else increment KEY, and try another row
IF PORTB.3=0 Then DEB_release 'S_Exit ' Return if a key on the fourth column is pressed
Key=Key+1 ' Else increment KEY, KEY now equals 16
K_Flag=0 ' Set the K_Flag to indicate no key pressed
S_Exit: Return ' And exit the subroutine
DEB_release:
'Check to see if key is released
counter=256
DEB_release_l1:
IF PORTB.0=0 Then DEB_release
IF PORTB.1=0 Then DEB_release
IF PORTB.2=0 Then DEB_release
IF PORTB.3=0 Then DEB_release
counter=counter-1
IF counter=0 Then S_Exit
GoTo DEB_release_l1
Hi ,
How many users could be added in this project , if i need more than 100 users , is it possible in this project ?
Kindly help
---------- Post added at 15:58 ---------- Previous post was at 15:37 ----------
Is it possible can u tell me how to program this in Mplab ide ? it would be very helpful for me
Hi,
Code:
Code:program calculator dim LCD_RS as sbit at RB4_bit LCD_EN as sbit at RB5_bit LCD_D4 as sbit at RB0_bit LCD_D5 as sbit at RB1_bit LCD_D6 as sbit at RB2_bit LCD_D7 as sbit at RB3_bit LCD_RS_Direction as sbit at TRISB4_bit LCD_EN_Direction as sbit at TRISB5_bit LCD_D4_Direction as sbit at TRISB0_bit LCD_D5_Direction as sbit at TRISB1_bit LCD_D6_Direction as sbit at TRISB2_bit LCD_D7_Direction as sbit at TRISB3_bit dim keypadPort as byte at PORTD dim kp as byte dim ky as byte dim key as byte[20] dim ks as string[20] dim temp as word sub procedure GlobInit TRISA = 0 TRISB = 0 LCD_Init LCD_Cmd(_LCD_CLEAR) LCD_Cmd(_LCD_CURSOR_OFF) Keypad_Init ADCON1 = 7 end sub main: GlobInit while true for temp = 0 to 3 kp = 0 while (kp = 0) kp = Keypad_Key_Click wend select case kp case 1 ky = 7 case 2 ky = 4 case 3 ky = 1 case 4 ky = 10 case 5 ky = 8 case 6 ky = 5 case 7 ky = 2 case 8 ky = 0 case 9 ky = 9 case 10 ky = 6 case 11 ky = 3 case 12 ky = 11 case 13 ky = 12 case 14 ky = 13 case 15 ky = 14 case 16 ky = 15 end select if (ky < 11) then key[temp] = ky ks[temp] = ky + 48 end if if (ky > 10) then break end if LCD_Out(1,1,ks) next temp kp = 0 while (kp = 0) kp = Keypad_Key_Click wend wend end.
Added after 1 minutes:
Hope it helps.
Let me know how it works out for you.
Tahmid.
Added after 28 seconds:
P.S. The compiler is mikroBASIC PRO for PIC v3.20.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?