![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | Thread Tools | Display Modes |
| | (permalink) |
| Experienced Member | Code: Dim Seg_Display as byte[5] 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 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 Above all codes written in mikroBasic I am beginer and learing from Nigel Goodwin's tutorials Thanks in advance. |
| | |
| | (permalink) |
| Super Moderator | Just allocate the bytes in GPR's, it's up to you though to access them correctly. |
| | |
| | (permalink) |
| Experienced Member | 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 |
| | |
| | (permalink) |
| Experienced Member | 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 |
| | |
| | (permalink) |
| Experienced Member | don't you just hate it when one line of code gets misaligned. |
| | |
| | (permalink) |
| Experienced Member | 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 |
| | |
| | (permalink) |
| Experienced Member | 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?? |
| | |
| | (permalink) | ||
| Experienced Member | Quote:
Quote:
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. | ||
| | |
| | (permalink) |
| Experienced Member | Is there any easier way for doing this instead adding indivisual byte as in ur example |
| | |
| | (permalink) | |
| Experienced Member | Quote:
__________________ --- The days of the digital watch are numbered. --- Last edited by kchriste; 25th December 2006 at 03:54 PM. | |
| | |
| | (permalink) |
| Experienced Member | 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 |
| | |
| | (permalink) |
| Experienced Member | Code: IF (INTCON,TOIF == 1) ;Flag Set if TMR0 Interrupt GOTO INT_TMRO ENDIF Code: IF(SEGMENT > 32) SEGMENT == 2 ENDIF 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 |
| | |
| | (permalink) |
| Experienced Member | What is the function of this command??? MOVPF It is an old command?? |
| | |
| | (permalink) | |
| Experienced Member | Quote:
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 MOVPF doesn't exist. HTH Mike. | |
| | |
| | (permalink) | |
| Experienced Member | 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:
| |
| | |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |