This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Code working in uVision 2 but not in hardware...!

Hello, being new to this, i'm not totally sure I'm not doing something silly wrong. Below are two 'C' files, one which works in the target hardware and another which does not. I am using an Atmel AT89S8252. All code compiles fine and seems to run well on the simulator. The code just initialises an LCD, and writes some characters to it. The only difference between the two programs is that one puts the LCD initialisation in a function called from main()and the working one just does it all in main(). Why will this not work? Any help is welcomed. I use alot more function calls in my project, but am equally unable to get that work aswell. Code follows:

Working code:

#include <AT898252.H>
#include <stdio.h>

void Delay(void);
void Data_Write(void);
void Initialise(void);

sbit RS = P2^0;		//
sbit R_W = P2^1;	// Set LCD controls
sbit Enable = P2^2;	//

main()
{
TMOD=0x12;		// Timer 1 is set for mode 1 operation
P0=0x00;		// Make P1 output for LCD data
RS=0;			//
R_W=0;			// RS, R/W, E = Outputs
Enable=0;		//


Delay();		// 8 bit mode, 2 line, 5x8 character
P0=0x38;
Data_Write();

Delay();		// Display ON, Cursor OFF, Blink OFF
P0=0x0C;
Data_Write();

Delay();		// Clear display and return to home
P0=0x01;
Data_Write();

Delay();		// Increment at write and shift cursor to right
P0=0x06;
Data_Write();

Delay();		// Set position to line 1 pos 6
P0=0x86;
Data_Write();

RS=1;
Delay();		// Write H to LCD
P0='H';
Data_Write();

Delay();		// Write M to LCD
P0='M';
Data_Write();

Delay();		// Write E to LCD
P0='E';
Data_Write();

Delay();		// Write ' ' to LCD
P0=' ';
Data_Write();

Delay();		// Write ' ' to LCD
P0=' ' ;
Data_Write();

Delay();		// Write M to LCD
P0='M';
Data_Write();

Delay();		// Write k to LCD
P0='k';
Data_Write();

Delay();		// Write 5 to LCD
P0='5';
Data_Write();

while (1);		// Stay here
}

void Delay(void)
{
int n;			// Delay for 6.1ms with 24MHz clock
TH0=0x00;
TR0=1;
for (n=0;n<50;n++) {
	while (!TF0);
	TF0=0;
	}
TR0=0;
}

void Data_Write(void)
{
int x=4;		// Write Data to LCD
int y=20;
while (x) x--;
Enable=1;
while (y) y--;
Enable=0;
}

Non working code:
#include <AT898252.H>
#include <stdio.h>

void Delay(void);
void Data_Write(void);
void Initialise(void);

sbit RS = P2^0;		//
sbit R_W = P2^1;	// Set LCD controls
sbit Enable = P2^2;	//

main()
{
TMOD=0x12;						// Timer 1 is set for mode 1 operation
P0=0x00;						// Make P1 output for LCD data
RS=0;							//
R_W=0;							// RS, R/W, E = Outputs
Enable=0;						//

Initialise();

while (1);
}

void Initialise(void)
{
Delay();		// 8 bit mode, 2 line, 5x8 character
P0=0x38;
Data_Write();

Delay();		// Display ON, Cursor OFF, Blink OFF
P0=0x0C;
Data_Write();

Delay();		// Clear display and return to home
P0=0x01;
Data_Write();

Delay();		// Increment at write and shift cursor to right
P0=0x06;
Data_Write();

Delay();		// Set position to line 1 pos 6
P0=0x86;
Data_Write();

RS=1;
Delay();		// Write H to LCD
P0='H';
Data_Write();

Delay();		// Write M to LCD
P0='M';
Data_Write();

Delay();		// Write E to LCD
P0='E';
Data_Write();

Delay();		// Write ' ' to LCD
P0=' ';
Data_Write();

Delay();		// Write ' ' to LCD
P0=' ' ;
Data_Write();

Delay();		// Write M to LCD
P0='M';
Data_Write();

Delay();		// Write k to LCD
P0='k';
Data_Write();

Delay();		// Write 5 to LCD
P0='5';
Data_Write();
}

void Delay(void)
{
int n;  		// Delay for 6.1ms with 24MHz clock
TH0=0x00;
TR0=1;
for (n=0;n<50;n++) {
	while (!TF0);
	TF0=0;
	}
TR0=0;
}

void Data_Write(void)
{
int x=4;		// Write Data to LCD
int y=20;
while (x) x--;
Enable=1;
while (y) y--;
Enable=0;
}

Parents
  • Thanks guys, I will look into it. I have extensively trawled the data sheets to see if what I was doing fitted in with the timings, and I have designed the code to fit in with this. Another thing that happens is that after the ports have been set up as inputs and outputs, they all go high, when the code that doesn't work is burnt into the device ( I assume it just crashes). I have it working using .asm code, but not C. I need to get the C working unless any of you have an algorithm that can do Natural Logarithms in assembler!! :o) Its for a university project... So I have about a month and a half to get it fully working... Hopefully!!!!

Reply
  • Thanks guys, I will look into it. I have extensively trawled the data sheets to see if what I was doing fitted in with the timings, and I have designed the code to fit in with this. Another thing that happens is that after the ports have been set up as inputs and outputs, they all go high, when the code that doesn't work is burnt into the device ( I assume it just crashes). I have it working using .asm code, but not C. I need to get the C working unless any of you have an algorithm that can do Natural Logarithms in assembler!! :o) Its for a university project... So I have about a month and a half to get it fully working... Hopefully!!!!

Children