PDA

View Full Version : ASM - Problem at first step!



Megahertz
- 23rd July 2011, 19:57
Hi, I am having problem in compiling the following code:

LIST P=16F676
__CONFIG H'2007', B'11000000000100'


ORG 0
GOTO 5
ORG 4
GOTO 5
ORG 5

END
The config line is causing the error. The error is the following:

Error[108] C:\D_DRIVE\ASM_LEARNING\16F676\676_ASM.ASM 2 : Illegal character (,)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\D_DRIVE\ASM_Learning\16F676\676_ASM.mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Sat Jul 23 19:48:06 2011
----------------------------------------------------------------------
BUILD FAILED


I am using MPLAB IDE V8.15. I am trying to learn ASM and this is my first shot at it.
Thanks

Bruce
- 23rd July 2011, 21:05
There are .asm template files in your MPASM directory that show basic templates for beginners.

Look in C:\Program Files\Microchip\MPASM Suite\Template\Code

For a template for the 16F676.

Megahertz
- 24th July 2011, 16:56
Thanks Bruce
Really useful information.

Megahertz
- 24th July 2011, 22:08
I am able to compile it now but it is not working. I am using Proteus 7.9 software to simulate it but :(
Is something wrong with the code?

LIST P=16F676
#include <p16F676.inc>
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT

ORG 0
GOTO 5
ORG 4
GOTO 5
ORG 5

CLRF H'07'
BSF H'03',5
CLRF H'07'
CLRF H'91'
BCF H'03',5

BSF H'07',4
BSF H'07',5
BSF H'07',2
BSF H'07',3

END

mister_e
- 25th July 2011, 01:10
couple of mistakes in there... no problem it's your first I guess ;)

You haven't cleared the TRISC register
no real need for multiple ORG and GOTO at the begining
If you want to use GOTOs, you want to use/define some label and jump to them.
It's really more readable to use register name instead of their addresses.
Make suire you're always in the good BANK when writing/writing to a registers. Datasheet show everything 'bout that
Maybe not a bad idea to retrieve the oscillator calibration at the begining.

Like Bruce said, check out your MPASM\Template\CODE folder.

Megahertz
- 25th July 2011, 10:59
couple of mistakes in there... no problem it's your first I guess ;)

You haven't cleared the TRISC register
no real need for multiple ORG and GOTO at the begining
If you want to use GOTOs, you want to use/define some label and jump to them.
It's really more readable to use register name instead of their addresses.
Make suire you're always in the good BANK when writing/writing to a registers. Datasheet show everything 'bout that
Maybe not a bad idea to retrieve the oscillator calibration at the begining.

Like Bruce said, check out your MPASM\Template\CODE folder.

Thanks. I was under the impression that the below statements clear the TRISC register.


CLRF H'07' ; clear portC
BSF H'03',5 ; Jump to bank 1
CLRF H'07' ; Clear Trisc
CLRF H'91' ; Clear ANSEL register
BCF H'03',5 ; Jump to Bank 0

Megahertz
- 25th July 2011, 13:03
Even tried this now. But :(

......
ORG 5

CLRF PORTC
BSF STATUS,RP0
CLRF TRISC
CLRF ANSEL
BCF STATUS,RP0
BSF PORTC,4
BSF PORTC,5
BSF PORTC,2
BSF PORTC,3

END

cncmachineguy
- 25th July 2011, 14:01
Compiles and works fine in MPLAB SIM. PORTC bits 4,5,2,3 all get set. Post your Protous file and we can have a look for you.

Megahertz
- 25th July 2011, 15:24
5796

My DSN file attached.

mister_e
- 26th July 2011, 14:50
I don't use ISIS/Proteus, but as per your configuration fuses, you must tie you MCLR pin to Vdd... make sure it is done.

Another thing... It's nogt a bad Idea to finish your program with an endless loop, so the LED will stay on.

I bet this will work, if you haven't tied you MCLR pin to Vdd


LIST P=16F676
#include <p16F676.inc>
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT

CLRF PORTC
BSF STATUS,RP0
CLRF TRISC
CLRF ANSEL
BCF STATUS,RP0
BSF PORTC,4
BSF PORTC,5
BSF PORTC,2
BSF PORTC,3
goto $
END

And from what I do remember of my venture with ISIS, you need to specify the osc speed... set it to 4MHz and try the above without specifying the configuration word value. If it's still not working, tie your MCLR pin to Vdd. Ought to work ... or throw away ISIS :D

cncmachineguy
- 26th July 2011, 15:12
Steve is correct You need to either turn off MCLR or tie it high. As a side note, you have some hardware issues that will make you think the program doesn't work. It has to do with tying all the LED's together then through 1 resistor to ground. Also I think you have to edit the properties for the GND symble and assign it the name "GND" to make it be ground.

I am Very new to ISIS, but that has caused me trouble in the past.

Sorry bout taking so long to reply, had trouble getting on the forum yesterday.

mister_e
- 26th July 2011, 15:18
..., had trouble getting on the forum yesterday.
Me too, and I guess everybody has too. Bah, it happen once in a while. No problem, nobody will die of it :D

Megahertz
- 26th July 2011, 21:16
Thanks for the help. I tied MCLR to VDD & named the ground terminal 'GND'. Worked fine. I almost started having suicidal thoughts becoz of this. Thanks again.

mister_e
- 27th July 2011, 00:43
I almost started having suicidal thoughts becoz of this.
Don't do that again, no SIM worth that much attention ;)