Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] need help, designing simple calculator using pic18f452

Status
Not open for further replies.

piyush999

Newbie level 3
Newbie level 3
Joined
Sep 23, 2014
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
27
i am doing a project to design a simple calculator using pic18f452,

pic18f452, in MPLAB IDE, using pic assembly language, and simulate it in proteus(using 4x4 keyboard,16x2 lcd)

right now i am trying to study the pic assembly language and tried to interface the lcd but it is not working. i need to finish this urgently pls, help.
 

Are you using the schematic from the proteus ISIS sample PIC18 folders?

Post your .asm file so we can look at it in detail...

Allen
 

this is what i have done, the ascii value of the character in the keyboard interfacing is saved in the portD, so i tried to give Portd directly as in input in the lcd interfacing, so that the ascii value of the character in the portD would go to the LCD_DATA register,

i have included the arithmatic operations yet, i was going to include it as functions later, i though to try this out first but even this is not working.

i have made the schematic according to this code,

Code:
           list p=18f452	 	
#include P18F452.INC

	CONFIG WDT=OFF; disable watchdog timer
	CONFIG DEBUG = OFF; Enable Debug Mode
	CONFIG LVP = OFF; Low-Voltage programming disabled
	CONFIG OSC = HS;

D15mH  EQU D'100' ;
D15mL  EQU D'225';
COL    EQU 0X08;
DR15mH EQU 0X09;
DR15mL EQU 0X0A

;-----------------------------

		    ORG 0X000000
RESET_ISR   GOTO MAIN ;
			ORG 0X000008
HI_ISR 		BTFSC INTCON,RBIF ;
			BRA RBIF_ISR;
			RETFIE;
			
;---------------------------PROGRAM FOR INITIALIZATION

MAIN	CLRF TRISD ;
		BCF INTCON2,RBPU;
		MOVLW 0X0F;
		MOVWF TRISB;
		MOVWF PORTB;
		
KEYOPEN	CPFSEQ PORTB;
		GOTO KEYOPEN;
		MOVLW UPPER(KCODE0)
		MOVWF TBLPTRU;
		MOVLW high(KCODE0)		
		MOVWF TBLPTRH;
		BSF INTCON,RBIE;
		BSF INTCON,GIE;
LOOP	GOTO LOOP;

;-------------------------KEY IDENTIFICATION ISR

RBIF_ISR    CALL DELAY
			MOVFF PORTB,COL;
			MOVLW 0XFE
			MOVWF PORTB;
			CPFSEQ PORTB ;
			BRA ROW0;
			MOVLW 0XFC
			MOVWF PORTB;
			CPFSEQ PORTB ;
			BRA ROW1;
			MOVLW 0XFB
			MOVWF PORTB;
			CPFSEQ PORTB ;
			BRA ROW2;
			MOVLW 0XF7
			MOVWF PORTB;
			CPFSEQ PORTB ;
			BRA ROW3;
			GOTO BAD_RBIF ;
ROW0		MOVLW Low(KCODE0);
			BRA FIND;
ROW1		MOVLW Low(KCODE1);
			BRA FIND;
ROW2		MOVLW Low(KCODE2);
			BRA FIND;
ROW3		MOVLW Low(KCODE3);
													
FIND		MOVWF TBLPTRL;
			MOVLW 0XF0
			XORWF COL;
			SWAPF COL,F;
AGAIN		RRCF COL;
			BC MATCH;
			INCF TBLPTRL;
			BRA AGAIN;
MATCH		TBLRD*+
			MOVFF TABLAT,PORTD;
WAIT		MOVLW 0XF0 
			MOVWF PORTB;
			CPFSEQ PORTB;
			BRA WAIT;
			BCF INTCON,RBIF;
			RETFIE;
BAD_RBIF	MOVLW 0X00;
			GOTO WAIT;
;---------------------------DELAY

DELAY:      MOVLW D15mH;
			MOVWF DR15mH;
D2:			MOVLW D15mL;
			MOVWF DR15mL;
D1:			DECF DR15mL,F;
			BNZ D1
			DECF DR15mH,F;
			BNZ D2			
			RETURN
;----------------------------KEY SCANCODE LOOK-UP TABLE

			ORG	300H
KCODE0: 	DB	'7','8','9','/';
KCODE1: 	DB	'4','5','6','*';
KCODE2: 	DB	'1','2','3','-';
KCODE3: 	DB	'C','0','=','+';
					
;------------LCD INTERFACING



LCD_DATA	EQU PORTC
LCD_CTRL	EQU PORTA
RS			EQU	RA0
RW			EQU RA1	
EN			EQU RA2

			CLRF TRISC
			CLRF TRISA
			BCF LCD_CTRL,EN;
			CALL LDELAY;
			MOVLW 0X38;
			CALL COMNWRT;
			CALL LDELAY;
			MOVLW 0X0E;
			CALL COMNWRT;
			CALL RDELAY;			
			MOVLW 0X01;
			CALL COMNWRT;
			CALL RDELAY;
			MOVLW 0X06;
			CALL COMNWRT;
			CALL RDELAY;
			MOVLW PORTD;
			CALL DATAWRT;
RAGAIN		BTG LCD_CTRL,0;
			BRA RAGAIN;

				
COMNWRT		MOVWF LCD_DATA ;
			BCF LCD_CTRL,RS;
			BCF LCD_CTRL,RW;
			BSF LCD_CTRL,EN;
			CALL SDELAY;
			BCF LCD_CTRL,EN;
			RETURN

DATAWRT     MOVWF LCD_DATA ;
			BSF LCD_CTRL,RS;
			BCF LCD_CTRL,RW;
			BSF LCD_CTRL,EN;
			CALL SDELAY;
			BCF LCD_CTRL,EN;
			RETURN
	
		
R2 		EQU 0X2
R3 		EQU 0X3
R4		EQU 0X4

LDELAY:		MOVLW D'5'
			MOVWF R4
BACK1		MOVLW D'100'
			MOVWF R3
AGAIN1		MOVLW D'250'
			MOVWF R2
HERE1		NOP
			NOP
			DECF R2,F
			BNZ HERE1
			DECF R3,F
			BNZ AGAIN1
			DECF R4,F
			BNZ BACK1
			RETURN					
			

RDELAY:		MOVLW D'3'
			MOVWF R4
BACK2		MOVLW D'100'
			MOVWF R3
AGAIN2		MOVLW D'250'
			MOVWF R2
HERE2		NOP
			NOP
			DECF R2,F
			BNZ HERE2
			DECF R3,F
			BNZ AGAIN2
			DECF R4,F
			BNZ BACK2
			RETURN					
			


SDELAY:		MOVLW D'2'
			MOVWF R4
BACK3		MOVLW D'100'
			MOVWF R3
AGAIN3		MOVLW D'250'
			MOVWF R2
HERE3		NOP
			NOP
			DECF R2,F
			BNZ HERE3
			DECF R3,F
			BNZ AGAIN3
			DECF R4,F
			BNZ BACK3
			RETURN					
			
				
				END



CAL.jpg

- - - Updated - - -

i have included the arithmetic operations yet, i was going to include it as functions later, i though to try this out first but even this is not working.
*not included the arithmetic operations yet
 
Last edited:

Code:
           list p=18f452	 	
#include P18F452.INC

	CONFIG WDT=OFF; disable watchdog timer
	CONFIG DEBUG = OFF; Enable Debug Mode
	CONFIG LVP = OFF; Low-Voltage programming disabled
	CONFIG OSC = HS;

D15mH  EQU D'100' ;
D15mL  EQU D'225';
COL    EQU 0X08;
DR15mH EQU 0X09;
DR15mL EQU 0X0A

;-----------------------------

		    ORG 0X000000
RESET_ISR   GOTO MAIN ;
			ORG 0X000008
HI_ISR 		BTFSC INTCON,RBIF ;
			BRA RBIF_ISR;
			RETFIE;
			
;---------------------------PROGRAM FOR INITIALIZATION

MAIN	CLRF TRISD ;
		BCF INTCON2,RBPU;
		MOVLW 0X0F;
		MOVWF TRISB;
		MOVWF PORTB;
		
KEYOPEN	CPFSEQ PORTB;
		GOTO KEYOPEN;
		MOVLW UPPER(KCODE0)
		MOVWF TBLPTRU;
		MOVLW high(KCODE0)		
		MOVWF TBLPTRH;
		BSF INTCON,RBIE;
		BSF INTCON,GIE;
LOOP	GOTO LOOP;

;-------------------------KEY IDENTIFICATION ISR

RBIF_ISR    CALL DELAY
			MOVFF PORTB,COL;
			MOVLW 0XFE
			MOVWF PORTB;
			CPFSEQ PORTB ;
			BRA ROW0;
			MOVLW 0XFC
			MOVWF PORTB;
			CPFSEQ PORTB ;
			BRA ROW1;
			MOVLW 0XFB
			MOVWF PORTB;
			CPFSEQ PORTB ;
			BRA ROW2;
			MOVLW 0XF7
			MOVWF PORTB;
			CPFSEQ PORTB ;
			BRA ROW3;
			GOTO BAD_RBIF ;
ROW0		MOVLW Low(KCODE0);
			BRA FIND;
ROW1		MOVLW Low(KCODE1);
			BRA FIND;
ROW2		MOVLW Low(KCODE2);
			BRA FIND;
ROW3		MOVLW Low(KCODE3);
													
FIND		MOVWF TBLPTRL;
			MOVLW 0XF0
			XORWF COL;
			SWAPF COL,F;
AGAIN		RRCF COL;
			BC MATCH;
			INCF TBLPTRL;
			BRA AGAIN;
MATCH		TBLRD*+
			MOVFF TABLAT,PORTD;
WAIT		MOVLW 0XF0 
			MOVWF PORTB;
			CPFSEQ PORTB;
			BRA WAIT;
			BCF INTCON,RBIF;
			RETFIE;
BAD_RBIF	MOVLW 0X00;
			GOTO WAIT;
;---------------------------DELAY

DELAY:      MOVLW D15mH;
			MOVWF DR15mH;
D2:			MOVLW D15mL;
			MOVWF DR15mL;
D1:			DECF DR15mL,F;
			BNZ D1
			DECF DR15mH,F;
			BNZ D2			
			RETURN
;----------------------------KEY SCANCODE LOOK-UP TABLE

			ORG	300H
KCODE0: 	DB	'7','8','9','/';
KCODE1: 	DB	'4','5','6','*';
KCODE2: 	DB	'1','2','3','-';
KCODE3: 	DB	'C','0','=','+';
					
;------------LCD INTERFACING



LCD_DATA	EQU PORTC
LCD_CTRL	EQU PORTA
RS			EQU	RA0
RW			EQU RA1	
EN			EQU RA2

			CLRF TRISC
			CLRF TRISA
			BCF LCD_CTRL,EN;
			CALL LDELAY;
			MOVLW 0X38;
			CALL COMNWRT;
			CALL LDELAY;
			MOVLW 0X0E;
			CALL COMNWRT;
			CALL RDELAY;			
			MOVLW 0X01;
			CALL COMNWRT;
			CALL RDELAY;
			MOVLW 0X06;
			CALL COMNWRT;
			CALL RDELAY;
			MOVLW PORTD;
			CALL DATAWRT;
RAGAIN		BTG LCD_CTRL,0;
			BRA RAGAIN;

				
COMNWRT		MOVWF LCD_DATA ;
			BCF LCD_CTRL,RS;
			BCF LCD_CTRL,RW;
			BSF LCD_CTRL,EN;
			CALL SDELAY;
			BCF LCD_CTRL,EN;
			RETURN

DATAWRT     MOVWF LCD_DATA ;
			BSF LCD_CTRL,RS;
			BCF LCD_CTRL,RW;
			BSF LCD_CTRL,EN;
			CALL SDELAY;
			BCF LCD_CTRL,EN;
			RETURN
	
		
R2 		EQU 0X2
R3 		EQU 0X3
R4		EQU 0X4

LDELAY:		MOVLW D'5'
			MOVWF R4
BACK1		MOVLW D'100'
			MOVWF R3
AGAIN1		MOVLW D'250'
			MOVWF R2
HERE1		NOP
			NOP
			DECF R2,F
			BNZ HERE1
			DECF R3,F
			BNZ AGAIN1
			DECF R4,F
			BNZ BACK1
			RETURN					
			

RDELAY:		MOVLW D'3'
			MOVWF R4
BACK2		MOVLW D'100'
			MOVWF R3
AGAIN2		MOVLW D'250'
			MOVWF R2
HERE2		NOP
			NOP
			DECF R2,F
			BNZ HERE2
			DECF R3,F
			BNZ AGAIN2
			DECF R4,F
			BNZ BACK2
			RETURN					
			


SDELAY:		MOVLW D'2'
			MOVWF R4
BACK3		MOVLW D'100'
			MOVWF R3
AGAIN3		MOVLW D'250'
			MOVWF R2
HERE3		NOP
			NOP
			DECF R2,F
			BNZ HERE3
			DECF R3,F
			BNZ AGAIN3
			DECF R4,F
			BNZ BACK3
			RETURN					
			
				
				END


*not included the arithmetic operations yet

The code here doesn't seem right....

Isn't "MOVLW PORTD" loading the address of the SFR Port D ?
I think the instruction should be "MOVF PORTD,W".

Code:
			CLRF TRISC
			CLRF TRISA
			BCF LCD_CTRL,EN;
			CALL LDELAY;
			MOVLW 0X38;
			CALL COMNWRT;
			CALL LDELAY;
			MOVLW 0X0E;
			CALL COMNWRT;
			CALL RDELAY;			
			MOVLW 0X01;
			CALL COMNWRT;
			CALL RDELAY;
			MOVLW 0X06;
			CALL COMNWRT;
			CALL RDELAY;
			MOVLW PORTD;          ;try movf portd,w here
			CALL DATAWRT;
RAGAIN		BTG LCD_CTRL,0;
			BRA RAGAIN;

Allen
 

Buy this book. https://www.flipkart.com/pic-microc...-assembly-c-18-english-1st/p/itmdytsukfghc8rx

It has asm code for keypad and LCD. It will help you in writing the code.
I am using the very same book, i used the code for keyboard and lcd from there only, but how do i make them work together?

The code here doesn't seem right....

Isn't "MOVLW PORTD" loading the address of the SFR Port D ?
I think the instruction should be "MOVF PORTD,W".

Allen

used it still not working, i also tried first moving the data from portd to another file register then to wreg still not working.

first of all is the value of the character from the look table being stored in portd?, is the keypad part correct?, if so then how do i put that value from portd to the LCD_DATA register?
 

There are more problems in your program than I've anticipated. in PIC18, all the ports that were used as output has to be changed from PORTx to LATx to make them work.

Further more the main problem is in the interrupt-driven keypad program. If I start off running from "main:", you can see grey color logic states on the port C and A in proteus. But if I modify the code to start running from the LCD part, and I replaced the instruction
"MOVF PORTD,W" with "MOVLW 0x41". I can at least see an "A" being displayed on the LCD.

Please do some more study on the keypad codes as I dont have enough time to go through all your codes. sorry!

Allen
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top