Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

include asm in keil c51

Status
Not open for further replies.

Chetan07

Newbie level 5
Joined
Apr 25, 2006
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,358
keil asm

dear all
i am having a code written for eeprom (24cxx) in assembly language for 8051 . i want to include it with my other program which is written in c languague using keil c51 . i mean i want to include asm file in c ,how to do it?

any reply will be helpful
 

keil c asm

You can embed assembly code within c code like this.
c code;
c code;
.
.

#pragma asm

assembly code
assembly code
.
.
#pragma endasm
c code;
c code;
Please right click the c file shown on the source group shown on left side, and go for the options for file xxx.c . Please make Generate Assembler SRC File and Assemble SRC File enabled (both are ticked). Add c51ms.lib in the source group. I think you can add some other lib files also.And you are done.

Include the appropriate library files in the source group.
C51S.LIB: Small model library without floating-point math.
C51C.LIB: Compact model library without floating-point math.
C51L.LIB: Large model library without floating-point math.
C51FPS.LIB: Small model library with floating-point math.
C51FPC.LIB: Compact model library with floating-point math.
C51FPL.LIB: Large model library with floating-point math.
 

keil c assembly

With Keil C51 an easy way to include asm is to create a separate c module with a dummy function that takes parameters you wish to pass to the assembler code and whatever you wish to return. Set the compiler option to generate asm source as an output. Now you have a template in asm in which you can write your asm. Just include this file as part of your project and that is all there is to it. Just by the way, Keil does very eficient code, most likely better than most asm coders can do. I have used it for about 8 years and find that you can do every thing in c without having to use asm.
 

asm in keil

How to set the compiler option ?.Sorry if it fells silly question to you.
 

keil #pragma asm

I need robotic books
 

c51fpl.lib

use the editor & include the asm code in the present c code if u want to load this code with the flash there in no problem as it will go as a hex file

hi friend a introductory book on robotics
 
  • Like
Reactions: js

    js

    Points: 2
    Helpful Answer Positive Rating
asm keil

to set the option depends if you are running it from command line our uMicrovision. The compile control is SRC. Your command line will look something like this: C51.EXE Test.c BROWSE SRC DEBUG OBJECTEXTEND. If you use umicrovision you set it under options for your project, goto C51 tab, and type SRC in the 'Misc Controls' edit box
 

c51 asm

nice book on robots..

Regards,
PARTHA
 

how to include assembler in keil

/*********************定义调节阀结束*****************************/
/*********************定义24C04开始*****************************/
#define WR 0xa0
#define RD 0xa1
/* 常,变量定义区 */
uchar Byte_[8]; /*端口位定义*/
sbit SDA=P1^3; /*模拟I2C数据传送位*/
sbit SCL=P1^2; /*模拟I2C时钟控制位*/
bit CSI24C021RWBYTE(uchar *Byte_,uchar BCount,uchar Address,uchar rw);
/****************************定义24C04结束******************************/

//———————START——I2C—————————————————
/*————————————————————————————————
调用方式:void I2CWait(void)
函数说明:私有函数,I2C专用 2002-08-15
————————————————————————————————*/
void I2CWait(void)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
}
/*———————————————————————————————
方式:void I2CStart(void)
函数说明:私有函数,I2C专用 2002-08-15
————————————————————————————————*/
void I2CStart(void)
{
SDA=1; SCL=1; I2CWait();
SDA=0; I2CWait();
SCL=0;
}
/*————————————————————————————————
调用方式:void I2CStop(void)
函数说明:私有函数,I2C专用 2002-08-15
————————————————————————————————*/
void I2CStop(void)
{
SCL=0;SDA=0;I2CWait();//INT
SCL=1;I2CWait();SDA=1;//STOP
}
/*————————————————————————————————
调用方式:bit WaitAck(void)
函数说明:私有函数,I2C专用,等待从器件接收方的应答 2002-08-15
————————————————————————————————*/
bit WaitAck(void)
{
uchar errtime=255;//因故障接收方无ACK,超时值为255。
SDA=1;I2CWait();
SCL=1;I2CWait();
while(SDA){errtime--;if(!errtime){I2CStop();return false;}}
SCL=0;
return true;
}
/* ————————————————————————————————
调用方式:void SendAck(void) 2002-08-15
函数说明:私有函数,I2C专用,主器件为接收方,从器件为发送方时,应答信号
————————————————————————————————*/
void SendAck(void)
{
SDA=0;I2CWait();
SCL=1;I2CWait();
SCL=0;
}
/* ————————————————————————————————
调用方式:void SendNoAck(void) 2002-08-15
函数说明:私有函数,I2C专用,主器件为接收方,从器件为发送方时,非应答信号
————————————————————————————————*/
void SendNoAck(void)
{
SDA=1;I2CWait();
SCL=1;I2CWait();
SCL=0;
}
/* ————————————————————————————————
调用方式:void I2CSend(uchar ch,uchar H_L)
函数说明:私有函数,I2C专用
————————————————————————————————*/
void I2CSendByte(uchar ch,uchar H_L)
{
uchar i=8;
while(i--)
{
SCL=0;_nop_();
if (H_L==1)
{ SDA=(bit)(ch&0x80);ch<<=1;}//从高到低MSB->LSB
else
{ SDA=(bit)(ch&0x01);ch>>=1;};//从低到高LSB->MSB
I2CWait();
SCL=1;I2CWait();
}
SCL=0;
}
/* ————————————————————————————————
调用方式:void I2CReceive(uchar H_L)
函数说明:私有函数,I2C专用
————————————————————————————————*/
uchar I2CReceiveByte(uchar H_L)
{
uchar i;//=8;
uchar ddata=0;
uchar ddata1=0;
SDA=1;
for(i=0;i<=7;i++)
{
if (H_L==1){ddata<<=1;};
SCL=0;I2CWait();
SCL=1;I2CWait();
ddata1=0;
ddata1|=SDA;
if (H_L!=1){ddata1<<=i;};
ddata|=ddata1;
}
SCL=0;
return ddata;
}
bit CSI24C021RWBYTE(uchar *Byte_,uchar BCount,uchar Address,uchar rw) //读写csi24c021
{
uchar i;
i=0x0A0;
I2CStart();
I2CSendByte(i,1); //写入控制字(SLAVE地址)
if(!WaitAck())return 1; //写入控制字失败重来
I2CSendByte(Address,1); //地址低8位
if(!WaitAck())return 1;
switch(rw)
{
case 1: //WRITE
for(i=0;i<BCount;i++)
{
I2CSendByte(Byte_,1);
if(!WaitAck())return 1;
}
break;
case 0: //READ
I2CStart(); //再次启动I2C
I2CSendByte(i+1,1);//写入控制字,传送OxA1的地址,即“读出的SLAVE地址
if(!WaitAck()) return 1;
for(i=0;i<BCount;i++)
{
Byte_=I2CReceiveByte(1);
if(i!=BCount-1){SendAck();}
}
SendNoAck();
}
I2CStop();
I2CWait();
return 0;
}
 

how to execute a asm program keil

Hi People........
I am writting an application in C.In this application I have include some assembly instructions(for manupulating the stack).I tried this including the asm code in between the #pragma directives.
#pragma asm

ASM code
#pragma endasm
When I am compiling this code( keil compiler u2),its getting compiled and generating the hex file sucessfully without any errors and warnings.But when run this through the simulator(KEIL simultor) the control is transferring to NOP location(I mean it not working or running).
I have included
C51S.LIB: Small model library without floating-point math.
C51C.LIB: Compact model library without floating-point math.
C51L.LIB: Large model library without floating-point math.
C51FPS.LIB: Small model library with floating-point math.
C51FPC.LIB: Compact model library with floating-point math.
C51FPL.LIB: Large model library with floating-point math.
to the source group and Generate Assembler SRC File and Assemble SRC File enabled (both are ticked).
So, please suggest something.Because of the I am strucking and cant implement my ideas further.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top