Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 25th December 2006, 05:04 AM   (permalink)
Experienced Member
 
Ayne is on a distinguished road
Default How we can do it in Assembly..Help Needed

Code:
Dim Seg_Display as byte[5]
It creats 5 variables in RAM like this
Seg_Display0
Seg_Display1
Seg_Display2
Seg_Display3
Seg_Display4
we can access any variable.
How we do this in Assembly??

Code:
Dim  Final_Volt    as longint
In this Final_Volt is equal to 32–bit long variable, We can assign any value between -2147483648 ~ 2147483647.
How we definae in assembly that variable(For example Variable Volt) is a longint??

Code:
Dim Seg_Display as byte[5]
Dim        v        as byte

Main:
PORTB  = Seg_Display[v]
Inc(v)
 if v > 4 then
    v = 0 
  end if
Seg_Display[0] = 10011011
Seg_Display[1] = 11001011
Seg_Display[2] = 10111111
Seg_Display[3] = 10111001
Seg_Display[4] = 11111011
Delay_ms(250) 
Goto Main
End
How can we do this in Assembly?
Above all codes written in mikroBasic

I am beginer and learing from Nigel Goodwin's tutorials
Thanks in advance.
Ayne is offline   Reply With Quote
Old 25th December 2006, 01:32 PM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

Just allocate the bytes in GPR's, it's up to you though to access them correctly.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 25th December 2006, 02:06 PM   (permalink)
Experienced Member
 
Ayne is on a distinguished road
Default

Code:
Dim Seg_Display as byte[5]
Dim        v        as byte

Main:
PORTB  = Seg_Display[v]
Inc(v)
 if v > 4 then
    v = 0 
  end if
Seg_Display[0] = 10011011
Seg_Display[1] = 11001011
Seg_Display[2] = 10111111
Seg_Display[3] = 10111001
Seg_Display[4] = 11111011
Delay_ms(250) 
Goto Main
End
Plz convert this code in assembly
Ayne is offline   Reply With Quote
Old 25th December 2006, 02:39 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

As I'm bored,

Definitely untested,

Code:
		cblock 0x20
Seg_Display:5
v
		endc

Main	incf	v,F
	movfw	v
	sublw	5
	btfsc	STATUS,z
	clrf	v
	movfw	v
	addlw	Seg_Display
	movwf	FSR
             bcf        STATUS,IRP
	movfw	INDF
	movwf	PORTB
	movlw	b'10011011'
	movwf	Seg_Display
	movlw	b'11001011'
	movwf	Seg_Display+1
	movlw	b'10111111'
	movwf	Seg_Display+2
	movlw	b'10111001'
	movwf	Seg_Display+3
	movlw	b'11111011'
	movwf	Seg_Display+4
	goto	Main
Pommie is offline   Reply With Quote
Old 25th December 2006, 02:41 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

don't you just hate it when one line of code gets misaligned.
Pommie is offline   Reply With Quote
Old 25th December 2006, 02:44 PM   (permalink)
Experienced Member
 
evandude is just really niceevandude is just really niceevandude is just really nice
Default

You can't declare a longint in assembly. The PIC is an 8-bit microcontroller, it can't natively handle anything but 8 bits at a time. If you want a 32-bit value, it's going to be represented as four 8-bit bytes, and you need to do all the math and housekeeping for each of those bytes yourself.
I suggest you check out the following pages, which have a lot of math routines, particularly for handling 16, 24, and 32-bit values in assembly. I think you're going to be disappointed when you realize how complicated it can be.
http://www.piclist.com/techref/microchip/math/basic.htm
http://www.piclist.com/techref/micro...32bmath-ph.htm

This is a perfect example of what I (and others) always say: to code effectively on a PIC in a high-level language, you really need to understand how your routines are getting translated to assembly. It's too easy to just throw in 32-bit variables in C or BASIC just because that's the way you do it on a PC, without realizing that the implementation in assembly to perform math operations on them can be a huge, inefficient nightmare.
__________________
EEgeek.net
evandude is offline   Reply With Quote
Old 25th December 2006, 02:51 PM   (permalink)
Experienced Member
 
Ayne is on a distinguished road
Default

Thank u, now i understand that,
we use "Seg_Display+0" instead "Seg_Display[0]"....(the difference is brakets and in assembly we will use +.

Now second question
Supose i have a variable named "Volt" i want to store a value "146621" . As we can see this value is larger than a byte. Now plz guide me how we store this value in variable??
Ayne is offline   Reply With Quote
Old 25th December 2006, 02:59 PM   (permalink)
Experienced Member
 
evandude is just really niceevandude is just really niceevandude is just really nice
Default

Quote:
Originally Posted by Ayne
Thank u, now i understand that,
we use "Seg_Display+0" instead "Seg_Display[0]"....(the difference is brakets and in assembly we will use +.
but you should actually understand what's going on there, rather than just considering it a difference of syntax. 'Seg_Display' represents a memory address. 'Seg_Display+1' represents the next memory address, and so on.

Quote:
Originally Posted by Ayne
Supose i have a variable named "Volt" i want to store a value "146621" . As we can see this value is larger than a byte. Now plz guide me how we store this value in variable??
You have to break it up.
146621 = 0b100011110010111101
that particular value is 18 bits in binary. So, presumably you'd store it as a 24-bit value consisting of 3 8-bit values. Look at the binary representation of it - the least significant 8 bits (10111101) would get stored in one byte, the next 8 (00111100) in another byte, and the rest in another byte (00000010). Any time you want to actually USE the variable, you need to use the kind of math routines I linked in my previous post, because unlike 8-bit variables, you can't just use the assembly add and subtract instructions and be done.
__________________
EEgeek.net

Last edited by evandude; 25th December 2006 at 03:02 PM.
evandude is offline   Reply With Quote
Old 25th December 2006, 03:24 PM   (permalink)
Experienced Member
 
Ayne is on a distinguished road
Default

Is there any easier way for doing this instead adding indivisual byte as in ur example
Ayne is offline   Reply With Quote
Old 25th December 2006, 03:49 PM   (permalink)
Experienced Member
kchriste is a glorious beacon of lightkchriste is a glorious beacon of lightkchriste is a glorious beacon of lightkchriste is a glorious beacon of lightkchriste is a glorious beacon of light
Default

Quote:
Is there any easier way for doing this instead adding indivisual byte as in ur example
Not without using a 24 or 32bit microcontroller. A PIC24F will make it a little earier because it can do 16bit.
__________________
--- The days of the digital watch are numbered. ---

Last edited by kchriste; 25th December 2006 at 03:54 PM.
kchriste is offline   Reply With Quote
Old 25th December 2006, 04:51 PM   (permalink)
Experienced Member
 
evandude is just really niceevandude is just really niceevandude is just really nice
Default

You really need to stop and think about whether you actually NEED 24 or 32-bit values in your program. Often, you can reorganize things so it's not necessary - for instance if it's only used for a long timing loop, a couple of nested 8-bit loops is just as good as a single 16-bit loop, and generally makes more sense in assembly.

If you are truly determined to do everything the easy way and not care at all about writing intelligent, efficient code, then you probably won't want to use assembly language, because it doesn't let you get away with it. BASIC and C compilers let you toss around 16, 24, and 32-bit values like you want, however if you do it that way, don't be surprised when your resulting programs compile to extremely large code size, have unexpected problems, and be extremely slow to run - it's not unreasonable to see multiplication and division on 32-bit numbers to take 1000 clock cycles to complete - do that very often and you can absolutely cripple your program on the PIC.
__________________
EEgeek.net
evandude is offline   Reply With Quote
Old 26th December 2006, 04:19 PM   (permalink)
Experienced Member
 
Ayne is on a distinguished road
Default

Code:
IF (INTCON,TOIF == 1)	;Flag Set if TMR0 Interrupt
 GOTO	INT_TMRO
 ENDIF
Can assembler perform bolean in IF instruction?

Code:
IF(SEGMENT > 32)
		SEGMENT == 2
		ENDIF
I want to check that segment is higher than 32(Decimal) or not.
How to tell the assembler that the value is in Decimal?
I think like below, plz tell me i am wrong or right
Code:
IF(SEGMENT > D'32')
		SEGMENT == 2
		ENDIF
Ayne is offline   Reply With Quote
Old 26th December 2006, 06:23 PM   (permalink)
Experienced Member
 
Ayne is on a distinguished road
Default

What is the function of this command??? MOVPF
It is an old command??
Ayne is offline   Reply With Quote
Old 26th December 2006, 10:36 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

Quote:
Originally Posted by Ayne
Code:
IF (INTCON,TOIF == 1)	;Flag Set if TMR0 Interrupt
 GOTO	INT_TMRO
 ENDIF
Can assembler perform bolean in IF instruction?

Code:
IF(SEGMENT > 32)
		SEGMENT == 2
		ENDIF
I want to check that segment is higher than 32(Decimal) or not.
How to tell the assembler that the value is in Decimal?
I think like below, plz tell me i am wrong or right
Code:
IF(SEGMENT > D'32')
		SEGMENT == 2
		ENDIF
Code:
        btfsc  INTCON,T0IF
        goto   INT_TMR0


        movfw	SEGMENT;	move segment to working register
        sublw 	.32;		subtract decimal (.) 32
        movlw	.2;		put 2 into work register
        btfss	STATUS,C;	test is w was more than 32
        movwf	SEGMENT;	if it was store W in segment
You can also use d'32' to tell the assembler it is decimal.

MOVPF doesn't exist.

HTH

Mike.
Pommie is offline   Reply With Quote
Old 27th December 2006, 08:33 AM   (permalink)
Experienced Member
 
Ayne is on a distinguished road
Default

I think we can use direct IF command in MPLAB.. What u say?
I am saying Yes because In the MPLAB assembler help file there are examples that using IF command in assembly.

Quote:
MOVPF doesn't exist.
AN617(Fixed Point Routines) is a file from Microchip. They are useing MOVPF instruction.
Ayne is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Need help with Intel Assembly Language and PIC16F877 avinsinanan Micro Controllers 10 4th March 2008 10:02 AM
Assembly? Marks256 Micro Controllers 43 28th July 2006 03:44 PM
Assembly compiler Thunderchild Micro Controllers 4 12th March 2006 01:25 PM
Learning Assembly Programming Language Johnson777717 Micro Controllers 4 22nd March 2004 02:00 PM
Assembly Language Question Jeggyman General Electronics Chat 6 30th January 2004 09:53 PM



All times are GMT. The time now is 12:01 AM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.