|
|
View previous topic :: View next topic |
Author |
Message |
gai_man_de
Joined: 18 Apr 2010 Posts: 1
|
Help in inserting ASM code into C code |
Posted: Sun Apr 18, 2010 6:13 am |
|
|
I'm trying to insert assembly code into C code in CCS that make LEDs blink 3 times. But there are 2 errors:
1. Expecting an opcode mnemoric Delay100ms;
2. Undefined label that use in a GOTO > main1
Can anyone help me to fix it?
Code: |
#include <16f877a.h>
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP
#use delay(clock=4000000)
int temp=3;
int delay_reg1;
int delay_reg2;
void main()
{
#asm
goto main1
Delay100ms
MOVLW 0x83
MOVWF delay_reg1
MOVLW 0xFF
MOVWF delay_reg2
loop1
DECFSZ delay_reg1
GOTO loop2
GOTO exit
loop2
DECFSZ delay_reg2
GOTO loop2
GOTO loop1
Exit
RETURN
main1
banksel TRISB
clrf TRISB
banksel PORTB
loop
clrf PORTB
call Delay100ms
movlw 0xff
movwf PORTB
call Delay100ms
decfsz temp,f
goto loop
#endasm
while(1);
}
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Apr 18, 2010 7:37 am |
|
|
Obvious error: labels should end with a ':' character. For example 'loop1' should be changed to 'loop1:'
But why would you use a C-compiler to write assembly? You are using the wrong tool for the job. Assembly is old and out of fashion, but if you need to use it then use the free Microchip Assembler which has much better support for writing assembly.
Still, writing your program in C gets you a working program faster, with less effort and easier to maintain. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|