Continue to Site

Welcome to

Welcome to our site! 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.

89c2051...a lookuptable in sdccC or keilC

Not open for further replies.


Newbie level 4
Jul 5, 2004
Reaction score
Trophy points
Activity points
.. 89c2051 has 2k code mem (onchip rom)

i want ,say a sin() lookuptable of 0xff height..

1)code unsigned char sintable[0x100]; //doesnt work says' u cant modify lvalue
2)tried xdata in place of it compiles fine.. but it is meaningless though..
(or leave aside sin() ,something arr=0xf1; in a loop shud show me something in the hex file.. nothing showsup)
3)why can't i write to code.... if i can do that in asm. with "db BYTE";

any #pragma directive can help?

even sdcc didnt help.. can some1 help me clear these things...

i used:
in Keil->targetOptions->use 0-0x07ff selected + small model, etc etc
sdcc -> default(small model)

try code const unsigned char sintable[0x100]; //doesnt work says' u cant modify lvalue

Problem is that you can not write to code so you have to initialize your array at compile time and can not modify it later ...

best regards

IMHO, "code const unsigned char sintable[0x100]" does not help you at all (but it is more appropriate C style for segment CODE) if you have "wrong intention of using the sintable[]". The problem is not in this line as long as you would try to do for example "something = sintable[0x01];" only. Your problem is, that in your code is line like "sintable[0x01] = something;".
You CAN NOT modify the 2k code mem (onchip rom) by a software itself. This is the basic rule for '51 architecture (it is not Intel x86 or so called Neumann architecture in general. (Sorry, if I am wrong with its name, but I am not an expert in the CPU theory.)
So, if you would like to create the lookup table, you need to forget to modify any sintable[] member, and you can only to read out its values. Whole sintable[] have to be initialized in the code as:
code const char sintable [0x100] = {
/* 256 values for initialisation of an array: 0x00, ... */
} // sintable[]

Of course, somebody could point out some '51 chips (Cygnals for example) which allows you to modify "code segment" by the software itself, but I would treat them as an exception to the general rule about character of code segment, because to be able to modify code inside these microprocessors requires some extra programming and it is "advanced technique".

Not open for further replies.

Part and Inventory Search

Welcome to