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

Memory mapped ADC

Hi, I want to access the ADC0804 which is connected as the memory mapped device at 0x0001. Initially, I want check whether, address and data bus is working fine. For the same, I wrote the code as
:::::Program 1:::::
#include <p89v51rx2.h>

volatile unsigned char xdata *p = (char xdata *)0x0000;
sbit LED = P3^0;

void main()
{ int j = 0;

while(1) { p[0] = 0x55; for(j=0; j<=2500; j++); LED = 0; p[1] = 0xAA; for(j = 0; j<=2500; j++); LED = 1; }
}

:::::: Program 2::::::::::::::::
#include <p89v51rx2.h>
#include <absacc.h>

volatile xdata at 0x1000 unsigned char config;
volatile xdata at 0x1001 unsigned char config1;
sbit LED = P3^0;

void main()
{ int j = 0; while(1) { config = 0xAA; for(j=0; j<=2500; j++); LED = 0; config1 = 0x55; for(j = 0; j<=2500; j++); LED = 1; }
}

Program 1: LED Blinks but, there is no ALE or BUS transisitions.
Program 2: Compiler through error that missing ; before 0x1000. This code I have refered from one of 8051 SBC webpage.

Kindly let me know what is the wrong? Is it, I need to set something in compiler? Iam using Keil uV4.

With thanks...

Parents Reply Children
  • Hi, Sorry, I was not clear in my question. Problem is.
    Non-of the two program toggles the address and data bus.
    Only I could able to see LED blinking with first program and could not able to compile second program...
    Provide me complete C code example to access external memory mapped I/O pls...
    With Thanks...

  • Provide me complete C code...
    Nopes. Its your job to write a code to interface ADC.

    Hint: !EA pin. Read datasheet of 8051 and figure out the starting address of the external memory depending on the status of !EA. Then compare it with the address you are initialsing in the xdata pointer.

  • could not able to compile second program...
    The previous post was with regards to this doubt of yours.

    Dont you see the difference in the definitions of the xdata variables?

    volatile unsigned char xdata i _at_ 0x1000;  //No compiler errors in uV4
    

  • Thanks... I agree that writing program is my part. But, Since, I am purly hardware designer and just started coding, I could not able to think 100% software points. So, If I get some example to access external memory mapped devices (basically, initialization and writing/reading to one location, it will be helpful to continue further.

    I am using P89V51RD2 from NXP.

    With Thanks...

  • Thanks... I will check this point. As I stated I am purly hardware engineer and this is my first programming experiance, I don't know this syntax's...
    I will change my code and try to check.

    By the way, I am using P89V51RD2..

  • The IC uses 8051 architecture, hence the its only a variant from NXP having some extra features compared to the basic 8051 IC. Wont make much difference for you now.

    Read the User Manual of the IC.

    I am purly hardware engineer
    That will be helpful in understanding the IC even better and will assist you writing the code.

  • The P89V51RD2 has an on-chip XRAM of 768 Bytes starting X:0x0000 up to X:0x02FF.
    Then you use the same address for external memory mapped devices?
    You need either disable that internal XRAM or -better- use a different XRAM address

  • Hi James,

    You need either disable that internal XRAM or -better- use a different XRAM address

    I have tried address of 0x8000 and 0x0301 as well.. the bus is not toggling even there is no transistion in ALE pin. I don't know where I am missing...... Is there any thing I need to configure in compiler (Keil)?

  • Then compare it with the address you are initialsing in the xdata pointer.
    !EA doesnot have any relation with xdata.
    if, !EA =0, external code memory is accessed. hence, toggling of address and data bus can be seen (helps verifying if the external buses are working properly or not). also ALE and PSEN toggle.

  • Hint: !EA pin
    fatty sausage + male cow manure

    Erik

  • I am purly hardware engineer and this is my first programming experiance

    trying to mak people switch to ARM, NXP has dropped "the bible" anyone know where "the bible" may still be found. It would be useful for the OP

    Erik