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.

Calculator using PIC16f877a microcontroller and simulation using proteus software

Status
Not open for further replies.

Gautam G

Newbie level 3
Joined
Apr 30, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Coimbatore
Activity points
1,305
good day,

can any one help in solving this error for my project...I have to submit before may 4th...plz plz plz help me
I will display my code here... My problem is if run my program in MPLAB IDE v8.83 I am getting right result and when I have done my simulation in proteus software I am getting wrong results. will some one help me with this problem??

code:

Code:
#include"p16f877a.inc"
status equ 0x03
cblock 0x20
r0,r1,temp,temp2,temp3,carry,rest,temp4
endc
org00
goto main
org 04h
retfie


main
movlw 0x00
movwf temp3	
bsf status,5
bcf status,6
movlw 0xf0
movwf TRISD
movlw 0x00
movwf TRISC
bcf status,5

top
bsf PORTD,0
BCF PORTD,1
BCF PORTD,2
BCF PORTD,3
btfsc PORTD,4
goto l1
btfsc PORTD,5
goto l2
btfsc PORTD,6
goto l3
btfsc PORTD,7
goto l4

bcf PORTD,0
bsf PORTD,1
BCF PORTD,2
BCF PORTD,3
btfsc PORTD,4
goto l5
btfsc PORTD,5
goto l6
btfsc PORTD,6
goto l7
btfsc PORTD,7
goto l8

BCF PORTD,0
BCF PORTD,1
bsf PORTD,2
BCF PORTD,3
btfsc PORTD,4
goto l9
btfsc PORTD,5
goto l10
btfsc PORTD,6
goto l11
btfsc PORTD,7
goto l12

BCF PORTD,0
BCF PORTD,1
bcf PORTD,2
BSF PORTD,3
btfsc PORTD,4
goto l13
btfsc PORTD,5
goto l14
btfsc PORTD,6
goto l15
btfsc PORTD,7
goto l16
goto top


l1	movlw 0x0e
movwf PORTC
movlw 0x07
movwf temp
goto top
l2	movlw 0xcc
movwf PORTC
movlw 0x04
movwf temp
goto top
l3	movlw 0x0c
movwf PORTC
movlw 0x01
movwf temp
goto top
l4	movlw 0x00
movwf PORTC
movlw 0x00
movwf temp
goto top


l5	movlw 0xfe
movwf PORTC
movlw 0x08
movwf temp
goto top
l6	movlw 0xda
movwf PORTC
movlw 0x05
movwf temp
goto top
l7	movlw 0xb6
movwf PORTC
movlw 0x02
movwf temp
goto top
l8	movlw 0x7e
movwf PORTC
movlw 0x00
movwf temp
goto top


l9	movlw 0xce
movwf PORTC
movlw 0x09
movwf temp
goto top
l10	movlw 0xfa
movwf PORTC
movlw 0x06
movwf temp
goto top
l11	movlw 0x9e
movwf PORTC
movlw 0x03
movwf temp
goto top
l12	
movlw 0xbc
subwf rest,0
btfsc status,2
goto div
movlw 0x92
subwf rest,0
btfsc status,2
goto mult
movlw 0x80
subwf rest,0
btfsc status,2
goto sub
movlw 0xe6
subwf rest,0
btfsc status,2
goto add
deck:
movf temp3,0
movwf temp4

movlw 0x00
subwf temp4,0
btfsc status,2
goto l8

movlw 0x01
subwf temp4,0
btfsc status,2
goto l3

movlw 0x02
subwf temp4,0
btfsc status,2
goto l7

movlw 0x03
subwf temp4,0
btfsc status,2
goto l11

movlw 0x04
subwf temp4,0
btfsc status,2
goto l2

movlw 0x05
subwf temp4,0
btfsc status,2
goto l6

movlw 0x06
subwf temp4,0
btfsc status,2
goto l10

movlw 0x07
subwf temp4,0
btfsc status,2
goto l1

movlw 0x08
subwf temp4,0
btfsc status,2
goto l5

movlw 0x09
subwf temp4,0
btfsc status,2
goto l9

goto top

l13	movlw 0xbc
movwf rest
movwf PORTC
movf temp,0
movwf temp2
goto top
l14	movlw 0x92
movwf rest
movwf PORTC
movf temp,0
movwf temp2
goto top
l15	movlw 0x80
movwf rest
movwf PORTC
movf temp,0
movwf temp2
goto top
l16	movlw 0xe6
movwf rest
movwf PORTC
movf temp,0
movwf temp2
goto top

add:
movf temp2,0
addwf temp,0
movwf temp3
goto deck

sub:
movf temp,0
subwf temp2,0
movwf temp3
goto deck

mult:
movlw 0x00
movwf carry
rot:
addwf temp,0
btfsc status,0
incf carry,1
decfsz temp2,1
goto rot
movwf temp3
goto deck

div:
movlw 0x00
movwf temp3
loop1:
movf temp,0
subwf temp2,1
btfsc status,0
goto loop2
movf temp,0
addwf temp2,1
goto deck

loop2:
incf temp3,1
goto loop1

last nop
end


any suggestions?

thanx guys.... :)
 
Last edited by a moderator:

Can you please explain a little more, What result are you looking for and what is right and wrong??

Have you asked the guys in Labcenter about your issue, I generally find them fairly good??
 

Can you please explain a little more, What result are you looking for and what is right and wrong??

Have you asked the guys in Labcenter about your issue, I generally find them fairly good??

Thanx for your interest.Well I am looking for result that appears in seven segment display. In proteus software the calculator keypad is available and also 1digit 7-segment (common cathode)display also available. I had connected apparatus and then run the program. When i pressed '2' button and then '+' and then '4' the answer I am getting is '8'. But when I checked in MPLAB IDE I am getting right answer as '6'. So asked my madam she suggested me to keep here. Code I had written is right. It shows no errors but while in simulation problem occurs and doesnt display required answer. If I multiply two numbers or divide two numbers it displays zero. And when I subtract two numbers the second number I entered to subtract and the final result obtained after subtraction both are displayed like toggling like "5-3" equals 232323..and then stops at either 2 or 3 being displayed unless '=' button is pressed again it doesnt show correct result. kindly help me with this problem.

thanx once again...:)
 

Well to be honest i would talk to the guys in Labcenter (Proteus) and explain the issue,

If MPLAB is showing it correctly then it would suggest the program is correct,

On a side note you might find it useful to comment your code, Reams of code like above with no comments make it difficult to see the flow and whats going on,
 

Well to be honest i would talk to the guys in Labcenter (Proteus) and explain the issue,

If MPLAB is showing it correctly then it would suggest the program is correct,

On a side note you might find it useful to comment your code, Reams of code like above with no comments make it difficult to see the flow and whats going on,

I am sorry about the comments I dont have that habbit next time I will keep the comments definitely.


Code:
#include"p16f877a.inc"
status equ 0x03
cblock 0x20
temp,temp2,temp3,carry,rest,temp4,rest                   ;declarations 'temp' for storing second digit 'temp2' for storing first digit 'temp3" and
endc                                                                ;'temp4' for storing result
org00
goto main
org 04h
retfie


main
movlw 0x00
movwf temp3	                                                   ;PORTD lsb 4bits configured as o/p bits and remaining as i/p bits
bsf status,5
bcf status,6
movlw 0xf0
movwf TRISD
movlw 0x00
movwf TRISC                                                        ;PORTC configured as o/p bits
bcf status,5

top
bsf PORTD,0
BCF PORTD,1                                                         ;In calculator 4x4 keypad is present 
BCF PORTD,2                                                         ; I configured as if lsb bits of PORTD made as '1000'
BCF PORTD,3                                                         ; input to pic will be either 7 or 4 or 1 or on/off(0) corresponding goes to that loop
btfsc PORTD,4                                                       ; l1 corresponds that to display 7 in 7-segment common cathode display similarly
goto l1                                                                 ; l2 corresponds to display 4
btfsc PORTD,5                                                       ; l3 corresponds to display 1 and goes on....
goto l2
btfsc PORTD,6
goto l3
btfsc PORTD,7
goto l4

bcf PORTD,0
BSF PORTD,1                                                         
BCF PORTD,2                                                         ; I configured as if lsb bits of PORTD made as '0100'
BCF PORTD,3                                                         ; input to pic will be either 8 or 5 or 2 or 0
btfsc PORTD,4
goto l5
btfsc PORTD,5
goto l6
btfsc PORTD,6
goto l7
btfsc PORTD,7
goto l8

bcf PORTD,0
BCF PORTD,1                                                         
BSF PORTD,2                                                         ; I configured as if lsb bits of PORTD made as '0010'
BCF PORTD,3                                                         ; input to pic will be either 9 or 6 or 3 or =
btfsc PORTD,4
goto l9
btfsc PORTD,5
goto l10
btfsc PORTD,6
goto l11
btfsc PORTD,7
goto l12

bcf PORTD,0
BCF PORTD,1                                                         
BCF PORTD,2                                                         ; I configured as if lsb bits of PORTD made as '0001'
BSF PORTD,3                                                         ; input to pic will be either / or * or - or +
btfsc PORTD,4
goto l13
btfsc PORTD,5
goto l14
btfsc PORTD,6
goto l15
btfsc PORTD,7
goto l16
goto top


l1	movlw 0x0e
movwf PORTC                                            ; '0e' is the value to be sent in order to display '7' similarly remaining and stores the value
movlw 0x07                                               ; in the temp reg
movwf temp
goto top
l2	movlw 0xcc
movwf PORTC
movlw 0x04
movwf temp
goto top
l3	movlw 0x0c
movwf PORTC
movlw 0x01
movwf temp
goto top
l4	movlw 0x00
movwf PORTC
movlw 0x00
movwf temp
goto top


l5	movlw 0xfe
movwf PORTC
movlw 0x08
movwf temp
goto top
l6	movlw 0xda
movwf PORTC
movlw 0x05
movwf temp
goto top
l7	movlw 0xb6
movwf PORTC
movlw 0x02
movwf temp
goto top
l8	movlw 0x7e
movwf PORTC
movlw 0x00
movwf temp
goto top


l9	movlw 0xce
movwf PORTC
movlw 0x09
movwf temp
goto top
l10	movlw 0xfa
movwf PORTC
movlw 0x06
movwf temp
goto top
l11	movlw 0x9e
movwf PORTC
movlw 0x03
movwf temp
goto top
l12	
movlw 0xbc                                                      ; rest reg is used to store the value corresponding to + or - or * or / and
subwf rest,0                                                     ; checks which one is pressed by the keypad 
btfsc status,2
goto div
movlw 0x92
subwf rest,0
btfsc status,2
goto mult
movlw 0x80
subwf rest,0
btfsc status,2
goto sub
movlw 0xe6
subwf rest,0
btfsc status,2
goto add
deck:
movf temp3,0
movwf temp4

movlw 0x00
subwf temp4,0                      ;checks if the number in temp4 reg is 0 or 1 or 2...or 9 and displays accordingly going to that sub-routine
btfsc status,2
goto l8

movlw 0x01
subwf temp4,0
btfsc status,2
goto l3

movlw 0x02
subwf temp4,0
btfsc status,2
goto l7

movlw 0x03
subwf temp4,0
btfsc status,2
goto l11

movlw 0x04
subwf temp4,0
btfsc status,2
goto l2

movlw 0x05
subwf temp4,0
btfsc status,2
goto l6

movlw 0x06
subwf temp4,0
btfsc status,2
goto l10

movlw 0x07
subwf temp4,0
btfsc status,2
goto l1

movlw 0x08
subwf temp4,0
btfsc status,2
goto l5

movlw 0x09
subwf temp4,0
btfsc status,2
goto l9

goto top

l13	movlw 0xbc                         ;displays 'd' in 7-seg display and stores in rest register and similarly others
movwf rest
movwf PORTC
movf temp,0
movwf temp2
goto top
l14	movlw 0x92
movwf rest
movwf PORTC
movf temp,0
movwf temp2
goto top
l15	movlw 0x80
movwf rest
movwf PORTC
movf temp,0
movwf temp2
goto top
l16	movlw 0xe6
movwf rest
movwf PORTC
movf temp,0
movwf temp2
goto top

add:
movf temp2,0                                      ;In all sub-routine's temp reg value stored in temp2 reg inorder to store second number
addwf temp,0                                      ; and corresponding add, subtract, multiplication and divisions are done
movwf temp3
goto deck

sub:
movf temp,0
subwf temp2,0
movwf temp3
goto deck

mult:
movlw 0x00
movwf carry
rot:
addwf temp,0
btfsc status,0
incf carry,1
decfsz temp2,1
goto rot
movwf temp3
goto deck

div:
movlw 0x00
movwf temp3
loop1:
movf temp,0
subwf temp2,1
btfsc status,0
goto loop2
movf temp,0
addwf temp2,1
goto deck

loop2:
incf temp3,1
goto loop1

last nop
end
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top