Shahzad Khan wrote:
I am a newbie with SDCC and facing a lot of problem in
a project. I am trying to glow a LED in the main
program and nothing else. But the LED doesn't behave
as desired. I am pretty sure that the problem is in
Why are you sure of that?

A common error is to connect the LED from a port pin to ground, with the intention that the LED will light when the pin is high.  This does not work, because the pin can not source much current.

The LED must be connected between the pin and Vcc, with a current limiting resistor in the range of 200 to 1000 ohms.  Disconnect the wire from your port pin and try shorting it to ground to verify that the LED really does light when the pin is driven low.

Also, connect a voltmeter to the pin and watch the actual voltage.  If the resistor is too high and its a low efficiency LED there may not be enough current to light the LED.

 Either, the linkage is not proper or their
is a memory problem (in RAM). 
Does SDCC give error in
compilation if there is a memory problem? (small
Usually you will get an error, but not always.

You did not provide the exact command you're using to run sdcc, so we can not see what options you are giving to the linker for memory mapping.  Please refer to the list of 4 recommended things to include in support requests:

Please help me as I am badly stuck.
Find the files attached.
I am using AT89C52.
The code looks like it should work, assuming you're compiling the main() in the second attached file.


Thanks in advance,

Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).

#include <8052.h> xdata at 0x800d unsigned char regd; xdata at 0x800a unsigned char rega; data unsigned char message1[16]="SHAHZAD KHAN,IIT"; data unsigned char message4[15]="Set date & time:"; data unsigned char message5[14]="Set Alarm Mode:"; data unsigned char message6[15]="Set Records Mode"; void usec_wait(unsigned char time) { time=(time*12)/11; ACC = time >> 1; _asm mov r0, a 00001$: djnz r0, 00001$ _endasm; return; } void msec_wait(unsigned char Time) { Time=(Time*12)/11; ACC = Time; _asm mov r2, a 00003$: mov r1, #0x05 00002$: mov r0, #0x64 00001$: djnz r0, 00001$ djnz r1, 00002$ djnz r2, 00003$ _endasm; return; } void sec_wait(unsigned char Time) /********************************************** ** ** This function will wait for "Time" Sec ** ***********************************************/ { Time=(Time*12)/11; ACC = Time; _asm mov r3, a 00004$: mov r2, #0x14 00003$: mov r1, #0x64 00002$: mov r0, #0xFA 00001$: djnz r0, 00001$ djnz r1, 00002$ djnz r2, 00003$ djnz r3, 00004$ _endasm; return; } void uint_to_ascii(volatile unsigned int n, volatile unsigned char *byte1, volatile unsigned char *byte2, volatile unsigned char *byte3, volatile unsigned char *byte4) { data volatile unsigned char tmp; tmp = (unsigned char)(n / (unsigned int)1000); n = n % (unsigned int)1000; *byte1 = tmp + '0'; tmp = (unsigned char)(n / (unsigned int)100); n = n % (unsigned int)100; *byte2 = tmp + '0'; tmp = (unsigned char)(n / (unsigned int)10); n = n % (unsigned int)10; *byte3 = tmp + '0'; *byte4 = n + '0'; return; } void uint_to_hexascii(volatile unsigned int n, volatile unsigned char *byte1, volatile unsigned char *byte2, volatile unsigned char *byte3, volatile unsigned char *byte4) { *byte1 = (unsigned char)(n >> 12) & 0x0F; *byte2 = (unsigned char)(n >> 8) & 0x0F ; *byte3 = (unsigned char)(n >> 4) & 0x0F; *byte4 = (unsigned char)n & 0x0F; if (( *byte1 >= 0 ) && (*byte1 <= 9)) *byte1 += '0'; else *byte1 += ( 'A'- 0x0A ); if (( *byte2 >= 0 ) && (*byte2 <= 9)) *byte2 += '0'; else *byte2 += ('A' - 0x0A ); if (( *byte3 >= 0 ) && (*byte3 <= 9)) *byte3 += '0'; else *byte3 += ( 'A' - 0x0A ); if (( *byte4 >= 0 ) && (*byte4 <= 9)) *byte4 += '0'; else *byte4 += ( 'A' - 0x0A ); return; } unsigned int hexascii_to_uint( volatile unsigned char byte1, volatile unsigned char byte2, volatile unsigned char byte3, volatile unsigned char byte4 ) { if ((byte1 >= '0') && (byte1 <= '9')) byte1 -= '0'; else byte1 -= ( 'A' - 0x0A ); if ((byte2 >= '0') && (byte2 <= '9')) byte2 -= '0'; else byte2 -= ( 'A' - 0x0A ); if ((byte3 >= '0') && (byte3 <= '9')) byte3 -= '0'; else byte3 -= ( 'A' - 0x0A ); if ((byte4 >= '0') && (byte4 <= '9')) byte4 -= '0'; else byte4 -= ( 'A' - 0x0A ); return (((unsigned int)byte1 << 12) | ((unsigned int)byte2 << 8) | ((unsigned int)byte3 << 4) | ((unsigned int)byte4)); } void write_lcd_instr(data unsigned char instr) { P1_4=0; //for writing instruction P1_5=0; //write enable P1_6=0; //deactivate enable P0=instr; P1_6=1; usec_wait(200); //small delay for bus to settle P1_6=0; //instruction is strobbed now msec_wait(10); //wait for 5 msec for time taken to execute return; } void write_lcd_data( data unsigned char lcd_data) { P1_4=1; //for wrting data P1_5=0; //write enable P1_6=0; //deactivate enable P0=lcd_data; P1_6=1; //activate enable usec_wait(200); //small delay for bus to settle P1_6=0; //data is strobbed now msec_wait(5); //5 ms wait for data to be executed return; } void clear_lcd(void) { write_lcd_instr(0x01); //clear lcd and home cursor write_lcd_instr(0x06); //incr cursor and no display shift return; } void init_lcd(void) { write_lcd_instr(0x30); // 8 bit interface write_lcd_instr(0x38); // 2 line display write_lcd_instr(0x0f); //display on,cursor on,blink cursor clear_lcd(); return; } void rom_display (data unsigned char arry[],data int j) { data int i; data unsigned char lcd_loc=0x7f; for (i=0;i<j;i++) { write_lcd_instr(lcd_loc++); write_lcd_data(arry[i]); sec_wait(1); } return; } void blink(data unsigned int sign_on) { data int i; for (i=0;i<sign_on;i++) { write_lcd_instr(0x08); //turn off display P1_7=0; //turn off the lcd msec_wait(20); write_lcd_instr(0x0c); //turn display on P1_7=1; //turn on the lcd msec_wait(20); } return; } void check_batt(void) { data volatile unsigned char message2[17]="NO LITHIUM BATTERY"; data int j=128; regd=regd & 128; if (regd==1) return; else { while(1) { clear_lcd(); rom_display(message2,17); blink(1); } } return; } void led_on(void) { P1_7=1; msec_wait(50); return; } void led_off(void) { P1_7=0; msec_wait(50); return; } void bcd2ascii(unsigned char number,unsigned char *num1,unsigned char *num2) { unsigned char temp; temp=number; number=number & 0x0f; number=number | 0x30; num1=number; number=temp; number=number & 0xf0; number=number | 0x30; num2=number; return; } unsigned char get_key(void) { unsigned char trigpin; unsigned char temp; temp=P1 & 0xff; //mask out the first nibble while (temp==0xff) temp=temp & 0x0f; //do nothing if no switched pressed while (temp != 0xff){ led_on(); temp=temp & 0xff;//glow led,remain in loop if no debounce trigpin=temp; } //P1=P1 & 0x0f; if (temp==0xff) // P1=P1 & 0x0f; //if debounce,turn off the led led_off(); led_on(); //turn on to acknowledge return (trigpin); } void show_clock(unsigned char num) { unsigned char a,b; bcd2ascii(num,&a,&b); write_lcd_data(a); write_lcd_data(b); return; } void show_time(void) { xdata unsigned char * data ptr = 0x8009; unsigned char chr,ch1,ch2; write_lcd_instr(0x80); //set ddram address to zero led_on(); rega=rega & 0x80; while (!rega); //wait for update in progress while (rega);//for busy flag chr=*ptr; bcd2ascii(chr,&ch1,&ch2); write_lcd_data(ch1); write_lcd_data(0x2d);//write a dash ptr=ptr--; show_clock(*ptr); //year write_lcd_data(0x2d); //write a dash ptr=ptr--; show_clock(*ptr); //month write_lcd_data(0x20); //write a space ptr=ptr-3; show_clock(*ptr); //hour write_lcd_data(0x3a); //write a colon ptr=ptr-2; show_clock(*ptr);//minute write_lcd_data(0x3a); //write a colon ptr=ptr-2; show_clock(*ptr); //second return; } void set_clock(void) { xdata unsigned char * data ptr = 0x800b; *ptr=0x8a; //enable set time,sqr wave,bcd mode,disbale interrupr ptr=ptr--; //0x800a *ptr=0x6f; //start counter,oscillator ptr=ptr--; //8000 *ptr=0x00; ptr=ptr+2; *ptr=0x00; //minutes ptr=ptr+2; *ptr=0x00; //hour ptr=ptr+2; *ptr=0x01; //sunday ptr=ptr++; *ptr=0x00; //date ptr=ptr++; *ptr=0x00;//month ptr=ptr++; *ptr=0x00; //year ptr=0x800b; *ptr=0x0a; //disable set time,retain sqr wave ptr--; *ptr=0x3f; //start oscillator clear_lcd(); show_time(); } int get_set(xdata unsigned char * data ptr,bit LSB) { unsigned char PressedKey; unsigned char a,b; while((PressedKey=get_key()) = 0xf5) { if (PressedKey==0xf7) { if (LSB) {(*ptr)--;} else {(*ptr)=(*ptr)-0x0f;} if (LSB){if ((*ptr & 0x0f)==0x0f) *ptr=0x09;} else {if ((*ptr & 0xf0)==0xf0) *ptr=0x90;} bcd2ascii(*ptr,&a,&b); if (LSB){write_lcd_data(b);} else {write_lcd_data(a);} } if (PressedKey==0xfd) { (*ptr)++; if ((*ptr & 0x0f)==0x0a) *ptr=0x00; bcd2ascii(*ptr,&a,&b); write_lcd_data(b); } if(PressedKey== 0xfe) { return(1); } if (PressedKey==0xfb) { return(0); } } } void set_time(void) { set_clock(); write_lcd_instr(0x0e); //cursor on write_lcd_instr(0x80); //1st lcd location for year if (get_set(0x8009,1)==1) return; write_lcd_instr(0x82); if (get_set(0x8008,0)==1) return; //msb for month write_lcd_instr(0x83); if (get_set(0x8008,1)==1) return; //lsb for month write_lcd_instr(0x85); if(get_set(0x8007,0)==1) return; //msb for day of month write_lcd_instr(0x86); if(get_set(0x8007,1)==1) return; //lsb for day of month write_lcd_instr(0x88); if(get_set(0x8004,0)==1) return; //msb for hour write_lcd_instr(0x89); if(get_set(0x8004,1)==1) return; //lsb for hour write_lcd_instr(0x8b); if(get_set(0x8002,0)==1) return; //msb for minute write_lcd_instr(0x8c); if(get_set(0x8002,1)==1) return; //lsb for minute write_lcd_instr(0x8e); if(get_set(0x8000,0)==1) return; //msb for second write_lcd_instr(0x8f); if(get_set(0x8000,1)==1) return; //lsb for second return; } void input_0(void) { loop: show_time(); //display time while (P1_0=1) //show time after debounce { show_time(); } led_on(); //glow after after triggering led_off(); //acknowledge the trigerring //led blinks for false trigerring if (P1_0==1) goto loop; //go to loop for false trigerring clear_lcd(); return; } void input_1(void) { clear_lcd(); rom_display(message4,14); blink(10); set_time(); return; } void input_2(void) { clear_lcd(); rom_display(message5,14); blink(10); return; } void input_3(void) { clear_lcd(); rom_display(message6,15); blink(10); return; }

#include <8052.h> #include "generic.c" void main (void) { P1_7=0; sec_wait(2); P1_7=1; sec_wait(2); P1_7=0; sec_wait(2); P1_7=1; return; }