THIS POST IS ALL ABOUT HOW TO CALL AN ASSEMBLY ROUTINE FROM C SOURCE CODE
I PRESENT A EXAMPLE BELOW
THERE IS THREE FILES
1) DELAYS.ASM
2)DELAY_MAIN.C
3)DELAY_HEADER.H
DELAYS.ASM
------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
DELAY_MAIN.C
---------------------------------------------------------------------------------------------------------------
/**
*THIS IS A C SOURCE CODE FROM WHERE ASSEMBLY ROUTINES ARE CALLED
*FILE NAME: DELAY_MAIN.C
*
*/
---------------------------------------------------------------------------------------------------------------
DELAY_HEADER.H
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
THE HOLE EXAMPLE PROJECT YOU CAN DOWNLOAD FROM HERE
DOWNLOAD HERE
I PRESENT A EXAMPLE BELOW
THERE IS THREE FILES
1) DELAYS.ASM
2)DELAY_MAIN.C
3)DELAY_HEADER.H
DELAYS.ASM
------------------------------------------------------------------------------------------------------------
;;
;THIS IS A ASSEMBLY LANGUAGE ROUTINES WHICH GENERATING
; 1MILI SEC,500MILI SEC
;AND 1SEC ROUTINES.
;THIS ROUTINES CAN BE CALLED FROM C LANGUAGE USING BELOW FORMATS
;FOR 1 MILI SEC:: void delay_1_ms(void);
;FOR 500 MILI SEC:: void delay_500_ms(void);
;FOR 1 SEC:: void delay_1_sec(void);
;FILE NAME:DELAYS.ASM
;AUTHOR::RAJESH KUMAR SAHOO
;SKYPE ID:rajesh6115
;face book:www.facebook.com/rajesh6115
; ; ;
?PR?del_seg SEGMENT CODE
PUBLIC delay_1_ms
PUBLIC delay_500_ms
PUBLIC delay_1_sec
RSEG ?PR?del_seg
delay_1_ms:
MOV R7,#250
DJNZ R7,$
MOV R7,#247
DJNZ R7,$
RET
delay_500_ms:
MOV R6,#250
L1_500:
ACALL delay_1_ms
DJNZ R6,L1_500
MOV R6,#248
L2_500:
ACALL delay_1_ms
DJNZ R6,L2_500
MOV R6,#250
DJNZ R6,$
MOV R6,#247
DJNZ R6,$
NOP
NOP
RET
delay_1_sec:
MOV R5,#8
LO_SEC:
MOV R6,#124
LI_SEC:
ACALL delay_1_ms
DJNZ R6,LI_SEC
DJNZ R5,LO_SEC
MOV R5,#5
L_SEC:
ACALL delay_1_ms
DJNZ R5,L_SEC
MOV R5,#250
DJNZ R5,$
MOV R5,#237
DJNZ R5,$
RET
END
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DELAY_MAIN.C
---------------------------------------------------------------------------------------------------------------
/**
*THIS IS A C SOURCE CODE FROM WHERE ASSEMBLY ROUTINES ARE CALLED
*FILE NAME: DELAY_MAIN.C
*
*/
#include <reg51.h>
#include "delays_header.h"
void main()
{
delay_1_sec();
delay_500_ms();
delay_1_ms();
delay_1_sec();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DELAY_HEADER.H
---------------------------------------------------------------------------------------------------------------
#ifndef _delay_h_
#define _delay_h_
void delay_1_ms(void);
void delay_500_ms(void);
void delay_1_sec(void);
#endif
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
THE HOLE EXAMPLE PROJECT YOU CAN DOWNLOAD FROM HERE
DOWNLOAD HERE
No comments:
Post a Comment