Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8051, C51 programming

Status
Not open for further replies.

behrang

Newbie level 1
Joined
Sep 8, 2005
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,303
/*in this hardware configuration, port2 is connected to the rows of an 8x5 LED array and the lower 3 bits of P1
/*is connected to a 3x8 decoder which controls the 5 columns of the array. in the software, character "A" is
/*displayed on the LED array using pointer function. when the array containg the patterns of character "A" is
/*placed in DATA memory, the program works perfectly well. the Irony is that when i tried to put the patterns in
/*code memory, nonsensical results were obtained. Can anyone help me with this mess?*/
#include <REG52.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

/***********************************Global parameters***********************************/

unsigned char *DATA_POINTER;
//unsigned char ARRAY_WIDTH;
signed int start_horiz_pos;
unsigned char char_pointer;
/* first */ /* unsigned char code A[6] ={0x00,0x3F,0x50,0x90,0x50,0x3F}; */
/* second */ /*unsigned char code A[6] ={0x00,0x3F,0x50,0x90,0x50,0x3F}; */


main()

{
/***********************************functions*******************************************/
void delay (void);
void DISP (unsigned char *DATA_POINTER);
void EMERGE_FROM_LEFT (unsigned char [6]);
/************************************variables******************************************/
unsigned char A[6]; /*=(0x00,0x3F,0x50,0x90,0x50,0x3F); */
/**************************************MAIN*********************************************/

A[0]=0x00;
A[1]=0x3F;
A[2]=0x50;
A[3]=0x90;
A[4]=0x50;
A[5]=0x3F;

while(1)
{
start_horiz_pos=0;
DATA_POINTER=&A[0];
DISP(DATA_POINTER);
// char_pointer=0;
// EMERGE_FROM_LEFT(A);
}
}
/*******************************************************************************************/
void delay (void)
{
unsigned char COUNTER;

for ( COUNTER=0; COUNTER<1 ; COUNTER++)
{
TR0=0;
TF0=0;
TMOD=1;
TL0=0x3C;
TH0=0xF6;
TR0=1;
while(!TF0){}

}
}
/*******************************************************************************************/

void DISP (unsigned char *DATA_POINTER)
{
signed char position;
for( position = start_horiz_pos; position < start_horiz_pos+6; position++, DATA_POINTER++)
{
if (position >-1 && position < 6 ) /* ARRAY_WIDTH*/
{
P2=*DATA_POINTER;
P1=position-1;
delay();
}
}
}
 

Seems to be a simple problem of 8051's memory architecture.

8051 supports Von Nuemonn architecture. Both program memory and data memory can exists at the same address. I.e 0x0000 to 0xFFFF. So with 16 address lines 8051 can access 64K of RAM and 64K of ROM.

The pointer type of the DATA_POINTER in

void DISP (unsigned char *DATA_POINTER) function decl and def

should be explicitly specified to point the ROM location.

The decl is unsigned char *DATA_POINTER always points to RAM not ROM
So the function is accessing RAM instead of ROM address.

You need to use "unsigned char code * DATA_POINTER" or some thing like that (I exactly do not remember) please check the documentation to make it work. If I find exact syntax, i will post soon.

Cheers

Added after 2 minutes:


Code:
unsigned char code A[6] ={0x00,0x3F,0x50,0x90,0x50,0x3F};

unsigned char code *DATA_POINTER; 

void DISP (unsigned char code *DATA_POINTER) 
{ 
    //display method
} 

void main(void)
{
    DATA_POINTER=&A[0];
    DISP(DATA_POINTER);
}

Check the above example code, when you place the array in ROM.

Because C51 uses diff instruction to access data from RAM (MOVX) and ROM (MOVEC).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top