• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help with PICBasic

Status
Not open for further replies.

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.:confused:

2- for the second parameter only the second digite is displied, but the first and the second digites aren't displied.:confused:

a tried to solve the problem many time but i couldn't. please help.:confused::confused:

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:

Pommie

Well-Known Member
Most Helpful Member
I have never seen an instruction "CASE is = 2". This would normally be written "CASE 2". Try removing all the "is =" bits.

Mike.
 

manba

New Member
Hi, Pommie..

CASE IS (variable) is on of the PICBasic commands. I have read it from my PICBasic referance book. It's just like CASE = (variable)...

I tride CASE without Is, but the result is the same..

hey, guys is it a puzzel.????? :confused::confused:
 
Last edited:

3v0

Coop Build Coordinator
Forum Supporter
Hi, Pommie..

CASE IS (variable) is on of the PICBasic commands. I have read it from my PICBasic referance book. It's just like CASE = (variable)...

I tride CASE without Is, but the result is the same..

hey, guys is it a puzzel.????? :confused::confused:
As is your code.

I see a GOTO MAIN but no MAIN, I do see a MAIN_KEY. It is difficult to follow your main code loop. Try coding the program without using GOTO.
 

mramos1

Active Member
As stated, I see no MAIN: in the program and can not imagine this will compile.

You also "CALL" inter_temp but end that routine with a GOTO LOOP that just loops? You need to put a RETURN at the end of that routine as well. Is this for debugging purpose?

The PICBasic I have does not have a CASE, so this must be PICBasic pro or something.
 

manba

New Member
Hi, there..

I have updated the code, but i still have the same problem.

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 ****
MAIN:
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 3
    KEY3 = NUM
    NUM3 = KEY3
    CASE = 2
    KEY2 = NUM
    NUM2 = KEY2
    CASE = 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 3
    KEY3 = NUM
    NUM6 = KEY3
    CASE 2
    KEY2 = NUM
    NUM5 = KEY2
    CASE 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
actually, i'm wondering why this error is occurred. :confused:

Or, can anyone give me another way to get three numbers from the keypad and disply them in the LCD.
 
Last edited:

mramos1

Active Member
Are you having problems with LCDOUT not showing the digits on the LCD display? If you are and you assume PICBasic routines are golden and hardware is too, did you check to see if your variables all have values in them.

The case statements look better now.
 
Status
Not open for further replies.

EE World Online Articles

Loading

 
Top