manba
New Member
Hi, all there..
i have a problem with the PICBasic programing (i'm a beginner in using the PICBasic). I have aproject using pic16f877a and lcd. PIC16f877a take the number from the keypad and send to the lcd but not directly. only three numbers for ach parameter "T1= 000 max" and "T2= 000 min". (my be the idea of the project isn't clear see the code)
the problem:
1- for the first parameter only two numbers displied the first and the third digites, second digite isn't displied.
2- for the second parameter only the second digite is displied, but the first and the second digites aren't displied.
a tried to solve the problem many time but i couldn't. please help.

i have a problem with the PICBasic programing (i'm a beginner in using the PICBasic). I have aproject using pic16f877a and lcd. PIC16f877a take the number from the keypad and send to the lcd but not directly. only three numbers for ach parameter "T1= 000 max" and "T2= 000 min". (my be the idea of the project isn't clear see the code)
the problem:
1- for the first parameter only two numbers displied the first and the third digites, second digite isn't displied.
2- for the second parameter only the second digite is displied, but the first and the second digites aren't displied.
a tried to solve the problem many time but i couldn't. please help.
Code:
DEFINE OSC 20
'**** LCD ****
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 8
DEFINE LCD_BITS 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 40
'**** VAR_LCD****
Key1 VAR BYTE
Key2 VAR BYTE
Key3 VAR BYTE
T1MAX VAR WORD
T1MIN VAR WORD
T2MAX VAR WORD
T2MIN VAR WORD
T1 VAR WORD
T2 VAR WORD
'**** VAR_KEY ****
OLD_RESULT VAR BYTE
KEY_RESULT VAR BYTE
KEYPRESS var byte
FLAG VAR BIT
FLAG2 VAR BIT
NUM1 VAR BYTE
NUM2 VAR BYTE
NUM3 VAR BYTE
NUM4 VAR BYTE
NUM5 VAR BYTE
NUM6 VAR BYTE
NUM VAR BYTE
I VAR BYTE
J VAR BYTE
'**** Initialize program ****
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
TRISD = %11110000
'**** MAIN program ****
CALL INTER_TEMP
GOTO MAIN
'**** Keypad Subprogram ****
MAIN_KEY:
CALL SCANKEY
IF KEY_RESULT = 12 THEN MAIN_KEY 'non is pressed
'**** Scan Key Subprogram ****
SCANKEY:
PORTD = %0100 ' Chose colum 1
CALL ROW
IF FLAG = 1 THEN FIRST_COLUM
PORTD = %0010 ' Chose colum 2
CALL ROW
IF FLAG = 1 THEN SECOND_COLUM
PORTD = %0001 ' Chose colum 3
CALL ROW
IF FLAG = 1 THEN THIRD_COLUM
KEY_RESULT = 12
RETURN
FIRST_COLUM:
LOOKUP KEYPRESS,[1,4,7,10],KEY_RESULT
OLD_RESULT = KEY_RESULT
NUM = KEY_RESULT
RETURN
SECOND_COLUM:
LOOKUP KEYPRESS,[2,5,8,0],KEY_RESULT
OLD_RESULT = KEY_RESULT
NUM = KEY_RESULT
RETURN
THIRD_COLUM:
LOOKUP KEYPRESS,[3,6,9,11],KEY_RESULT
OLD_RESULT = KEY_RESULT
NUM = KEY_RESULT
RETURN
ROW:
KEYPRESS = 0
FLAG = 1
IF PORTD.4 = 1 THEN EXIT_ROW
KEYPRESS = KEYPRESS + 1
IF PORTD.5 = 1 THEN EXIT_ROW
KEYPRESS = KEYPRESS + 1
IF PORTD.6 = 1 THEN EXIT_ROW
KEYPRESS = KEYPRESS + 1
IF PORTD.7 = 1 THEN EXIT_ROW
KEYPRESS = KEYPRESS + 1
FLAG = 0
EXIT_ROW:
RETURN
'** Inter temperature value Subprogram ****
INTER_TEMP:
CALL PARA_1
CALL PARA_2
GOTO LOOP
'** First parameter Subprogram ****
PARA_1:
FOR I = 0 TO 4
CALL T1_MAX
CALL MAIN_KEY
KEY_RESULT = 12
I = I + 1
CALL DIGITS
PAUSE 1000
NEXT I
RETURN
DIGITS:
SELECT CASE I
CASE is = 3
KEY3 = NUM
NUM3 = KEY3
CASE is = 2
KEY2 = NUM
NUM2 = KEY2
CASE is = 1
KEY1 = NUM
NUM1 = KEY1
CASE ELSE
RETURN
END SELECT
RETURN
'** Second parameter Subprogram ****
PARA_2:
FOR J = 0 TO 4
CALL T1_MIN
CALL MAIN_KEY
KEY_RESULT = 12
CALL DIGITS_2
J = J + 1
PAUSE 1000
NEXT J
RETURN
DIGITS_2:
SELECT CASE J
CASE is = 3
KEY3 = NUM
NUM6 = KEY3
CASE is = 2
KEY2 = NUM
NUM5 = KEY2
CASE is = 1
KEY1 = NUM
NUM4 = KEY1
CASE else
RETURN
END SELECT
RETURN
'**** T1_MAX Subprogram ****
T1_MAX:
LCDOUT $FE,1
LCDOUT $FE,$83
LCDOUT "T1=",DEC NUM1,DEC NUM2,DEC NUM3," max"
RETURN
'**** T1_MIN Subprogram ****
T1_MIN:
LCDOUT $FE,$C3
LCDOUT "T1=",DEC NUM4,DEC NUM5,DEC NUM6," min"
RETURN
'**** LOOP Subprogram ****
LOOP:
GOTO LOOP
'****************
END
Attachments
Last edited: