Hello, I have the problem that I have a program that works on the AT89C51, but not on the AT89S51. A simple program (blink.c) works on both MC. AT89C51 with #include <at89c51RC2.h> AT89S51 with #include <at89x52.h> Compiler = Keil C version 9.60.7.0The program for AT89S51#include <at89x52.h> #include <stdio.h> #include <stdlib.h> #include <absacc.h> #include <float.h> #include <string.h> #define LCD_ADR XBYTE[0xF800] // Basisadresse : Daten in das Befehlsregister // schreiben #define LCD_ADR1 XBYTE[0xF801] // Basisadresse +1: Daten in das Datenregister // schreiben #define LCD_ADR2 XBYTE[0xF802] // Basisadresse +2: Inhalt des Befehlsregister // lesen #define LCD_ADR3 XBYTE[0xF803] // Basisadresse +3: Inhalt des Datenregister // lesen //#define LCD_ADR *((unsigned char volatile xdata*)0xF800) //#define LCD_ADR1 *((unsigned char volatile xdata*)0xF801) //#define LCD_ADR2 *((unsigned char volatile xdata*)0xF802) //#define LCD_ADR3 *((unsigned char volatile xdata*)0xF803) #define LCD_INI1 0x01 // Clear Display #define LCD_INI2 0x02 // Cursor Home #define LCD_INI3 0x06 // Entry Mode Set 06 #define LCD_INI4 0x0F // Display On, Cursor blink #define LCD_INI5 0x14 // Cursor/Display Shift 14 #define LCD_INI6 0x38 // Funktion Set #define ADDR1 0x80 // Cursoradresse Zeichen 0-7 #define ADDR2 0xC0 // Cursoradresse Zeichen 8-15 #define CURSOR_FLASH 0x0F // Cursor blink sbit P10 = P1^0; sbit P14 = P1^4; unsigned char code string1[]="******TEST******"; void lcd_init(void); void lcd_clear(void); void lcd_addr1(void); void lcd_addr2(void); void lcd_sendstring(unsigned char[]); void lcd_out_char(unsigned char); void delay(int); //sub routine for delay void delay_init(void); void main() { P10 = 0; P14 = 0; lcd_init(); delay_init(); lcd_sendstring(string1); // delay(10000); lcd_clear(); delay(10000); } void delay(int value ) //Delay Function { int i,j; for(i=0;i<=value;i++) for(j=0;j<=5;j++); } void delay_init() { int i; for(i=0;i<=1000;i++); //software delay } void lcd_init() { LCD_ADR = 0x38; delay_init(); LCD_ADR = 0x38; delay_init(); LCD_ADR = 0x38; delay_init(); LCD_ADR = 0x0C; delay_init(); LCD_ADR = 0x01; delay_init(); LCD_ADR = 0x02; delay_init(); } void lcd_clear() { LCD_ADR = LCD_INI1; delay_init(); LCD_ADR = LCD_INI2; delay_init(); } void lcd_sendstring(unsigned char text[]) { unsigned char b; int i = 0, l = 0; l = 16; //lcd_addr1(); for(i = 0; i <= l; i++) { if(i < 8) { b = text[i]; lcd_out_char(b); LCD_ADR = ADDR1+i+1; } if(i == 8) lcd_addr2(); if(i > 8 && i < 17) { b = text[i-1]; lcd_out_char(b); LCD_ADR = ADDR2+i-8; } } } void lcd_out_char(unsigned char letter) { LCD_ADR1 = letter; delay_init(); } // Cursor auf Zeichen 0 setzen void lcd_addr1() { LCD_ADR = ADDR1; delay_init(); } // Cursor auf Zeichen 8 setzen void lcd_addr2() { LCD_ADR = ADDR2; delay_init(); }
#include <at89x52.h> #include <stdio.h> #include <stdlib.h> #include <absacc.h> #include <float.h> #include <string.h> #define LCD_ADR XBYTE[0xF800] // Basisadresse : Daten in das Befehlsregister // schreiben #define LCD_ADR1 XBYTE[0xF801] // Basisadresse +1: Daten in das Datenregister // schreiben #define LCD_ADR2 XBYTE[0xF802] // Basisadresse +2: Inhalt des Befehlsregister // lesen #define LCD_ADR3 XBYTE[0xF803] // Basisadresse +3: Inhalt des Datenregister // lesen //#define LCD_ADR *((unsigned char volatile xdata*)0xF800) //#define LCD_ADR1 *((unsigned char volatile xdata*)0xF801) //#define LCD_ADR2 *((unsigned char volatile xdata*)0xF802) //#define LCD_ADR3 *((unsigned char volatile xdata*)0xF803) #define LCD_INI1 0x01 // Clear Display #define LCD_INI2 0x02 // Cursor Home #define LCD_INI3 0x06 // Entry Mode Set 06 #define LCD_INI4 0x0F // Display On, Cursor blink #define LCD_INI5 0x14 // Cursor/Display Shift 14 #define LCD_INI6 0x38 // Funktion Set #define ADDR1 0x80 // Cursoradresse Zeichen 0-7 #define ADDR2 0xC0 // Cursoradresse Zeichen 8-15 #define CURSOR_FLASH 0x0F // Cursor blink sbit P10 = P1^0; sbit P14 = P1^4; unsigned char code string1[]="******TEST******"; void lcd_init(void); void lcd_clear(void); void lcd_addr1(void); void lcd_addr2(void); void lcd_sendstring(unsigned char[]); void lcd_out_char(unsigned char); void delay(int); //sub routine for delay void delay_init(void); void main() { P10 = 0; P14 = 0; lcd_init(); delay_init(); lcd_sendstring(string1); // delay(10000); lcd_clear(); delay(10000); } void delay(int value ) //Delay Function { int i,j; for(i=0;i<=value;i++) for(j=0;j<=5;j++); } void delay_init() { int i; for(i=0;i<=1000;i++); //software delay } void lcd_init() { LCD_ADR = 0x38; delay_init(); LCD_ADR = 0x38; delay_init(); LCD_ADR = 0x38; delay_init(); LCD_ADR = 0x0C; delay_init(); LCD_ADR = 0x01; delay_init(); LCD_ADR = 0x02; delay_init(); } void lcd_clear() { LCD_ADR = LCD_INI1; delay_init(); LCD_ADR = LCD_INI2; delay_init(); } void lcd_sendstring(unsigned char text[]) { unsigned char b; int i = 0, l = 0; l = 16; //lcd_addr1(); for(i = 0; i <= l; i++) { if(i < 8) { b = text[i]; lcd_out_char(b); LCD_ADR = ADDR1+i+1; } if(i == 8) lcd_addr2(); if(i > 8 && i < 17) { b = text[i-1]; lcd_out_char(b); LCD_ADR = ADDR2+i-8; } } } void lcd_out_char(unsigned char letter) { LCD_ADR1 = letter; delay_init(); } // Cursor auf Zeichen 0 setzen void lcd_addr1() { LCD_ADR = ADDR1; delay_init(); } // Cursor auf Zeichen 8 setzen void lcd_addr2() { LCD_ADR = ADDR2; delay_init(); }
I solved the problem: Difference between AT89S51 and AT89S51 AT89C51: EA/VPP pin = 5 volts AT89S51: EA/VPP pin = 12 volts Found in:
https://microchip.my.site.com/s/article/Migration-from-AT89S52-to-AT89C51RD2
Kind regards
Juergen