-
July 5th, 2010, 10:54 PM
#1
MPLab PIC Microchip / Version of Assembly Question
I've been tasked with writing a concise bit of code for a microchip and have been using the MPLAB IDE. I have a little experience with Assembly, but it was with MASM. I've got the pseudo code and my best effort at a MASM implementation, but I guess several of the things I'm doing won't work with bare bones assembly.
Pseudo code (which I was given)
Code:
;Output_a on or off output
;Output_b on or off output
;Boolean_a
;Wait()=1ms
;Wait2= 1.1ms
while(true){
if(Input_a > 200){
Boolean_a=1
Wait();
Output_a on until input_a<200
}
if (Output_a off & Boolean_a=1 then Boolean_a=0 and Output_b on){
Wait2()
}
Output_b off
}
Assembly I translated the pseudo code into:
Code:
; Given as part of template file
MAIN CODE 0x000
movwf OSCCAL ; update register with factory cal value
start
;GP0 is input_a
;GP1 is output_a
;Gp3 is output_b
bool_a WORD 0 ;initializes bool_a to 0
Delay1 Proc Near
movlw 0x01 ;delay for 1.000 ms
Ret
Delay1 Endp
Delay2
movlw 0x011 ;delay for 1.100 ms
Ret
Delay2 Endp
Loop:
if1: ;(GP0 > 200){
mov bool_a, 1
Call Delay1 ;calls a delay of 1ms
mov GP1, 1 ;sets output_a
while1: ;(GP0 >= 200){
cmp GP0, 200
jae while1 ;jumps to while1 if GP0 >= 200
;}
cmp GP0, 200
ja if1 ;jumps to if1 if GP0 > 200
;}
bool_a = 0
mov GP3, 1 ;sets output_b to on
Call Delay2 ;calls a delay of 1.1ms
mov GP3, 0 ;sets output_b to off
jmp Loop ;go to Loop (repeat everything)
END ;directive 'end of program'
And finally, the long list of errors the MPLAB IDE gives me when I try to compile this.
Code:
Error[122] C:\PROJECTS\FIRSTTRY.ASM 74 : Illegal opcode (WORD)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 76 : Illegal opcode (Proc)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 78 : Found label after column 1. (Ret)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 79 : Illegal opcode (Endp)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 83 : Found label after column 1. (Ret)
Error[116] C:\PROJECTS\FIRSTTRY.ASM 83 : Address label duplicated or different in second pass (Ret)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 84 : Illegal opcode (Endp)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 87 : Found label after column 1. (Loop)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 88 : Found label after column 1. (if1)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 89 : Found label after column 1. (mov)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 89 : Illegal opcode (bool_a)
Error[113] C:\PROJECTS\FIRSTTRY.ASM 90 : Symbol not previously defined (Delay1)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 92 : Found label after column 1. (mov)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 92 : Illegal opcode (GP1)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 94 : Found label after column 1. (while1)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 96 : Found label after column 1. (cmp)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 96 : Illegal opcode (GP0)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 97 : Found label after column 1. (jae)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 97 : Illegal opcode (while1)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 99 : Found label after column 1. (cmp)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 99 : Illegal opcode (GP0)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 100 : Found label after column 1. (ja)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 100 : Illegal opcode (if1)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 103 : Found label after column 1. (bool_a)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 104 : Found label after column 1. (mov)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 104 : Illegal opcode (GP3)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 106 : Found label after column 1. (mov)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 106 : Illegal opcode (GP3)
Warning[207] C:\PROJECTS\FIRSTTRY.ASM 109 : Found label after column 1. (jmp)
Error[122] C:\PROJECTS\FIRSTTRY.ASM 109 : Illegal opcode (Loop)
Warning[205] C:\PROJECTS\FIRSTTRY.ASM 112 : Found directive in column 1. (END)
Halting build on first failure as requested.
It seems to be telling me that just about everything I'm doing is causing an error. Does anybody have any helpful hints or a link to some good reading on PIC microchip programming?
-
July 6th, 2010, 08:03 PM
#2
Re: MPLab PIC Microchip / Version of Assembly Question
Sorry to say that, but it really looks as if you are not knowing what you are doing there.
I have no experience with these PIC microcontrollers myself, but here are just a few things that immediately caught my eye:
I don't suppose a basic microcontroller like most of the PICs are to have any notion of the distinction between near and far jumps (or calls).
And even if they have, and even if the syntax for coding procedures is the same as for x86 (which I strongly doubt): Your Delay2 proc lacks the proc and near keywords on the first line.
And why are you expecting a single mov instruction to cause a delay of any defined time or even one that has exactly the duration of the ms count you load into the accumulator? (And why should 0x011 be 1.1 ms when 0x01 is 1 ms? This accumulator certainly is not some kind of floating point register.)
As I said, I don't know these PICs myself (and there are lots of them), but simply hacking the word PIC into Wikipedia took me to http://en.wikipedia.org/wiki/PIC_microcontroller. (I wonder why you haven't tried at least that yourself. It's about the first thing I try for almost any question.) That Wikipedia article has quite a bunch of external links of which one or the other might take you further.
Sorry if I was inappropriately harsh, I think I may not yet have enough merits around here to go that far.
But HTH anyway. Please keep me informed about whether the Wikipedia article was of any use to you.
-
July 9th, 2010, 03:34 AM
#3
Re: MPLab PIC Microchip / Version of Assembly Question
Yeah as eri mentioned, it's not really looking good so far. movlw is just about the only bit of the instruction set for PICs I saw in your code. you may want to check out http://www.gooligum.com.au/tutorials.html and http://www.winpicprog.co.uk/pic_tutorial.htm both got some great tutorials for beginners.... goes through everything from setting up ports as input/output to using USART and PWM...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|