# 8051 & 8052 ??

Status
Not open for further replies.

#### tariq7868

##### New Member
Hello, i wrote a simple program to to display text on lcd in nibble mode in MikroC. The problem is when i tried this prog on AT89S52 it worked alright, but on AT89S51 it just didnt work (i.e lcd didnt initialize ;just nothing happened) .. i wrote many other simple prog and tested on both ics and all worked but display text in nibble mode isnt working in AT89S51..

#### Wond3rboy

##### Member
What is the code.Can you post it?.

#### Papabravo

##### Well-Known Member
Hello, i wrote a simple program to to display text on lcd in nibble mode in MikroC. The problem is when i tried this prog on AT89S52 it worked alright, but on AT89S51 it just didnt work (i.e lcd didnt initialize ;just nothing happened) .. i wrote many other simple prog and tested on both ics and all worked but display text in nibble mode isnt working in AT89S51..
You do realize that they are different parts with subtle differences that are nonetheless spelled out in the datasheets. Right?

When Intel made the originals there was a clear distinction between the two flavors. Atmel did not invent these things, they were always just a second source. One among many.

#### tariq7868

##### New Member
Written in 'C ' using MikroC which uses its own libraries ::

sbit LCD_RS at P2.B6;
sbit LCD_EN at P2.B7;
sbit LCD_D7 at P0.B7;
sbit LCD_D6 at P0.B6;
sbit LCD_D5 at P0.B5;
sbit LCD_D4 at P0.B4;

void main() {

lcd_init();
lcd_out(1,5," @$$.Testing 123"); } Assembly code generated:: _main: MOV 129, #128 MOV 130, #?ICSlstr1_lcd2+0 MOV 131, hi(#?ICSlstr1_lcd2+0) MOV R0, #lstr1_lcd2+0 MOV R1, #17 LCALL ___CC2D+0 ;lcd2.c,8 :: void main() { ;lcd2.c,9 :: lcd_init(); LCALL _Lcd_Init+0 ;lcd2.c,10 :: lcd_out(1,5," @$$.Testing 123");
MOV FARG_LCD_Out+0+0, #1
MOV FARG_LCD_Out+1+0, #5
MOV FARG_LCD_Out+2+0, #lstr1_lcd2+0
LCALL _LCD_Out+0
;lcd2.c,11 :: delay_ms(1000);
MOV R5, 4
MOV R6, 255
MOV R7, 255
NOP
DJNZ R7, -3
DJNZ R6, -7
DJNZ R5, -11
MOV R6, 255
MOV R7, 255
NOP
DJNZ R7, -3
DJNZ R6, -7
MOV R6, 173
MOV R7, 255
NOP
DJNZ R7, -3
DJNZ R6, -7
MOV R7, 143
NOP
DJNZ R7, -3
NOP
;lcd2.c,13 :: }
SJMP #254
; end of _main

#### johnsmith123

##### Member
Assembly code generated::
_main:
MOV 129, #128
the first line is your problem. The above line is setting up the stack pointer to an address that does not exist in the 89S51. The 89S52 has twice the ram as the 89S51.

If you select the 89S51 in your compiler then the code will work for both the 89S51 and the 89S52.

#### Papabravo

##### Well-Known Member
It would also work if you select the correct processor for each build, or as was suggested make one build that works for both.

Notice from the datasheets that the AT89S52 has peripheral devices and pin functions that are not available on the AT89S51.

Where is the call to delay_ms(1000) that shows up in the assembled output but not in the orginal C-code. Maybe a little fudging going on?

Last edited:

#### rushi53

##### Member
the first line is your problem. The above line is setting up the stack pointer to an address that does not exist in the 89S51. The 89S52 has twice the ram as the 89S51.

If you select the 89S51 in your compiler then the code will work for both the 89S51 and the 89S52.

Good catch...

Status
Not open for further replies.