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] Scientific Calculator to be done with PIC18f4520

Status
Not open for further replies.

KhaledOsmani

Full Member level 6
Full Member level 6
Joined
May 4, 2014
Messages
384
Helped
1
Reputation
2
Reaction score
1
Trophy points
18
Visit site
Activity points
3,933
Hi,

Does any body knows how to make a cosine, sin, tan, exp, ln, AND OR XOR functions with PIC18 IDE Simulator?

The flowchart is as follows:
1.user inputs an operand (number) from a 4*4 keypad
2.the keypad turns to mathematical operations input (i.e 1 is for ADD 2 is for COS etc..)
3.the user inputs a second operand (number) from the same 4*4 keypad
4.the add or whatever else function is called, and the result is outputted on the GLCD

Thanks,
 

Doesn't PIC Simulator IDE has Math functions (Library) ? Are you writing code in PIC Simulator IDE's Basic Compiler or Assembler ?
 

PIC18 IDE basic compiler,
Actually there is a math library, and if you want to add two integers assumed to be X & Y you do:
code = X + Y

But the problem after making this done, is that the answer is only an arrangement of two sets of integers X & Y.
For example:
1 + 1 = 11
1 + 0 = 10
111 + 000 = 111000

See attachment
 

Attachments

  • add.png
    add.png
    9 KB · Views: 120

Please zip and post your PIC18 Simulator IDE basic or assembler program file. I will test it. maybe you are using demo version of PIC18 Simulator IDE which doesn't support math operations.

In basic + is used for addition and also string concatanation. It seems + is working as concatanation operator.
 
Last edited:

@milan.rajik:

only option 1 (addition) is available so far, all other operations are ignored.
Code:
Define GLCD_DREG = PORTB
Define GLCD_RSREG = PORTD
Define GLCD_RSBIT = 2
Define GLCD_EREG = PORTD
Define GLCD_EBIT = 3
Define GLCD_RWREG = PORTD
Define GLCD_RWBIT = 4
Define GLCD_CS1REG = PORTD
Define GLCD_CS1BIT = 0
Define GLCD_CS2REG = PORTD
Define GLCD_CS2BIT = 1

WaitMs 20
GLcdinit
Dim code As Long
Dim code1 As Long
Dim code2 As Long
Dim ans As Long
Dim j As Word
Dim i As Word
Dim k As Word

main:
	GLcdposition 0, 5
	GLcdwrite "+"
	GLcdposition 0, 32
	GLcdwrite "-"
	GLcdposition 8, 5
	GLcdwrite "*"
	GLcdposition 8, 32
	GLcdwrite "OP"
	GLcdposition 1, 5
	GLcdwrite "/"
	GLcdposition 1, 32
	GLcdwrite "Sin"
	GLcdposition 9, 5
	GLcdwrite "Cos"
	GLcdposition 9, 32
	GLcdwrite "ANS"
	GLcdposition 2, 5
	GLcdwrite "exp"
	GLcdposition 2, 32
	GLcdwrite "10"
	GLcdposition 10, 5
	GLcdwrite "tan"
	GLcdposition 10, 32
	GLcdwrite "AC"
	GLcdposition 3, 5
	GLcdwrite "AND"
	GLcdposition 3, 32
	GLcdwrite "OR"
	GLcdposition 11, 5
	GLcdwrite "XOR"
	GLcdposition 11, 32
	GLcdwrite "="
	begin:
	code = 0
	GLcdclean 4
	GLcdclean 5
	GLcdclean 6
	GLcdclean 7
	j = 4
	i = 0
	k = 4
	Gosub checkcode
	code1 = code
	herre:
	j = 5
	i = 5
	Gosub checkoperation
	here:
	j = 6
	i = 0
	Gosub checkcode
	End

checkcode:
	High PORTC.0
	
	If PORTC.4 Then
		code = code * 10 + 1
		GLcdposition j, i
		GLcdwrite "1"
		WaitMs 20
		i = i + 6
		Goto checkcode
	Endif
			
	If PORTC.5 Then
		code = code * 10 + 4
		GLcdposition j, i
		GLcdwrite "4"
		WaitMs 20
		i = i + 6
		Goto checkcode
	Endif
	
	If PORTC.6 Then
		code = code * 10 + 7
		GLcdposition j, i
		GLcdwrite "7"
		WaitMs 20
		i = i + 6
		Goto checkcode
	Endif
	
	Low PORTC.0
	WaitMs 20
	High PORTC.1
	
	If PORTC.4 Then
		code = code * 10 + 2
		GLcdposition j, i
		GLcdwrite "2"
		WaitMs 20
		i = i + 6
		Goto checkcode
	Endif
	
	If PORTC.5 Then
		code = code * 10 + 5
		GLcdposition j, i
		GLcdwrite "5"
		WaitMs 20
		i = i + 6
		Goto checkcode
	Endif
	
	If PORTC.6 Then
		code = code * 10 + 8
		GLcdposition j, i
		GLcdwrite "8"
		WaitMs 20
		i = i + 6
		Goto checkcode
		Endif
		
	If PORTC.7 Then
		code = code * 10 + 0
		GLcdposition j, i
		GLcdwrite "0"
		WaitMs 20
		i = i + 6
		Goto checkcode
		Endif


	Low PORTC.1
	WaitMs 20
	High PORTC.2
	
		If PORTC.7 Then
			GLcdclean k, 0
			i = 0
			code = 0
		Endif
	
	If PORTC.4 Then
		code = code * 10 + 3
		GLcdposition j, i
		GLcdwrite "3"
		WaitMs 20
		i = i + 6
		Goto checkcode
	Endif
	
		If PORTC.5 Then
		code = code * 10 + 6
		GLcdposition j, i
		GLcdwrite "6"
		WaitMs 20
		i = i + 6
		Goto checkcode
	Endif
	
	If PORTC.6 Then
		code = code * 10 + 9
		GLcdposition j, i
		GLcdwrite "9"
		WaitMs 20
		i = i + 6
		Goto checkcode
	Endif
	Low PORTC.2
	WaitMs 25
	High PORTC.3
		If PORTC.4 Then
			Goto endcheckcode
		Endif
		If PORTC.5 Then
			Goto endcheckcode
		Endif
	Low PORTC.3
	Goto checkcode
endcheckcode:
Return                                            

checkoperation:
	'WaitMs 25
	High PORTC.0
	
	If PORTC.4 Then
		'code = code * 10 + 1
		GLcdposition j, i
		GLcdwrite "+"
		WaitMs 20
		i = i + 6
		Goto addition
	Endif
			
	If PORTC.5 Then
		'code = code * 10 + 4
		GLcdposition j, i
		GLcdwrite "/"
		WaitMs 20
		i = i + 6
		Goto here
	Endif
	
	If PORTC.6 Then
		'code = code * 10 + 7
		GLcdposition j, i
		GLcdwrite "exp"
		WaitMs 20
		i = i + 6
		'Goto exponential
	Endif
	
	If PORTC.7 Then
		GLcdposition j, i
		GLcdwrite "AND"
		WaitMs 20
		Goto here
	Endif
	
	Low PORTC.0
	High PORTC.1
	
	If PORTC.4 Then
		'code = code * 10 + 2
		GLcdposition j, i
		GLcdwrite "-"
		WaitMs 20
		i = i + 6
		Goto here
	Endif
	
	If PORTC.5 Then
		'code = code * 10 + 5
		GLcdposition j, i
		GLcdwrite "Sin"
		WaitMs 20
		i = i + 6
		Goto here
	Endif
	
	If PORTC.6 Then
		'code = code * 10 + 8
		GLcdposition j, i
		GLcdwrite "10"
		WaitMs 20
		i = i + 6
		Goto here
		Endif
		
	If PORTC.7 Then
		'code = code * 10 + 0
		GLcdposition j, i
		GLcdwrite "0R"
		WaitMs 20
		i = i + 6
		Goto here
		Endif


	Low PORTC.1
	High PORTC.2
	
		If PORTC.7 Then
			GLcdclean k, 0
			i = 0
			code = 0
		Endif
	
	If PORTC.4 Then
		'code = code * 10 + 3
		GLcdposition j, i
		GLcdwrite "*"
		WaitMs 20
		i = i + 6
		Goto here
	Endif
	
		If PORTC.5 Then
		'code = code * 10 + 6
		GLcdposition j, i
		GLcdwrite "Cos"
		WaitMs 20
		i = i + 6
		Goto here
	Endif
	
	If PORTC.6 Then
		'code = code * 10 + 9
		GLcdposition j, i
		GLcdwrite "tan"
		WaitMs 20
		i = i + 6
		Goto here
		Endif
	
	If PORTC.7 Then
		GLcdposition j, i
		GLcdwrite "XOR"
		WaitMs 20
		Goto here
	Endif
	Low PORTC.2
	
	High PORTC.3
		If PORTC.4 Then
			GLcdposition j, i
			GLcdwrite "OP"
			WaitMs 20
			Goto here
			Endif
		
		If PORTC.5 Then
			GLcdposition j, i
			GLcdwrite "ANS"
			WaitMs 20
			Goto here
		Endif

		If PORTC.6 Then
			GLcdposition j, i
			GLcdwrite "AC"
			WaitMs 20
			Goto here
		Endif
		
		If PORTC.6 Then
			GLcdposition j, i
			GLcdwrite "="
			WaitMs 20
			Goto here
		Endif

			
	Low PORTC.3
	Goto checkoperation
doneoperation:
Return                                            


addition:
	j = 6
	i = 0
	Gosub checkcode
	code2 = code
	ans = code1 + code2
	GLcdposition 7, 0
	GLcdwrite "ANS:", #ans
	WaitMs 20
	checkclear:
	High PORTC.3
		If PORTC.6 Then
			Goto begin
		Else
			Goto checkclear
		Endif
	Low PORTC.3
Return

- - - Updated - - -

PIC Simulator IDE is a toy for newbie, who wants to understand a mcu basics.

nice mouth man, better to control it though
 

How to test the code. I saved it as .bas file from within PIC18 Simulator IDE's Basic Compiler and Compiled and loaded the file. Opened GLCD and applied the GLCD setup and started the simulation but GLCD doesn't display anything.
 

Copy/Paste it into the BASIC simulator
save it: File: Save as
Compile, assemble and load it by pressing F9 or Tools: Compile Assemble & Load
Make sure that the setup of the GLCD is the same exact ones used in the code
 

Everything is setup properly but GLCD is not displaying anything. I am getting these messages when compiling. See image.
 

Attachments

  • pic sim.png
    pic sim.png
    266.1 KB · Views: 119

No, the one in the background is Keil uVision 4 with ARM assembly language program. The one in front is PIC18 Simulator IDE showing GLCD connections and Compilation messages.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top