0

Can anyone help me on how to to set the I/O configuration in C programming. This is my code, I am using keil uvision4 as my ide to generate the hex file and isis proteus to model the circuit.

When i try to use DDRA=0xFF and PORTA=0. I get the error that DDRA and PORTA is not defined. is there any particular header i must include that am not

Here is the code

 #include <AT89X51.H>

 #define PORT2     P2


void main (void)
{
DDRA=0xff;
    PORTA=0xff; 
}
flexxxit
  • 2,440
  • 5
  • 42
  • 69
  • The code did not get posted. Paste it and press the `{}` button to format it properly. – Potatoswatter Feb 21 '13 at 16:21
  • "This is my code". Did you forget to add something? – Joachim Isaksson Feb 21 '13 at 16:21
  • "This is my code" - it's actually very simple, so to say. –  Feb 21 '13 at 16:28
  • Well, I've spent a few minutes and found documentation such as http://www.atmel.com/Images/doc4235.pdf which covers internal peripherals, http://www.atmel.com/Images/doc4316.pdf for general programming including port configuration, and the datasheet http://www.atmel.com/images/doc0265.pdf, and nothing clearly describes what register configures the I/O pins. WTF, good luck guys. – Potatoswatter Feb 21 '13 at 16:39
  • @Potatoswatter I added my code – flexxxit Feb 21 '13 at 16:45
  • DDRA set as 0xFF configures PORTA as an output, from the sample code I've found on the same family of processors. @Yehonathan, is your compiler able to find that header file? Does that header include the definition of these registers? – Peter L. Feb 21 '13 at 17:14
  • @Peter The only header file I have is `#include ` I thought the definitions will be in it but apparently they are not. So how do I get the appropriate headerfile ? – flexxxit Feb 21 '13 at 18:42
  • I've also looked around and can't find where DDRA is specified (or used) with Atmel 8051 processors. There exist DDRA registers for processors of other architectures, but nothing seems to indicate that there is a register to configure PORTA, although it would make sense if there were. – Peter L. Feb 21 '13 at 22:00

3 Answers3

1

I know this is old but I just came across it and maybe someone else will too

It looks like you are missing an include:

#include <avr/io.h>

That should give you the PORTx and DDRx defines you are looking for.

Rob R.
  • 3,629
  • 2
  • 14
  • 12
0

You may need to include a register file example #include <REGX51.H>. It has the definitions for Ports, so that you can use P2 etc directly.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
code8230
  • 57
  • 1
  • 7
  • I already have it. I saved it as AT89X51.h. Thats my present header file yet DDRA is still not defined. Got the header file from this link [link](http://www.keil.com/dd/docs/c51/atmel/regx51.h) – flexxxit Feb 22 '13 at 00:24
  • As far as I remember, there are no direction registers in 8051. You need to assign a value 0xFF to the Port to make it Input or 0x00 to make it as output. – code8230 Feb 22 '13 at 00:39
0

I think this 3 regs: PORTA DDRA PINA can only be used in AVR MCUs family, such as the ATmega8, and can not be used in the 51 cmpatibility MCUs.

This is why you can't find where the regs are defined.

Do as follows:

1, #include <REGX51.H>, not the avr/io.h for AVR MCUs family

2, operate the IO port as P0, P1, P2

when you want to write port, P0 = 0xFF;

iama
  • 103
  • 7