The code given below with the date from 2013 in the constant string was complied and exectued correctly in Februar 2013. SAB80C535 and LCD Modul in eight Bit Modus.
Today with the changed date for next year the code was compiled and linked witout any error message but does no longer execute properly on the hardware. Either the the display is not initialzied or the float value is not written to the dispaly or the float value is zero.
If the float operations are deleted, the remaining programm is executed properly.
If only sqrt is computed and written to the string, the string is correctly written to the display. All other char strings and their LCD operations deleted.
Compiling is in Large Code and Large Memory Model. Compiler is the same as in February. The SAB 80C535 has 56k external RAM. Hardware the same as before.
No clue what has happend since February. The project is unaltered in folders, projectfile and so on, except for the content of the one constant string with the date. And the length of the string is 19 characters plus /n as before.
#include <reg515.h> #include <lcd.h> #include <math.h> #include <stdio.h> void main(void) { char select; float x; xdata char zeile1[20] = "Berufskolleg Hilden"; xdata char zeile2[20] = " 15. November 2014 "; xdata char zeile3[20] = " Kreis Mettmann "; xdata char zeile4[20] = " IT-Abteilung "; xdata char zeile5[20] = " Mikrocontroller "; xdata char zeile6[20] = " Digitaltechnik "; xdata char zeile7[20] = " Schlüsselverfahren"; xdata char zeile8[20] = " "; init(1,1,0); display_on_off(1,1,0); entry(1,0); home(); clrscr(); lcdadr(0); datschreib(zeile1); lcdadr(63); datschreib(zeile2); lcdadr(20); datschreib(zeile3); x = sqrt(2.0); printf(zeile8 , "%14.6f" , x); do { switch(select % 5) { case 0 : { lcdadr(84); datschreib(zeile4); warte(2000); break; } case 1 : { lcdadr(84); datschreib(zeile5); warte(2000); break; } case 2 : { lcdadr(84); datschreib(zeile6); warte(2000); break; } case 3 : { lcdadr(84); datschreib(zeile7); warte(2000); break; } case 4 : { lcdadr(84); datschreib(zeile8); warte(2000); break; } } select++; }while(1); }
Inhalt von lcd.h
void warte (unsigned int zeit); void init(bit D, bit N, bit F); void clrscr(void); void home(void); void entry(bit ID, bit S); void display_on_off(bit D, bit C, bit B); void datschreib(char *z); void lcdadr(char a7);
So perhaps you should look carefully at your xdata implementation - again, timing would be prime suspect...
Is the LCD connected to the data/address bus...?
Oscillatorfrequency is 12 MHz. Chosen in order to have 1 machine cycle = 1 microsecond.
The LCD is connected to Port P4. DB0 of LCD at P4.0 and DB7 of LCD to P4.7.
I have a second version, where idata for the constant strings idata is changed to code. That wokrs too, but is a bit slower due to the code memory access.
There is sometime something wrong with strings and memory access and the optimization. There have been displays of characters belonging to different strings. But xdata should cause lesser problems due to more xdata than idata.
There is no extern access ot P0 and P2. That can only be done by changing the original layout of the hps teaching system. And that is not an option.
The wait function is not state of the art but works. May be I change that to timing with timer 0.
The LCD is busy while DB7 is zero. The manual says while 1, but that is wrong. Between EN = 1 and EN = 0 the dummy++ causing a delay of 1 microsecond is necessary. Without the delay, the timing is out of order.
#include<reg515c.h> #define LCD P4 sbit RS = P3^3; sbit RW = P3^4; sbit EN = P3^5; sbit LCD0 = P4^0; sbit LCD1 = P4^1; sbit LCD2 = P4^2; sbit LCD3 = P4^3; sbit LCD4 = P4^4; sbit LCD5 = P4^5; sbit LCD6 = P4^6; sbit LCD7 = P4^7; char dummy = 0x00; void warte (unsigned int zeit) //Zeit wird in Millisekunden übergeben { // bei fosz 12 MHz unsigned int i, j; for (i=0; i < zeit; i++) { for (j=0; j<55; j++) {;} } } void init(bit D, bit N, bit F) { char i; // LCD Port für die Datenbits // RS, RW, EN Portleitungen für Steuerbits // RS RW D7 D6 D5 D4 D3 D2 D1 D0 // 0 0 0 1 1 D N F x x Function Set // D = 1 Display on, D = Display off // N = 1 5 x 8 Punkte zweizeilig // N = 0, F = 0 5 x 8 Punkte einzeilig // N = 0, F = 1 5 x 10 Punkte einzeilig RS = 0; // Steuerleitungen auf Befehle zum Display schreiben RW = 0; LCD = 0x30; // 0x30 Function set LCD4 = D; LCD3 = N; LCD2 = F; LCD1 = 0; LCD0 = 0; for(i = 3; i > 0; i-- ) { EN = 1; dummy++; EN = 0; warte(20); // 20 ms warten } } void clrscr(void) { // Display mit Leerzeichen überschreiben und Cursor an Anfang Zeile 1, Spalte 1 RS = 0; // Steuerleitungen auf Befehle zum Display schreiben RW = 0; LCD = 0x01; EN = 1; dummy++; EN = 0; warte(20); // 20 ms warten } void home(void) { // Cursor zurück in Zeile 1 Spalte 1, Displayinhalt nicht gelöscht RS = 0; // Steuerleitungen auf Befehle zum Display schreiben RW = 0; LCD = 0x02; EN = 1; dummy++; EN = 0; warte(20); // 20 ms warten } void entry(bit ID, bit S) { // Displayadresse incrementieren RS = 0; // Steuerleitungen auf Befehle zum Display schreiben RW = 0; LCD = 0x04; LCD1 = ID; // ID = 1 Inkrementieren, 0 Dekrementieren LCD0 = S; // S = 1 Display Shift, ID = 1 Linksshift, ID = 0 Rechtsshift EN = 1; dummy++; EN = 0; warte(20); // 20 ms warten } void display_on_off(bit D, bit C, bit B) { // Cursor zurück in Zeiel 1 Spalte 1, Displayinhalt nicht gelöscht RS = 0; // Steuerleitungen auf Befehle zum Display schreiben RW = 0; LCD = 0x08; LCD2 = D; // D = 1 Dislay on, D = 0 Display off LCD1 = C; // C = 1 Cursor on, C = 0 Cursor off LCD0 = B; // B = 1 Blink on, B = 0 blink off EN = 1; dummy++; EN = 0; warte(20); // 20 ms warten } void datschreib(char *z) { char i; RW = 0; RS = 1; for(i = 0; z[i] != '\0'; i++) { LCD = z[i]; EN = 1; dummy++; EN = 0; dummy++; LCD = 0xFF; do { RW = 1; RS = 0; EN = 1; dummy++; EN = 0; dummy++; }while(LCD7 == 0); RW = 0; RS = 1; } } void lcdadr(char a7) { // Zeile 1 Anfangsadresse 00H = 0 dezimal // Zeile 2 Anfangsadresse 40H = 64 dezimal // Adresse 7 Bit => 128 Speicherplätze RS = 0; RW = 0; LCD = a7 | 128; EN = 1; dummy++; EN = 0; LCD = 0xFF; do { RW = 1; RS = 0; EN = 1; dummy++; EN = 0; dummy++; }while(LCD7 == 0); }