blinksumgreen
July 5th, 2010, 10:54 PM
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)
;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:
; 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.
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?
Pseudo code (which I was given)
;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:
; 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.
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?